Cookies.NET Security Summer 2006 CS795/895 Hadi Arbabi.

Slides:



Advertisements
Similar presentations
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.
Advertisements

JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
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.
How Clients and Servers Work Together. Objectives Learn about the interaction of clients and servers Explore the features and functions of Web servers.
Session Management A290/A590, Fall /25/2014.
Creating Web Page Forms
Operating System & Application Files BACS 371 Computer Forensics.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
11 SUPPORTING INTERNET EXPLORER IN WINDOWS XP Chapter 11.
 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.
The World-Wide Web. Why we care? How much of your personal info was released to the Internet each time you view a Web page? How much of your personal.
Computer Concepts 2014 Chapter 7 The Web and .
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.
 TCP/IP is the communication protocol for the Internet  TCP/IP defines how electronic devices should be connected to the Internet, and how data should.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
JavaScript, Fourth Edition
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
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.
Session 10: Managing State. Overview State Management Types of State Management Server-Side State Management Client-Side State Management The Global.asax.
State Management. What is State management Why State management ViewState QueryString Cookies.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Securing a Microsoft ASP.NET Web Application.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Types of Electronic Infection
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
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.
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.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
ASP.NET State Management. Slide 2 Lecture Overview Client state management options Cookies Server state management options Application state Session state.
ITCS373: Internet Technology Lecture 5: More HTML.
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.
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.
Cookies Bill Chu. © Bei-Tseng Chu Aug 2000 Definition A cookie is a TEXT object of max 4KB sent from a web server to a browser It is intended for the.
TCP/IP (Transmission Control Protocol / Internet Protocol)
Visual Basic.NET Programming March 3, Agenda Questions / Discussion Cookies Project Work (Ends Around 9:00 PM) Demo's (15 minutes per team)
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Security fundamentals Topic 5 Using a Public Key Infrastructure.
Chapter 12: How Private are Web Interactions?. Why we care? How much of your personal info was released to the Internet each time you view a Web page?
How to create a SharePoint site MICROSOFT OFFICE SHAREPOINT DESIGNER.
WEB SERVER SOFTWARE FEATURE SETS
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
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.
8-Mar-16 More About Servlets Session Tracking. Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information:
Cookies and Sessions in PHP. Arguments for the setcookie() Function There are several arguments you can use i.e. setcookie(‘name’, ‘value’, expiration,
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
COOKIES AND SESSIONS.
ASP.NET WEB Applications. ASP.NET  Web application framework developed by Microsoft  Build dynamic data driven web applications and web services  Subset.
COOKIES Gloria Soria Network Security COSC 356. What is a Cookie? A cookie is a piece of text that a Web Server can store on a user's hard disk. Cookies.
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.
ASP.NET State Management Overview Prepared By Manish Kumar Aery(IM66) Department of computer Application IET Bhaddal (Ropar)
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Internet Programming Chapter 9: State Management in ASP.NET
How to Check if a site's connection is secure ?
Cookies and JavaScript
Uses Of Encryption Algorithms
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.
HTML5 and Local Storage.
CSc 337 Lecture 27: Cookies.
Designing IIS Security (IIS – Internet Information Service)
CSc 337 Lecture 25: Cookies.
Presentation transcript:

Cookies.NET Security Summer 2006 CS795/895 Hadi Arbabi

Maintaining State Information Query strings Are visible to the user, should not contain secure information View state ViewState property as hidden fields on page Session state Local to current session (single user) Application state Available to all users of application Cookies Store small amount of information on a client (if not refused)

What Are Cookies? A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the application can read whenever the user visits the site. Cookies are normally written to the user's disk. The Browser looks on the local hard disk for a cookie associated with the URL. If the cookie exists, the browser sends the cookie to your site along with the page request. Cookies are used for all sorts of purposes, all relating to helping the Web site remember you.

Properties Cookies are associated with a Web site, not with a specific page. As the user visits different sites, each site might send a cookie to the user's browser as well. The browser stores all the cookies separately. Most browsers support cookies of up to 4096 bytes. Most browsers allow only 20 cookies per site; if you try to store more, the oldest cookies are discarded. Cookies are stored by Name, so if you create two cookies with the same name, one overwrites the other. Different browsers store cookies in different ways. Cookies are case sensitive.

Properties IE5 and higher store cookies in this way: C:\Documents and Settings\ NOTE: You can open the cookie with a text editor. If the file contains multiple cookies, they are separated with an asterisk (*). The first line of each cookie is its name, and the second has the values. The remaining lines have cookie housekeeping information such as the expiration date and time. There is also a simple checksum in the cookie; if you change the length of the cookie name or value, the browser will detect the tampering and will discard the cookie.

Approaches Two approaches when storing and retrieving user information through cookies: 1. Store all the user information as a cookie on the client’s computer It is useful when user information is simple and is not required on the server for any tasks. 2. Store an identification key on client’s machine, and then retrieve user information from a data source on the server using that identification key It is the best for storing more extensive information.

HttpCookie Class in.NET Public Properties DomainGets or sets the domain to associate the cookie with ExpiresGets or sets the expiration date and time for the cookie HasKeysGets a value indicating whether a cookie has subkeys NameGets or sets the name of a cookie PathGets or sets the virtual path to transmit with the current cookie SecureGets or sets a value indicating whether to transmit the cookie securely (that is, over HTTPS only) ValueGets or sets an individual cookie value ValuesGets a collection of key-and-value value pairs that are contained within a single cookie object

Using Cookies U sers can set their browser to refuse cookies. The application should not depend on being able to store cookies. Use cookies for nice-to-have features; do not use them to support critical features. C#: private void Function(….) { // If the browser supports cookies if(Request.Browser.Cookies) { // Create a cookie HttpCookie myCookie = new HttpCookie(“MyCookie”); cookie.Value = “This is value of my cookie”; // Add the cookie Response.Cookies.Add(myCookie); }

Creating Cookie Steps to store a cookie: 1. Check whether the client supports cookies by using the Browser object’s Cookies property. 2. If so, check whether the cookie already exists by using the Request object’s Cookies collection. 3. If not, create a new cookie object using the HttpCookie class. 4. Set the cookie object’s Value and Expiration properties. 5. Add the cookie object to Response object’s Cookies collection.

Code C# private void Page_Load(object sender, System.EventArgs e) { if(Request.Browser.Cookies) { if(Request.Cookies[“MyCookie”] == null) { HttpCookie myCookie = new HttpCookie(“MyCookie”); myCookie.Value = “This is my cookie value”; myCookie.Expires = DataTime.Now.AddDays(5); Response.Cookies.Add(myCookie); } else { HttpCookie myCookie = Request.Cookies[“MyCookie”]; myCookie.Value = “Set the value”; myCookie.Expires = DataTime.Now.AddDays(5); } else{ // SHOW MESSAGE; THE BROWSER DOES NOT ACCEPT COOKIES. (ALERT). }

Expiration?!!! If you do not set the cookie's expiration, the cookie is created but it is not stored on the user's hard disk. Instead, the cookie is maintained as part of the user's session information. When the user closes the browser or if the session times out, the cookie is discarded. A non-persistent cookie like this is handy for information that needs to be stored for only a short time or that for security reasons should not be written to disk on the client computer. For example, non-persistent cookies are useful if the user is working on a public computer, where you do not want to write the cookie to disk. So Expires property determines when the client’s machine can discard the cookie. Setting Expires to the DateTime.MaxValue means that the cookie never expires. Response.Cookies[“MyCookie”].Expires= DateTime.MaxValue ; Resetting the Expires property to the current time or the past time removes the cookies form client’s machine. Response.Cookies[“MyCookie”].Expires= DateTime.Now ;

Using Keys, Multi-Valued Cookies private void SetKeys(….) { HttpCookie cuky = new HttpCookie(“UserInfo”); cuky[“FirstName”] = firstname; cuky[“LastName”] = lastname; cuky[“Tel”]=tel; … cuky.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(cuky); } private void ReadKeys(…) { HttpCookie cuky = Request.Cookies[“UserInfo”]; firstname = cuky[“FirstName”]; lastname = cuky[“LastName”]; tel = cuky[“Tel”]; …. }

Storing User Information on the Server 1. Create a unique key to identify the user. 2. Save the unique key as a cookie on the user’s computer. 3. Create a file on the server to store user information. 4. Save the user information on the server using the unique key as an index. * System.Guid.NewGuid().ToString();

Security You should never store secrets in a cookie — no user names, no passwords, no credit card numbers, and so on. Do not put anything in a cookie that should not be in the hands of a user or of someone who might somehow steal the cookie. Similarly, be suspicious of information you get out of a cookie. Do not assume that the data is the same as when you wrote it out. Limit the scope of cookies to a folder on the server, which in practical terms allows you to limit cookies to an application on the site. Response.Cookies[“domain1”].Path = “/Application1”; Set scope to a domain, which allows you to specify which subdomains in a domain can access a cookie. Response.Cookies[“domain1”].Domain = “hadi.arbabi.com“; Set appropriate expiration date and time for cookies.

Security You can set a cookie property that causes the cookie to be transmitted only if the connection uses the Secure Sockets Layer (SSL, >> If(myCookie.Secure){ …. } If you do want to store sensitive information such as a user ID in a cookie, you can encrypt the cookie. Use HTTP-only Cookies. NOTE: To mitigate the risk of information disclosure with a cross-site scripting attack, a new attribute is introduced to cookies for Internet Explorer 6SP1. This attribute specifies that a cookie is not accessible through script. By using HTTP-only cookies, a Web site eliminates the possibility that sensitive information contained in the cookie can be sent to a hacker's computer or Web site with script. If a Web site sets an HTTP-only cookie on a browser that does not support HTTP-only cookies, the cookie is either ignored or downgraded to a traditional, scriptable cookies.

References Book Developing WEB APPLICATIONS with Microsoft Visual C#.NET Published by Microsoft Press (MCAD/MCSD) Web Libraries Microsoft Developer Network -HttpCookies -Cookies in.NET -State Management in ASP.NET