Submit Your Article Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
IT Discussion Forum Having IT issues? Got IT questions? Who doesn't? If you can't get your Apache to work with your MySQL or your php is choking on your ODBC... Let's see if we can help you come up with some ideas.

Share Thread: & Tags

Share Thread:

Tags
random, secure, security, sql

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-25-2009, 12:08 AM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,436
morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6
Default Is It Secure To Use The Session ID as a Profile Selector Condition With SQL?

So I snagged this pretty good login script that uses sessions and now that I can get a user to log in but the tricky part is displaying only their data.

I was able to catch the randomly created id through this SQL statement "MD5(UNIX_TIMESTAMP()".

Is it safe to use that generated variable as the condition to check and get the user's information?

__________________
Join free dating sites and meet single people without paying a penny.
Submit your articles at my article directory and get quite a few instant back-links from other social sites!
Reply With Quote
  #2 (permalink)  
Old 11-25-2009, 10:36 AM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,825
wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10
Default Re: Is It Secure To Use The Session ID as a Profile Selector Condition With SQL?

Assuming you are referring to getting the PHP session id, the workaround you are suggesting could be incorrect at times. To get the actual PHP session id, the code is $id = session_id();

Once a user is logged in, you can use print_r($_SESSION); to view the variables the login script stores in the session, and access them with your own scripts.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #3 (permalink)  
Old 11-25-2009, 10:48 AM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,436
morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6
Default Re: Is It Secure To Use The Session ID as a Profile Selector Condition With SQL?

OK thanks (again) wige...

So using the session is as the condition for selecting the user's data is ok security wise?
__________________
Join free dating sites and meet single people without paying a penny.
Submit your articles at my article directory and get quite a few instant back-links from other social sites!
Reply With Quote
  #4 (permalink)  
Old 11-25-2009, 11:21 AM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,825
wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10wige RepRank 10
Default Re: Is It Secure To Use The Session ID as a Profile Selector Condition With SQL?

Um, well...

It really depends on how sensitive the data in question is. If you are talking about simply editing a user profile on a social networking site, that should be fine. If you are talking about financial, or medical information, additional authentication should be done, such as reconfirming the user's password from within an encrypted channel.

In theory, an unauthenticated user could hijack a session from an authenticated user on a standard HTTP connection. The protection against this is to "reinitialize" the session and reauthenticate the user. This requires the use of secure cookies, and that all communication within the secure area of the site be done over HTTPS. Additional security can be achieved against hijacking by continuously checking the user's IP address.

The basic workflow would be as follows:

The user comes into the web site as an unauthenticated user, and is assigned a session id.
The user goes to the secure site to authenticate, and the unauthenticated session id is reset.
The user authenticates, and the session now stores the user's id and IP address, but no other authentication information.
The user returns to to the unsecure section of the site and continues browsing, keeping the same session id.
The user decides to access secure information, and returns to the secure area of the site. The user's session is reset, the current IP address is checked against the IP stored in the session, and the user is prompted to re-enter their password.
The user reauthenticates, and maintains the same session id, and proceeds to access the secure information.

This method can be less friendly from a user standpoint, since the user has to reenter their password each time they go to the secure area of the site, and as a result this approach may only be desired if you are storing sensitive information. Most sites do not take this type of precaution, as it can be a bit of overkill for most situations.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #5 (permalink)  
Old 11-25-2009, 11:31 AM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,436
morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6
Default Re: Is It Secure To Use The Session ID as a Profile Selector Condition With SQL?

Very well then...in my case it is only about being able to view their own data and edit it as they please...My only worry is that somehow they end up being able to edit other members information but as you mentioned, if I check their password and session ID I should be safe...there really isn't too much personal data - just profile information and at most the users email address...

Thanks so much wige - you're always great help!
__________________
Join free dating sites and meet single people without paying a penny.
Submit your articles at my article directory and get quite a few instant back-links from other social sites!
Reply With Quote
  #6 (permalink)  
Old 11-25-2009, 02:53 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,944
kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10kgun RepRank 10
Default Re: Is It Secure To Use The Session ID as a Profile Selector Condition With SQL?

And you can write a wrapper around PHP's session functions

Code:
<?php
/**
 * A wrapper around PHP's session functions
 * <code>
 * $session = new Session();
 * $session->set('message','Hello World!');
 * echo ( $session->get('message'); // Displays 'Hello World!'
 * </code>
 * @access public
 */
class Session
{
  /**
   * Session constructor<br />
   * Starts the session with session_start()
   * <b>Note:</b> that if the session has already started,
   * session_start() does nothing
   * @access public
   */
  public function __construct()
  {
    session_start();
  }

  /**
   * Sets a session variable
   * @param string name of variable
   * @param mixed value of variable
   * @return void
   * @access public
   */
  public function set($name, $value)
  {
    $_SESSION[$name] = $value;
  }

  /**
   * Fetches a session variable
   * @param string name of variable
   * @return mixed value of session varaible
   * @access public
   */
  public function get($name)
  {
    if (isset($_SESSION[$name]))
    {
      return $_SESSION[$name];
    }
    else
    {
      return false;
    }
  }
  
  /**
   * unsets a session variable
   * @param string name of variable
   * @return void
   * @access public
   */
  public function del($name)
  {
    unset($_SESSION[$name]);
  }

  /**
   * Destroys the whole session
   * @return void
   * @access public
   */
  public function destroy()
  { 
    $_SESSION = array();
    session_destroy();
    session_regenerate_id();
  }
} 
?>
Source: The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - SitePoint Books (see chapter 10 The whole chapter page 269 - 362 almost 100 pages is about the important subject of access control. Highly recommended reading.)

Your program is no more secure than your coding.
__________________
Mini Network:: Financial information at your fingertips
Learn object oriented programming where it started

I will use a search engine before I ask dumb questions.

Last edited by kgun; 11-25-2009 at 03:00 PM.
Reply With Quote
  #7 (permalink)  
Old 11-25-2009, 02:57 PM
morestar's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 1,436
morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6morestar RepRank 6
Default Re: Is It Secure To Use The Session ID as a Profile Selector Condition With SQL?

thank you too kgun...i shall look into this as well...I truly need to strengthen my PHP coding as well...it is time...
__________________
Join free dating sites and meet single people without paying a penny.
Submit your articles at my article directory and get quite a few instant back-links from other social sites!
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > IT Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
For Sale: T-Rex Dinosaur (Good Condition) TrafficProducer The Castle Breakroom (General: Any Topic) 3 09-13-2009 03:08 PM
Secure and non-secure things on checkout pages rjjj111 eCommerce Discussion Forum 2 07-10-2008 09:23 AM
Keyword Selector Tool Zhoog Submit Your Site For Review 1 01-09-2008 11:49 PM
PHP condition Nanor21 Web Programming Discussion Forum 5 05-13-2006 11:41 PM
Google Analytics on site with secure and non secure pages? joer80 Google Discussion Forum 7 12-07-2005 01:15 AM


All times are GMT -4. The time now is 05:16 PM.



Search Engine Optimization by vBSEO 3.3.0