Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 582327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:40:30+00:00 2026-05-13T14:40:30+00:00

Okay so the way this works is the user authenticates via web form and

  • 0

Okay so the way this works is the user authenticates via web form and generates a session ID as so:

sub session_open
{
    my $sid;
    my $user = shift;

    if ( open(SEMA, "> ../sema/sess") )
    {
        flock SEMA, LOCK_EX;
        do 
        {
            $sid = generate_session_id();
        } 
        while ( -d "$SDIR/$sid" );
        my $sstr = "$user:$ENV{'HTTP_USER_AGENT'}";
        write_file('>', "$SDIR/$sid", $sstr);
        close SEMA;
    }

    return $sid;
}

The session ID is then passed to every page in the url, if the session file exists and checks out against his user agent and remote addr it allows the user to continue:

sub check_sid
{   
    my $sid = shift;
     return 0 if $sid =~ /[^\w\d]/;
    return 0 if !open(SID, "< $SDIR/$pid");
    my ($user, $agent) = split /:/, <SID>, 2;
    close SID;
    return 0 if $agent ne $ENV{'HTTP_USER_AGENT'}";
    return $user;
}

In the background I have a cron job running a script every 5 minutes expiring sessions 2 hours old:

foreach (<../session/*>)
{
    unlink $_ if -M $_ > 0.08333;
}

Are there any flaws, unnecessary steps I am taking here? I figured use the user_agent and remote_addr as it would be harder to jack someones session ID that way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:40:30+00:00Added an answer on May 13, 2026 at 2:40 pm

    Use CGI::Session. See also CGI::Application::Plugin::Session.

    • There is a race condition in session_open.

    • Does your session handling code allow any other session information to be written to the session file?

    • In check_sid, you have my $sid = shift; but you try to open "$SDIR/$pid".

    • Even if you had correctly named the variable to be interpolated into the filename, there is the obvious flaw that you are not untainting the session id (that is, you are trusting unchecked input). Combine that with the fact that you are using the two argument form of open, and interesting possibilities present themselves.

    In any case, there is no reason for anyone to write session handling code. The work has been done for you. Don’t reinvent the wheel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay guess this question looks a lot like: What is the best way to
Okay I'll try describe this the best way I can. I have a chat
Is this an okay practice or an acceptable way to use PHP's error suppressing?
Okay, I stumbled upon this piece of code.. How come this works? What sort
okay i have found the way to run a video in a image.... the
Okay, This may be really simple or it may not even be possible, or
okay so this is probably a soft pitch question for sombody, but I want
Okay, I have done a bit of searching online and found this thread, but
Okay so i have a semi weridish problem with re.sub. Take the following code:
Okay, so not sure if apple.stackexchange is a better place for this, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.