Web Security: Session Management

Slides:



Advertisements
Similar presentations
Nick Feamster CS 6262 Spring 2009
Advertisements

Cookie Same Origin Policy Dan Boneh CS 142 Winter 2009 Monday: session management using cookies.
ForceHTTPS: Protecting High-Security Web Sites from Network Attacks Collin Jackson and Adam Barth.
HTTPS and the Lock Icon Dan Boneh. Goals for this lecture Brief overview of HTTPS: How the SSL/TLS protocol works (very briefly) How to use HTTPS Integrating.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
Session Management Dan Boneh CS 142 Winter Sessions A sequence of requests and responses from one browser to one (or more) sites Session can be.
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation.
EECS 354 Network Security Cross Site Scripting (XSS)
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz.
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License. The OWASP.
Online Security Tuesday April 8, 2003 Maxence Crossley.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
©2009 Justin C. Klein Keane PHP Code Auditing Session 7 Sessions and Cookies Justin C. Klein Keane
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
Lecture 16 Page 1 CS 236 Online Cross-Site Scripting XSS Many sites allow users to upload information –Blogs, photo sharing, Facebook, etc. –Which gets.
Cookies COEN 351 E-commerce Security. Client / Session Identification HTTP does not maintain state. State Information can be passed using: HTTP Headers.
WEB SECURITY WORKSHOP TEXSAW 2013 Presented by Joshua Hammond Prepared by Scott Hand.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
 A cookie is a piece of text that a Web server can store on a user's hard disk.  Cookie data is simply name-value pairs stored on your hard disk by.
Introduction to InfoSec – Recitation 10 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
Cookies Cross site scripting
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Cookies Set a cookie – setcookie() Extract data from a cookie - $_COOKIE Augment user authentication script with a cookie.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
WEB SECURITY WEEK 3 Computer Security Group University of Texas at Dallas.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
Session Management and User Authentication Dan Boneh CS 155 Spring 2011.
Chapter 9 Web Applications. Web Applications are public and available to the entire world. Easy access to the application means also easy access for malicious.
Robust Defenses for Cross-Site Request Forgery CS6V Presented by Saravana M Subramanian.
JavaScript, Fourth Edition
© All rights reserved. Zend Technologies, Inc. PHP Security Kevin Schroeder Zend Technologies.
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
Session and cookie management in.Net Justin Brunelle CS795 6/18/2009.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Feedback #2 (under assignments) Lecture Code:
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
SEC835 Runtime authentication Secure session management Secure use of cryptomaterials.
COOKIES and SESSIONS. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each.
1 Robust Defenses for Cross-Site Request Forgery Adam Barth, Collin Jackson, John C. Mitchell Stanford University 15th ACM CCS.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
Ins and Outs of Authenticating Users Requests to IIS 6.0 and ASP.NET Chris Adams Program Manager IIS Product Unit Microsoft Corporation.
Cookies COEN 351 E-commerce Security. Client / Session Identification HTTP Headers Client IP Address HTTP User Login FAT URLs Cookies.
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
Session Management Tyler Moore CS7403 University of Tulsa Slides adapted in part or whole from Dan Boneh, Stanford CS155 1.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
COEN 350: Network Security E-Commerce Issues. Table of Content HTTP Authentication Cookies.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
@Yuan Xue Web and HTTP Protocol A special acknowledge goes to J.F Kurose and K.W. Ross Some of the slides used in this lecture.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
Srinivas Balivada USC CSCE548 07/22/2016.  Cookies are generally set server-side using the ‘Set-Cookie’ HTTP header and sent to the client  In PHP to.
Avishai Wool Slides credit: Dan Boneh, John Mitchell
Cookies Cross site scripting
Cross-Site Forgery
Client / Session Identification Cookies
Client / Session Identification Cookies
John Mitchell (based on Dan’s previous slides)
Cross Site Request Forgery New Attacks and Defenses
Cross Site Request Forgery (CSRF)
Presentation transcript:

Web Security: Session Management CS155 Web Security: Session Management

Same origin policy: review Review: Same Origin Policy (SOP) for DOM: Origin A can access origin B’s DOM if match on (scheme, domain, port) This lecture: Same Original Policy (SOP) for cookies: Based on: ([scheme], domain, path) optional scheme://domain:port/path?params

Setting/deleting cookies by server GET … Server Browser HTTP Header: Set-cookie: NAME=VALUE ; domain = (when to send) ; path = (when to send) secure = (only send over SSL); expires = (when expires) ; HttpOnly scope if expires=NULL: this session only if expires=past date: browser deletes cookie Default scope is domain and path of setting URL

Scope setting rules (write SOP) domain: any domain-suffix of URL-hostname, except TLD example: host = “login.site.com” login.site.com can set cookies for all of .site.com but not for another site or TLD Problematic for sites like .stanford.edu (and some hosting centers) path: can be set to anything allowed domains login.site.com .site.com disallowed domains other.site.com othersite.com .com

Cookies are identified by (name,domain,path) name = userid value = test domain = login.site.com path = / secure cookie 2 name = userid value = test123 domain = .site.com path = / secure distinct cookies Both cookies stored in browser’s cookie jar both are in scope of login.site.com

Reading cookies on server (read SOP) Browser GET //URL-domain/URL-path Cookie: NAME = VALUE Browser sends all cookies in URL scope: cookie-domain is domain-suffix of URL-domain, and cookie-path is prefix of URL-path, and [protocol=HTTPS if cookie is “secure”] Goal: server only sees cookies in its scope

Examples cookie 1 name = userid value = u1 domain = login.site.com both set by login.site.com cookie 1 name = userid value = u1 domain = login.site.com path = / secure cookie 2 name = userid value = u2 domain = .site.com path = / non-secure http://checkout.site.com/ http://login.site.com/ https://login.site.com/ cookie: userid=u2 cookie: userid=u1; userid=u2 FF3: most specific cookie sent first

Client side read/write: document.cookie Setting a cookie in Javascript: document.cookie = “name=value; expires=…; ” Reading a cookie: alert(document.cookie) prints string containing all cookies available for document (based on [protocol], domain, path) Deleting a cookie: document.cookie = “name=; expires= Thu, 01-Jan-70” SOP: same as server-side read/write. Explain HttpOnly cookies: not available in document.cookie. document.cookie often used to customize page in Javascript

javascript: alert(document.cookie) Javascript URL javascript: alert(document.cookie) Displays all cookies for current document

Viewing/deleting cookies in Browser UI Users an easily edit cookie database and modify cookies arbitrarily.

Cookie protocol problems

Cookie protocol problems Server is blind: Does not see cookie attributes (e.g. secure, HttpOnly) Does not see which domain set the cookie Server only sees: Cookie: NAME=VALUE RFC 2109 (cookie RFC) has an option for including domain, path in Cookie header, but not supported by browsers.

Example 1: login server problems Alice logs in at login.site.com login.site.com sets session-id cookie for .site.com 2. Alice visits evil.site.com overwrites .site.com session-id cookie with session-id of user “badguy” 3. Alice visits course.site.com to submit homework course.site.com thinks it is talking to “badguy” Problem: course.site.com expects session-id from login.site.com; cannot tell that session-id cookie was overwritten Writes creditcard number into attacker’s account. Common in hosting providers.

Example 2: “secure” cookies are not secure Alice logs in at https://accounts.google.com Alice visits http://www.google.com (cleartext) Network attacker can inject into response Set-Cookie: SSID=badguy; secure and overwrite secure cookie Problem: network attacker can re-write HTTPS cookies !  HTTPS cookie value cannot be trusted set-cookie: SSID=A7_ESAgDpKYk5TGnf; Domain=.google.com; Path=/ ; Expires=Wed, 09-Mar-2023 18:35:11 GMT; Secure; HttpOnly set-cookie: SAPISID=wj1gYKLFy-RmWybP/ANtKMtPIHNambvdI4; Domain=.google.com;Path=/ ; Expires=Wed, 09-Mar-2023 18:35:11 GMT; Secure Alice visits http://www.google.com automatically due to phishing filter

Interaction with the DOM SOP Cookie SOP path separation: x.com/A does not see cookies of x.com/B Not a security measure: x.com/A has access to DOM of x.com/B <iframe src=“x.com/B"></iframe> alert(frames[0].document.cookie); Path separation is done for efficiency not security: x.com/A is only sent the cookies it needs

Cookies have no integrity User can change and delete cookie values Edit cookie database (FF: cookies.sqlite) Modify Cookie header (FF: TamperData extension) Silly example: shopping cart software Set-cookie: shopping-cart-total = 150 ($) User edits cookie file (cookie poisoning): Cookie: shopping-cart-total = 15 ($) Similar problem with hidden fields <INPUT TYPE=“hidden” NAME=price VALUE=“150”> 16 16

Not so silly … (as of 2/2000) D3.COM Pty Ltd: ShopFactory 5.8 @Retail Corporation: @Retail Adgrafix: Check It Out Baron Consulting Group: WebSite Tool ComCity Corporation: SalesCart Crested Butte Software: EasyCart Dansie.net: Dansie Shopping Cart Intelligent Vending Systems: Intellivend Make-a-Store: Make-a-Store OrderPage McMurtrey/Whitaker & Associates: Cart32 3.0 pknutsen@nethut.no: CartMan 1.04 Rich Media Technologies: JustAddCommerce 5.0 SmartCart: SmartCart Web Express: Shoptron 1.2 All these shopping carts stored data on browser Source: http://xforce.iss.net/xforce/xfdb/4621 17 17

Solution: cryptographic checksums Goal: data integrity Requires server-side secret key k unknown to browser Generate tag: T  MACsign(k, SID ll name ll value ) Server Browser Set-Cookie: NAME = value T k Cookie: NAME = value T Verify tag: MACverify(k, SID ll name ll value, T) non-keyed checksums (e.g. CRC) are insufficient for this purpose !! Can still swap with cookies from another active session. Bind to IP address? Binding to session-id (SID) makes it harder to replay old cookies

Example: ASP.NET System.Web.Configuration.MachineKey Secret web server key intended for cookie protection Creating an encrypted cookie with integrity: HttpCookie cookie = new HttpCookie(name, val); HttpCookie encodedCookie = HttpSecureCookie.Encode (cookie); Decrypting and validating an encrypted cookie: HttpSecureCookie.Decode (cookie); Attack: http://netifera.com/research/poet/PaddingOraclesEverywhereEkoparty2010.pdf 19

Session Management

Sessions A sequence of requests and responses from one browser to one (or more) sites Session can be long (e.g. Gmail) or short without session mgmt: users would have to constantly re-authenticate Session mgmt: authorize user once; All subsequent requests are tied to user

Pre-history: HTTP auth HTTP request: GET /index.html HTTP response contains: WWW-Authenticate: Basic realm="Password Required“ Browsers sends hashed password on all subsequent HTTP requests: Authorization: Basic ZGFddfibzsdfgkjheczI1NXRleHQ=

HTTP auth problems Hardly used in commercial sites: User cannot log out other than by closing browser What if user has multiple accounts? multiple users on same machine? Site cannot customize password dialog Confusing dialog to users Easily spoofed

Session tokens GET /index.html set anonymous session token web site Browser GET /index.html set anonymous session token GET /books.html anonymous session token check credentials (crypto) POST /do-login Username & password elevate to a logged-in session token POST /checkout logged-in session token Validate token Validate token: check that it belongs to an active session that has not been logged out or timed out.

Storing session tokens: Lots of options (but none are perfect) Browser cookie: Set-Cookie: SessionToken=fduhye63sfdb Embed in all URL links: https://site.com/checkout ? SessionToken=kh7y3b In a hidden form field: <input type=“hidden” name=“sessionid” value=“kh7y3b”>

Storing session tokens: problems Browser cookie: browser sends cookie with every request, even when it should not (CSRF) Embed in all URL links: token leaks via HTTP Referer header In a hidden form field: does not work for long-lived sessions Best answer: a combination of all of the above. (or if user posts URL in a public blog)

The HTTP referer header Referer leaks URL session token to 3rd parties Referer supression: not sent when HTTPS site refers to an HTTP site in HTML5: <a rel=”noreferrer” href=www.example.com>

The Logout Process Web sites must provide a logout function: Functionality: let user to login as different user Security: prevent others from abusing account What happens during logout: 1. Delete SessionToken from client 2. Mark session token as expired on server Problem: many web sites do (1) but not (2) !! ⇒ Especially risky for sites who fall back to HTTP after login

Session hijacking

Session hijacking Attacker waits for user to login then attacker steals user’s Session Token and “hijacks” session ⇒ attacker can issue arbitrary requests on behalf of user Example: FireSheep [2010] Firefox extension that hijacks Facebook session tokens over WiFi. Solution: HTTPS after login

Beware: Predictable tokens Example 1: counter  user logs in, gets counter value, can view sessions of other users Example 2: weak MAC. token = { userid, MACk(userid) } Weak MAC exposes k from few cookies. Apache Tomcat: generateSessionId() Returns random session ID [server retrieves client state based on sess-id] Don’t generate your own. Use built in procedures: ASP, Tomcat, JServ

Session tokens must be unpredictable to attacker To generate: use underlying framework (e.g. ASP, Tomcat, Rails) Rails: token = MD5( current time, random nonce ) Don’t generate your own. Use built in procedures: ASP, Tomcat, JServ

Beware: Session token theft Example 1: login over HTTPS, but subsequent HTTP Enables cookie theft at wireless Café (e.g. Firesheep) Other ways network attacker can steal token: Site has mixed HTTPS/HTTP pages ⇒ token sent over HTTP Man-in-the-middle attacks on SSL Example 2: Cross Site Scripting (XSS) exploits Amplified by poor logout procedures: Logout must invalidate token on server

Mitigating SessionToken theft by binding Mitigating SessionToken theft by binding SessionToken to client’s computer A common idea: embed machine specific data in SID Client IP addr: makes it harder to use token at another machine But honest client may change IP addr during session client will be logged out for no reason. Client user agent: weak defense against theft, but doesn’t hurt. SSL session id: same problem as IP address (and even worse) Can also embed agent’s timezone.

Session fixation attacks Suppose attacker can set the user’s session token: For URL tokens, trick user into clicking on URL For cookie tokens, set using XSS exploits Attack: (say, using URL tokens) Attacker gets anonymous session token for site.com Sends URL to user with attacker’s session token User clicks on URL and logs into site.com this elevates attacker’s token to logged-in token Attacker uses elevated token to hijack user’s session.

Session fixation: lesson When elevating user from anonymous to logged-in: always issue a new session token After login, token changes to value unknown to attacker  Attacker’s token is not elevated. Problems with new SessionToken after every request: the back button (but can be dealt with with proper handling of replays)

Summary Always assume cookie data retrieved from client is adversarial Session tokens are split across multiple client state mechanisms: Cookies, hidden form fields, URL parameters Cookies by themselves are insecure (CSRF, cookie overwrite) Session tokens must be unpredictable and resist theft by network attacker Ensure logout invalidates session on server

THE END