Session and cookie management in.Net Justin Brunelle CS795 6/18/2009.

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
©2009 Justin C. Klein Keane PHP Code Auditing Session 5 XSS & XSRF Justin C. Klein Keane
Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation.
By Brian Vees.  SQL Injection  Username Enumeration  Cross Site Scripting (XSS)  Remote Code Execution  String Formatting Vulnerabilities.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
Cookies.NET Security Summer 2006 CS795/895 Hadi Arbabi.
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.
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.
Session Management A290/A590, Fall /25/2014.
Designing Security In Web Applications Andrew Tomkowiak 10/8/2013 UW-Platteville Software Engineering Department
Web Application Vulnerabilities Checklist. EC-Council Parameter Checklist  URL request  URL encoding  Query string  Header  Cookie  Form field 
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.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
Session 11: Security with ASP.NET
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
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.
Security.NET Chapter 1. How Do Attacks Occur? Stages of attack Examples of attacker actions 1. FootprintRuns a port scan on the firewall 2. PenetrationExploits.
Prevent Cross-Site Scripting (XSS) attack
+ Websites Vulnerabilities. + Content Expand of The Internet Use of the Internet Examples Importance of the Internet How to find Security Vulnerabilities.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Lecture 14 – Web Security SFDV3011 – Advanced Web Development 1.
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.
JavaScript, Fourth Edition
© All rights reserved. Zend Technologies, Inc. PHP Security Kevin Schroeder Zend Technologies.
November 13, 2008 Ohio Information Security Forum Attack Surface of Web Applications James Walden Northern Kentucky University
©2008 Gotham Digital Science Secure Parameter Filter (SPF) (AKA Protecting Vulnerable Applications with IIS7) Justin Clarke, Andrew Carey Nairn.
State Management. What is State management Why State management ViewState QueryString Cookies.
Lecture 16 Page 1 CS 236 Online SQL Injection Attacks Many web servers have backing databases –Much of their information stored in a database Web pages.
1 Web services and security ---discuss different ways to enforce security Presenter: Han, Xue.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Chapter 2. Core Defense Mechanisms. Fundamental security problem All user input is untrusted.
Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Exceptions Handling Exceptionally Sticky Problems.
Website Development with PHP and MySQL Saving Data.
Dr. Mustafa Cem Kasapbaşı Security in ASP.NET. Determining Security Requirements Restricted File Types.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
SEC835 Runtime authentication Secure session management Secure use of cryptomaterials.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Session and Cookie Management in.Net Sandeep Kiran Shiva UIN:
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
October 3, 2008IMI Security Symposium Application Security through a Hacker’s Eyes James Walden Northern Kentucky University
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
CIS 451: Cookies Dr. Ralph D. Westfall February, 2009.
(Some from Chapter 11.9 – “Web” 4 th edition and
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
HTTP Transactions 1. 2 Client-Server Model 3 HTTP HyperText Transport Protocol Native protocol for WWW Sits on top of internet’s TCP/IP protocol HTTP.
Radoslav Georgiev Telerik Corporation
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Building Secure ColdFusion Applications
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Handling Exceptionally Sticky Problems
Cross-Site Forgery
Validation and Building Small Apps
Session management.
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
PHP: Security issues FdSc Module 109 Server side scripting and
Web Programming Language
Handling Exceptionally Sticky Problems
Presentation transcript:

Session and cookie management in.Net Justin Brunelle CS795 6/18/2009

Introduction to Cookies Used to store data –Stateful way of storing data in stateless environment Contain two attributes – names and values

Cookie Example Creating a cookie in ASP.NET: HttpCookie cookie = new HttpCookie(“cookieName”); cookie.Values[“ValueName1”] = “MyVal1”; cookie.Values[“ValueName2”] = “MyVal2”; Retrieving a cookie in ASP.NET HttpCookie myCookie = Request.Cookies[“cookieName”]; if(myCookie != null) { string val1 = myCookie.Values[“ValueName1”]; string val2 = myCookie.Values[“ValueName2”]; }

Introduction to Sessions ASP starts a session and returns a cookie –Automatic when using sessions on user login –Needs cookies Session Objects contain session state data

Session Example Add data to a session object Session[“DataName’] = myData; Retrieving data from a session object myData = Session[“DataName”] Other Functions: Session.IsNewSession Session.RemoveAll Session.SessionID

Sessions without Cookies You don't have to change anything in your ASP.NET application to enable cookieless sessions, except the following configuration setting – Session identifiers stored in the URL Session information lost between sessions with cookieless sessions Cookieless sessions creates a security issue when sending URLs to others

Session Variables Can be used to store data about the current user and his session Session["FirstName"] = FirstNameTextBox.Text; Session["LastName"] = LastNameTextBox.Text;

Cookies and Security Insecure –Stored in text –Can be encrypted Still can be read, and possibly decoded Solution: –Encrypt in web.config Use timeouts to prevent theft and reuse

Cookie Poisoning Cookies intercepted when sent between the server and the client Modifying cookies to gain access to sensitive information –Such as, getting a cookie and changing the values –Extracting passwords Both done with a web proxy tool

Prevent Cookie Poisoning Encrypt values and sensitive information –DES, AES, etc.

Prevent Cookie Poisoning Treat cookies as untrusted sources of information Use regular expressions and type matching to test validity of cookies –Use regular expressions and strict data formatting conventions in your code –If the type stored in a cookie is known, make sure the value of the cookie can be cast such as string to int, where int is the desired type

Protection from JavaScript and Cookies Users can use scripting attacks by entering JavaScript into forms fields –Can be stored in cookies and read later We can cache malicious attacks –Attacks cached from Cookies, QueryString and Forms Posts.

Protection from JavaScript and Cookies –Checks all input data against a list of potentially dangerous values –Slows performance, but only for users doing the attack ValdidateRequest=true won't hamper your users experience in any way HttpRequestValidationException is thrown to signal malicious code –Catch the error and program accordingly

Alternate script injection protection Server.HtmlEncode(string) –Encodes the inserted script using html codes – alert(“hi”); becomes – < script > language=" javascript" >alert(" hi" );</script> –Must be careful about how we use decoded strings with this method

Encrypting Cookies Use HttpSecureCookie and MachineKeyCryptography Function secureMyCookie(HttpCookie myCookie) { HttpCookie encodedCookie = new HttpCookie(myCookie.Name, myCookie.Value); encodedCookie.Domain = myCookie.Domain; encodedCookie.Expires = myCookie.Expires; encodedCookie.HttpOnly = myCookie.HttpOnly; encodedCookie.Path = myCookie.Path; encodedCookie.Secure = myCookie.Secure; encodedCookie.Value = MachineKeyCryptography.Encode(cookie.Value, CookieProtection cookieProtection); return encodedCookie; }

Encryption and Decryption HttpCookie cookie = new HttpCookie("UserName", "Terminator"); cookie.Expires = DateTime.Now.AddDays(1); HttpCookie encodedCookie = HttpSecureCookie.Encode(cookie); Response.Cookies.Add(encodedCookie); HttpCookie cookie = Request.Cookies["UserName"]; lblDisplayBefore.Text = cookie.Value; HttpCookie decodedCookie = HttpSecureCookie.Decode(cookie);

Session State in IE Tabs Session only shared between tabs if user opens a new tab from a tab already in the session –State can become unstable if user modifies the same data a different way in each tab –User might have to log into each of the tabs

Resolutions Issues with these: –Logging in is annoying –Can’t use pop-ups to transmit data Don’t have sessions –Hidden fields are insecure Problem stems from the process that runs the tabs

Resolutions (cont’d) Config Setting: Appends the session state to the URL of the new tab –Gives us a new session for each tab stemming from the first session

IE8 Tabs Tabs run by one process –Tab process handles a single session for each tab –Code from the previous slide forces a new session Users can also select “File -> New Session”

Tricking ASP.NET Sessions Normally, session cookies expire at the end of the session We can enter JavaScript in the address bar to create your own session cookies: javascript:void(document.cookie="ASP.NET_SessionId=WhyDidTheChickenCr ossThe;path=/") We can set the expiration date to save the cookie and session data javascript:void(document.cookie="ASP.NET_SessionId=WhyDidTheCh ickenCrossThe;path=/;expires=Mon, 19 Mar :25:19 GMT");

Protecting Session Cookies ASP.NET does not put login credentials in session cookies –Mitigates the following problem slightly Hijackers can still take session cookies and reuse them to gain access to information Use the following to protect your cookies: if (!Page.User.Identity.IsAuthenticated) { if (Page.Request.Cookies["ASP.NET_SessionId"] != null) { Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddYears(-30); } Session.Abandon(); }

Questions?