Sessions. Mendel Rosenblum. CS142 Lecture Notes - Sessions

Similar documents
Front End Programming

Persistence. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Persistence & State. SWE 432, Fall 2016 Design and Implementation of Software for the Web

Large-Scale Web Applications

Cookies, sessions and authentication

CS 142 Final Examination

CNIT 129S: Securing Web Applications. Ch 3: Web Application Technologies

Managing State. Chapter 13

Storage Tier. Mendel Rosenblum. CS142 Lecture Notes - Database.js

Controller/server communication

CS142 - Web Applications

Controller/server communication

How to Configure SSL VPN Portal for Forcepoint NGFW TECHNICAL DOCUMENT

CN Assignment I. 1. With an example explain how cookies are used in e-commerce application to improve the performance.

WEB APPLICATION ENGINEERING II

CS144: Sessions. Cookie : CS144: Web Applications

Cookie Security. Myths and Misconceptions. David Johansson OWASP London 30 Nov. 2017

8.0 Help for Community Managers Release Notes System Requirements Administering Jive for Office... 6

Introduction. Server-side Techniques. Introduction. 2 modes in the PHP processor:

CMSC 332 Computer Networking Web and FTP

Cloud Help for Community Managers...3. Release Notes System Requirements Administering Jive for Office... 6

DreamFactory Security Guide

Lecture 9a: Sessions and Cookies

Future Web App Technologies

GET /index.php HTTP/1.1 Host: User- agent: Mozilla/4.0

Developing Applications with Alfresco s Unified REST APIs. Will Abson, Alfresco

ASP.NET State Management Techniques

MongoDB Web Architecture

ColdFusion Application Security: The Next Step - Handout

P2_L12 Web Security Page 1

CS193X: Web Programming Fundamentals

a Very Short Introduction to AngularJS

Smashing Node.JS: JavaScript Everywhere

welcome to BOILERCAMP HOW TO WEB DEV

INTERNET ENGINEERING. HTTP Protocol. Sadegh Aliakbary

Backend Development. SWE 432, Fall 2017 Design and Implementation of Software for the Web

eb Security Software Studio

Real Life Web Development. Joseph Paul Cohen

RESTful Services. Distributed Enabling Platform

Jquery.ajax Call Returns Status Code Of 200 But Fires Jquery Error

Firmware Update Procedure by HTTP Server (FIRMWARE1/FIRMWARE2/FIRMWARE3/FIRMWARE4) Rev.5.0

Tuesday, January 13, Backend III: Node.js with Databases

Attacks Against Websites. Tom Chothia Computer Security, Lecture 11

CSC 482/582: Computer Security. Cross-Site Security

Web, HTTP and Web Caching

Input and Validation. Mendel Rosenblum. CS142 Lecture Notes - Input

RKN 2015 Application Layer Short Summary

Mobile Site Development

Lecture 7b: HTTP. Feb. 24, Internet and Intranet Protocols and Applications

Computer Networks. Wenzhong Li. Nanjing University

Single Page Applications

We are assuming you have node installed!

Development of Web Applications

Backend IV: Authentication, Authorization and Sanitization. Tuesday, January 13, 15

Combating Common Web App Authentication Threats

Web Security. Web Programming.

flask-jwt-extended Documentation

Scaling DreamFactory

Security. CSC309 TA: Sukwon Oh

Microservices with Node.js

OWASP Top 10. from a developer s perspective. John Wilander, OWASP/Omegapoint, IBWAS 10

Attacks Against Websites 3 The OWASP Top 10. Tom Chothia Computer Security, Lecture 14

THE FLEXIBLE DATA-STRUCTURE SERVER THAT COULD.

5/19/2015. Objectives. JavaScript, Sixth Edition. Saving State Information with Query Strings. Understanding State Information

HyperText Transfer Protocol

Web basics: HTTP cookies

What is Node.js? Tim Davis Director, The Turtle Partnership Ltd

Serverless Single Page Web Apps, Part Four. CSCI 5828: Foundations of Software Engineering Lecture 24 11/10/2016

GraphQL in Python and Django. Patrick

Enhancing cloud applications by using external authentication services. 2015, 2016 IBM Corporation

Ruby on Rails Secure Coding Recommendations

How is state managed in HTTP sessions. Web basics: HTTP cookies. Hidden fields (2) The principle. Disadvantage of this approach

Autopopulation; Session & Cookies

Chapter 2: Application Layer. Chapter 2 Application Layer. Some network apps. Application architectures. Chapter 2: Application layer

Contents. xvii xix xxiil. xxvii

CS 5450 HTTP. Vitaly Shmatikov

LEMONLDAP::NG 2.0. FOSDEM 2019

SC/CSE 3213 Winter Sebastian Magierowski York University CSE 3213, W13 L8: TCP/IP. Outline. Forwarding over network and data link layers

BUILDING THE FASTEST DRUPAL OF THE GALAXY

s642 web security computer security adam everspaugh

LAN protected by a Firewall. ArcGIS Server. Web Server. GIS Server. Reverse Proxy. Data

Azure Developer Immersions API Management

Web basics: HTTP cookies

Authentication for Web Services. Ray Miller Systems Development and Support Computing Services, University of Oxford

CS 155 Project 2. Overview & Part A

Improving Web Security:

Some Facts Web 2.0/Ajax Security

1-1. Switching Networks (Fall 2010) EE 586 Communication and. September Lecture 10

Using OAuth 2.0 to Access ionbiz APIs

Please post bugs on our forum on or us on

Application Security through a Hacker s Eyes James Walden Northern Kentucky University

flask-jwt Documentation

Ethical Hacking as a Professional Penetration Testing Technique ISSA Southern Tier & Rochester Chapters

GETTING STARTED WITH MARKETPLACE PORTAL

WEB API. Nuki Home Solutions GmbH. Münzgrabenstraße 92/ Graz Austria F

Avoiding Web Application Flaws In Embedded Devices. Jake Edge LWN.net URL for slides:

Review of Previous Lecture

Device Recognition Best Practices Guide

Yioop Full Historical Indexing In Cache Navigation. Akshat Kukreti

PowerExchange for Facebook: How to Configure Open Authentication using the OAuth Utility

Transcription:

Sessions Mendel Rosenblum

How do we know what user sent request? Would like to authenticate user and have that information available each time we process a request. More generally web apps would like to keep state per active browser Concretely: Called session state expressapp.get('/user/:user_id', function (httprequest, httpresponse) // Need to make a decision to accept the request or reject it var sessionstate = GetSessionState(httpRequest);

Where could we get the session state from? Maybe Here? Not Here - Stateless Here Web Browser Web Server Storage System HTTP Internet LAN 3

Session state lookup problem HTTP request just come into a web server Not a lot information to uniquely identify "session" Solution: Include something in the request to tells us the session Care must taken to avoid forgeries Early HTTP solution: Cookies State set by web server that browser attaches to every request Useful but with a checkered history Modern browser support local storage API

HTTP Cookies: Basic Idea Web server adds Set-Cookie: to HTTP response header Set-Cookie: cookie_name1=cookie_value1 Set-Cookie: cookie_name2=cookie_value2; expires=sun, 16 Jul 2016 06:23:41 GMT Each cookie is just a name-value pair. Future requests from browser to same server should include the Cookie:header Cookie: cookie_name1=cookie_value1; cookie_name2=cookie_value2

Cookie contents Cookie: name and data Domain for this cookie: server, port (optional), URL prefix (optional) The cookie is only included in requests matching its domain Expiration date: browser can delete old cookies Limits: Data size limited by browsers (typically < 4 KB) Browsers limit the number of cookies per server (around 50)

Cookies as web app storage User can: View cookies Modify/corrupt cookies Delete cookies Create cookies Lose cookies to hackers Simply switching browsers looks like you deleted the app's cookies Cookies have been used in bad ways (more later in class): Users are suspicious of them Pretty unreliable web app storage Limited to hint, shortcut, etc. that can be recovered if missing While actively communicating with web app: Session cookies

Session state with cookies Early web frameworks (e.g. Rails) supported storing session state in cookies Rails provided session, a JavaScript-like object, that you could store anything session[:user_id] = "mendel" Rails packaged session into a cookie and added to HTTP response Data will be available in all future requests from the same browser Rails automatically checks for a session cookie at the start of each request: Cookie exists? use it to find session data No cookie? Create new session, new cookie End of each request: save session data where it can be found by future requests. (where?)

Session state in cookies Early approach: Store session state in cookie Since cookies can be viewed, changed, deleted, stolen, etc. care must be taken. Example: session.user_id = "mendel"; session.password = "foobar"; Using cryptography you can: Hide content from viewers, hackers Detect forgeries and changes Can't do much about deletions An alternative is to put a pointer to the session state in the cookie: Set-Cookie: session=0x4137fd6a; Expires=Wed, 09 Jun 2012 10:18:14 GMT Less transfer overhead but still need to protect with cryptography

Options for storing session state Web server's memory Fastest access May be too large (many active users) Makes load balancing across web servers hard Storage system Easily shared across all the web servers May be overkill: Don't need the super reliability of storage system May be too much load for the storage system Specialized storage system Support fast fetching of small, short-lived data Example: memcache, redis - in memory key-value stores

var session = require('express-session'); ExpressJS has a middleware layer for dealing with the session state Usage: Stores a sessionid safely in a cookie Store session state in a session state store Like Rails, handles creation and fetching of session state for your request handlers app.use(session({secret: 'badsecret'})); secret is used to cryptographically sign the sessionid cookie app.get('/user/:user_id', function (httprequest, httpresponse) httprequest.session is an object you can read or write

Express session usage example Login handler route can store into httprequest.session.user_id All other handlers read httprequest.session.user_id If not set error or redirect to login page Otherwise we know who is logged in Can put other per-session state in httprequest.session On logged out you will want to destroy the session httprequest.session.destroy(function (err) { } );

Express Session: Session Store Default session store is in the Node.js memory OK for development but not production Has session store backends for many storage systems Hooking up to MongoDB via Mongoose var MongoStore = require('connect-mongo')(express); expressapp.use(session({ store: new MongoStore({ mongooseconnection: mongoose.connection }) }));

Cookie replacement: Web Storage API sessionstorage - Per origin storage available when page is open localstorage - Per origin storage with longer lifetime Standard key-value interface: localstorage.appsetting = 'Anything'; localstorage.setitem('appsetting', 'Anything'); sessionstorage['app2setting'] = 2; Limited space (~10MB) and similar reliability issues to cookies