Home > Security Tips > Web Security Advisor > How to secure session tokens
Security Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WEB SECURITY ADVISOR

How to secure session tokens


Joel Dubin
10.26.2005
Rating: -3.44- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Web sites by their very nature are stateless. HTTP initiates a new connection every time a user clicks on a link within a site. Session cookies keep state by moving a user's preferences from page to page as long as the session is active. But how do you keep a Web site secure for the entire session a user has logged in? There are many ways to pass a session token securely, some of which still include using the venerable old session cookie. Here are some dos and don'ts to protect users who are logged in, especially to secure sites, such as those for e-commerce, online purchasing and banking transactions.

The first rule is to create a secure logon from the start. Make sure that even the URL of your logon page is HTTPS and uses SSL. Otherwise, there's the possibility that logon credentials, such as user IDs and passwords, may be caught en route in clear text by sniffing from a plain unencrypted HTTP site. Starting with SSL encrypts from the beginning and protects those vital credentials.

Second, the best token for maintaining secure state is a session ID generated by the server. Make sure session IDs, which can be stored in session cookies or even URLs, are generated only by the Web server – not the client. Examples include JSESSIONIDs and ASPSESSIONIDs. Any token created by the browser is easy to capture and replay to spoof the user's identity. When the user moves to the next page in the application, all that is sent back by the browser – again by session cookie or URL – is the session ID, which can be verified by the server that generated it.

But, wait. The session ID can still be captured on the round trip and replayed in some cases, l...



ike when it's passed in the URL. So, all session IDs should be unique, random and encrypted. Unique means that every session should have its own session ID. So, even if the same user logged on twice, there should be two separate session IDs. And, in that particular case, the server should map the session ID to the user on the back end. If it's the same user trying to log on twice – a tell-tale sign of a malicious spoofer – the second user, innocent or not, should be blocked from accessing the Web site.

Session IDs should be generated randomly, so they can't be guessed. A favorite technique of hackers is figuring out session ID patterns, such as incrementing for each new user, and then replaying the pattern to gain access. And, of course, encrypt all session IDs with 3DES, MD5 or at least 128-bit encryption to keep sniffers clueless. Before encryption, it's a good idea to combine a timestamp into the session ID, which adds to its uniqueness, as well as making it more cryptic to begin with.

Finally, make sure all tokens, session IDs and session cookies expire after a reasonable time period -- between 20 minutes and an hour, for example, depending on the business requirements of your application. When the session has timed out or the user has logged out, clear out all tokens, whether session IDs or cookies, by deleting them on both client and the server. This way a session is completely dead and can't be brought back to life.

Using these same rules, it should be obvious that session tokens should never be put in hidden HTML fields or passed unencrypted as part of URLs. Follow the three rules of session tokens – unique, random and encrypted – and your users will use your Web site safely and securely.

About the author
Joel Dubin, CISSP, is an independent computer security consultant based in Chicago. He specializes in Web and application security and is the author of the recently released book The Little Black Book of Computer Security available from Amazon. SearchSecurity users can submit their questions to Joel via our Ask the Expert feature, or read an excerpt from his book.


Rate this Tip
To rate tips, you must be a member of SearchSecurity.com.
Register now to start rating these tips. Log in if you are already a member.




BROWSE BY TAG
Web Security Advisor,   Web Authentication and Access Control,   Enterprise Identity and Access Management,   Application and Platform Security,   Web Security Tools and Best Practices,   Web Application Security,   VIEW ALL TAGS

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Web Security Advisor
DNS rebinding defenses still necessary, thanks to Web 2.0
New defenses for automated SQL injection attacks
PCI compliance and Web applications: Code review or firewalls?
Worst practices: Bad security incidents to avoid
Web scanning and reporting best practices
Social networking Web site threats manageable with good enterprise policy
Enterprise security in 2008: Building trust into the application development process
PCI DSS Section 6: A plan for tackling application security
Making the case for Web application vulnerability scanners
Preparing for uniform resource identifier (URI) exploits

Web Authentication and Access Control
Group to shed light on secure identity management threats
How to confirm the receipt of an email with security protocols
Schneier-Ranum Face-Off: Is Perfect Access Control Possible?
Kaminsky reveals key flaws in X.509 SSL certificates at Black Hat
Changing times for identity management
How to use single sign-on for Web access control to prevent malware
IBM USB banking device stops keyloggers, malware
Can mutual authentication beat phishing or man-in-the-middle attacks?
Could someone place a rootkit on an internal network through a router?
Sun launches open source OpenSSO for identity management

Web Application Security
Black box and white box testing: Which is best?
InZero Systems launches hardware-based security gateway
Web application vulnerability assessment shows patching progress
Preventing SQL injection attacks: A network admin's perspective
Cisco acquires SaaS security vendor ScanSafe
Web application firewall use goes beyond compliance, company finds
Gumblar Trojan drive-by exploits spike following Adobe update
Some Facebook applications lead to Russian attack sites
Barracuda acquires Purewire expanding Web security reach
An enterprise strategy for Web application security threats

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
access log  (SearchSecurity.com)
anonymous Web surfing  (SearchSecurity.com)
authentication, authorization, and accounting  (SearchSecurity.com)
identity chaos  (SearchSecurity.com)
knowledge-based authentication  (SearchSecurity.com)
multifactor authentication (MFA)  (SearchSecurity.com)
walled garden  (SearchSecurity.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Research Solutions for Network Security, Access Control and Security Threats
TechTarget Security Media
Information Security View this month\\'s issue and subscribe today.
Information Security Decisions Apply online for free conference admission.
SearchSecurity.com
HomeNewsMagazineMultimediaWhite PapersLearningAdviceTopicsEventsAbout Us

About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts