Cookies and sessions sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019 http://www.flickr.com/photos/torkildr/3462607995/

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

Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation.
Website Development Registering Users – Introducing Cookies.
Session Management A290/A590, Fall /25/2014.
CSE 154 LECTURE 13: SESSIONS. Expiration / persistent cookies setcookie("name", "value", expiration); PHP $expireTime = time() + 60*60*24*7; # 1 week.
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.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Cookies, Sessions, and Authentication Dr. Charles Severance
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.
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.
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
CS453: State in Web Applications (Part 1) State in General Sessions (esp. in PHP) Prof. Tom Horton.
Web Programming Language Week 7 Dr. Ken Cosh Security, Sessions & Cookies.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Session tracking There are a number of problems that arise from the fact that HTTP is a "stateless" protocol. In particular, when you are doing on- line.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
Nic Shulver, Introduction to Sessions in PHP Sessions What is a session? Example Software Software Organisation The login HTML.
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.
Cookies & Session Web Technology
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Web Database Programming Week 7 Session Management & Authentication.
Sessions, Cookies, &.htaccess IT 210. Procedural Issues  Quiz #3 Today!  Homework #3 Due Friday at midnight UML for Lab 4  Withdraw Deadline is Wed,
MEMBERSHIP AND IDENTITY Active server pages (ASP.NET) 1 Chapter-4.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
CP476 Internet Computing CGI1 Cookie –Cookie is a mechanism for a web server recall info of accessing of a client browser –A cookie is an object sent by.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Google App Engine Sessions and Cookies ae-09-session
Database Access Control IST2101. Why Implementing User Authentication? Remove a lot of redundancies in duplicate inputs of database information – Your.
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.
How to maintain state in a stateless web Shirley Cohen
Cloud Computing Computer Science Innovations, LLC.
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
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.
Internet Flow By: Terry Hernandez. Getting from the customers computer onto the internet Internet Browser
8-Mar-16 More About Servlets Session Tracking. Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information:
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.
COOKIES AND SESSIONS.
LOGIN FORMS.
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.
GENERAL SECURITY CONSIDERATIONS.
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
PHP – Hypertext Preprocessor.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● / www,histpk.org Hidaya Institute of Science & Technology
The need for persistence Consider these examples  Counting the number of “hits” on a website  i.e. how many times does a client load your web page source.
Cookies Tutorial Cavisson Systems Inc..
Tonga Institute of Higher Education IT 141: Information Systems
CHAPTER 5 SERVER SIDE SCRIPTING
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Assess Survey Invitations
ITM 352 Cookies.
Cookies and Sessions Charles Severance
Cross-Site Forgery
Web Programming Language
Cookies and Sessions in PHP
Cookies BIS1523 – Lecture 23.
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.
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Web Programming Language
Cookies and Sessions.
Web Programming Language
PHP-II.
Presentation transcript:

Cookies and sessions sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019 http://www.flickr.com/photos/torkildr/3462607995/

HTTP is “stateless” By default, web servers are “forgetful” As far as they can tell, every request comes from a totally new and different browser (Not exactly true. We'll discuss persistent connections in the context of performance.) sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Pros of stateless servers Chief benefit: Potential for replication Improved performance: A sysadmin can fire up N copies of a website (on N machines) and any machine can serve each request. Improved reliability: If a machine crashes, then another can be started up in its place, and no data gets lost in the process. sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Cons of stateless servers Chief problem: Keeping track of which requests "go together" Security challenge: If a user submits username & password in http request X, then tries to access resources in http request Y, how does the server know that request Y is from somebody who already logged in? By the time that request Y comes in, the server will already have forgotten that request X ever occurred. And on a replicated system, request Y might be served by a different machine than request X. sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Cookies to the rescue! Reminder: Cookie = a piece of data that is automatically copied between the client and server Cookies can be set by the client (as in the last unit) or by the server. sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

A simple way to use cookies for login… When user sends a valid username & password in request X, the server replies with a cookie containing the username & password When user subsequently makes request Y, the browser sends along the cookie. Sounds appealing: user only needs to log in once Serious security hole: anybody who gets his hands on the user's computer can see cookies sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Using just cookies for login Browser Server Type username & password Send username & password Authenticate Cookie = usernm&pwd Click a link or whatever Warning This design contains a serious security hole. Request page (send cookie) sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Send back page Saturday, February 23, 2019Saturday, February 23, 2019

A more secure way of cookies+login When user sends a valid username & password in request X, the server replies with a cookie containing a secret that the client couldn't possibly have guessed. When user subsequently makes request Y, the browser sends along the cookie. Since the client couldn't have guessed this value without logging in, the server knows that the user did in fact previously log in. sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Using cookies for login Browser Server Filesystem or Database Type username & password Send username & password Authenticate Store a random number valid only for next 10 minutes Cookie = the random # Click a link or whatever Request page (send cookie) Check if the number is right; if so, give another 10 minutes sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Send back page Saturday, February 23, 2019Saturday, February 23, 2019

Session = state stored across requests This is what we call a "session" Session is basically an add-on to the basic http functionality of a website So that the website can remember information across requests. You can store lots of stuff in session Numbers, strings, stringified objects, … sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Pros of sessions Stores information between requests Much more secure than the simple cookie-based approach I showed you A bad person would need to steal the random number (cookie) within 10 minutes of its creation sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Cons of sessions Requires your web server to have write-access to some sort of storage medium File system, database, …, if you want replication Otherwise just use memory (lost on server crash) Requires user to access site every few minutes Though you can configure longer or shorter times This is a tradeoff between usability & security. EECS servers currently are set to 24 minutes. sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Simple example of using session <?php session_start(); if (isset($_SESSION['numhits'])) $_SESSION['numhits'] = $_SESSION['numhits']+ 1; else $_SESSION['numhits'] = 1; echo "You hit my server ".$_SESSION['numhits']." times."; ?> sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Authentication (Using hardcoded username&pwd for now) <?php session_start(); /* login.php */ if (array_key_exists("username", $_REQUEST) && array_key_exists("password", $_REQUEST)) { /* here is where we would check the username and password */ $_SESSION['uid'] = 1; echo '<a href="inventory.php">View Inventory</a>'; } else { ?> <form action="login.php" method="POST"> <div>Username: <input type="text" name="username"></div> <div>Password: <input type="password" name="password"></div> <div><input type="submit" value="OK"></div> </form> <?php } <?php session_start(); /* inventory.php */ if (isset($_SESSION['uid'])) echo "This is where we would show inventory."; else echo "You need to <a href='login.php'>Log in</a>"; ?> sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

You can set cookies without session <?php $nhits = isset($_COOKIE['numhits']) ? $_COOKIE['numhits'] : 0; $nhits = $nhits + 1; setcookie('numhits', $nhits, time()+86400*365); /* expires in 365 days */ echo "You hit my server ".$nhits." times."; ?> sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Summarizing cookies vs sessions Little bits of data that are stored on client but also copied automatically to the server Useful for storing little bits of data on the client, but they are visible to everybody So don't store sensitive data in cookies Sessions Data is stored on the server (e.g., filesystem), keyed by a random number The random number is sent as a cookie to the browser And the random number expires after a little while sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

When to use cookies vs sessions Use cookies when You need to save a small amount of data between requests, and it doesn't need to be kept secret Use sessions when You need to save a larger amount of data between requests, or when the data needs to be secret sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Examples of information not to store in unencrypted cookies Passwords Credit card numbers Social security numbers Student ID numbers Birthdates List of diseases the user has contracted Anything that must be kept secret sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019

Yet another caveat After all of those warnings, you still can save secret data in cookies, IF IT IS ENCRYPTED You will see how to do this later in the term But we don't really use encrypted cookies much because it can cause usability problems. sohamsengupta@yahoo.com, soham.sengupta.java@gmail.com Saturday, February 23, 2019Saturday, February 23, 2019