SlideShare a Scribd company logo
1 of 29
COOKIES & SESSION
Advanced
YOU HAVE ZERO PRIVACY
ANYWAY
Scott McNealy (Sun Microsystems)
What is Cookie?
 A cookie is a text-only string created by the
website you navigate and gets entered into
the memory of the browser.
 If the lifetime of this value is set to be longer
than the time you spend at that site, then this
string is saved to file for future reference.
Historical Brief
 Lou Montulli, protocols manager in
Netscape's client product division, wrote the
cookies specification for Navigator 1.0.
 Netscape Navigator 1.0 the first browser to
use the technology.
Cookie Anatomy
 A Cookie can have 6 parameters passed to it
 Name (Mandatory)
 Value (Mandatory)
 Expiration Date (If not set the default is end of
session).
 Path
 Domain
 Secure Connected Required
Cookie Anatomy – Expiration Date
 The expires parameter lets you determine the
lifetime of the cookie.
 If not set explicitly, then it defaults to end-of-
session.
 The length of a session is the length of time
that the browser is open for (even if the user
is no longer at that site).
Cookie Anatomy – Path
 It sets the URL path the cookie is valid
within.
 Pages outside of that path cannot read or
use the cookie.
Cookie Anatomy – Domain
 If a site uses multiple servers within a domain then it is important to
make the cookie accessible to pages on any of these servers.
 Cookies can be assigned to individual machines, or to an entire
Internet domain.
 The only restrictions on this value is that it must contain at least two
dots (.myserver.com, not myserver.com) for the normal top-level
domains, or three dots for the "extended" domains
(.myserver.ny.us, not myserver.ny.us)
 The server issuing the cookie must be a member of the domain that
it tries to set in the cookie.That is, a server called
www.myserver.com cannot set a cookie for the domain
www.yourserver.com.The security implications should be obvious
 If Domain is not set explicitly, then it defaults to the full domain of the
document creating the cookie.
Cookie Anatomy – Secure
 False by default; only used in HTTPS
websites.
Create Cookie
 In PHP use the function: setcookie
 Setcookie takes the 6 parameters
 Name
 Value
 Expire Date
 Path
 Domain
 Secure
Retrieving a Cookie Value
 Cookies can be read on the browser side or the server side.
Again, the determining factor is the language used.
 The main limit on retrieving a cookie is that you can only
retrieve cookies that are valid for the document your script
resides in.That is, a script on www.myserver.com cannot
read cookies from www.yourserver.com.
 Also for subdirectories within your site.A cookie valid for
/dirOne cannot be read by a script in /dirTwo.This is mainly
governed on the browser side, as browsers know the URL
that they are accessing, and only transmit cookies for that
server across the connection.
Retrieving Cookie (PHP)
 Use the variable $_COOKIE[‘name’]
Clearing Cookie Value
 Set the cookie's value to null.
 Set the cookie's expiration date to some
time in the past.
What is a session?
 You are working with an application.You
open it, make some changes, and then you
close it.That is a session.
How session works?
 Each user accessing the website has a unique
ID assigned to him managed by PHP.
 Session Stores the information on the server
rather than the client side like in Cookies.
What is $_SESSION
 It is a special array used to store
information across the page requests a
user makes during his visit to your website
or web application.
Starting Session
 session_start() starts the session between
the user and the server, and allows values
stored in $_SESSION to be accessible in
other scripts later on.
Killing Session Variables
 To end single session variable use unset(‘session
variable’)
 To unset all of the session’s values, you can use
the session_unset() function.
 It is very important to clean up after yourself
to ensure maximum security when dealing
with potentially sensitive information.
 To avoid having a huge amount of stale
session data sitting on the server.
Terminate Session
 session_destroy() is responsible for
terminating the session so you can no more
access/store session variables in the array
$_SESSION.
Session Security Tips
 SettingTimeout
 Regenerate Session ID
 Destroy Session
 Use Permanent storage
Session Timeout
 Timing-out sessions is a very important
action if you are dealing with users logged
in to your website or application. If a user
logs in to your site in an Internet café and
then leaves the computer and café without
logging out, how do you stop the next user
on that computer from still having access
to the previous user’s session?
Regenerate Session ID
 The session_regenerate_id() function creates a
new unique-ID for to represent the current user’s
session.
 This should be regenerated time any important
authentication action is performed, such as
logging in or updating user profile data.
 Giving the sessions a new ID after such actions
make your application more secure by reducing
the risk of a specific attack known as “Session
Hijacking.”
Destroy Session
 This stops attackers from hijack the stale
session, again increasing the session-related
security of your web site.
Use Permanent Storage
 Use a database to store data at the earliest
moment you know the data will be persistent;
don’t let it stay as part of the session for too
long as this opens it up to possible attack.
Really think about whether the data belongs
should be stored in $_SESSION because
session data is meant to be transient.
Session Hacking
 Session Fixation
 Prediction
 Capture
 Fixation -- Exclude
 Session Hijacking
Session Fixation (Prediction)
 Rarely used.
 Prediction refers to guessing a valid session
identifier.With PHP's native session
mechanism, the session identifier is
extremely random, and this is unlikely to be
the weakest point in your implementation.
Session Fixation (Capture)
 Most Common.
 Because session identifiers are typically propagated
in cookies or as GET variables, the different
approaches focus on attacking these methods of
transfer.
 While there have been a few browser vulnerabilities
regarding cookies, these have mostly been Internet
Explorer, and cookies are slightly less exposed than
GET variables.
 Thus, for those users who enable cookies, you can
provide them with a more secure mechanism by
using a cookie to propagate the session identifier.
Sesson Hijacking
 Most common session attack
 Session hijacking refers to all attacks that
attempt to gain access to another user's
session.
 If your session mechanism only consists
of session_start(), you are vulnerable,
although the exploit isn't as simple.
Session Hijacking
 Rather than focusing on keeping the session
identifier from being captured, focus on how
to make such a capture less problematic.
 The goal is to complicate impersonation,
since every complication increases security.
 With the most simplistic session mechanism,
a valid session identifier is all that is needed
to successfully hijack a session. In order to
improve this, we need to see if there is
anything extra in an HTTP request that we
can use for extra identification

More Related Content

What's hot

Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessionsUdaAs PaNchi
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanismJivan Nepali
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookiesmussawir20
 
PHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and AuthenticationPHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and AuthenticationGerard Sychay
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and SessionsNisa Soomro
 
Internet Cookies
Internet CookiesInternet Cookies
Internet Cookiesanita gouda
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In PhpHarit Kothari
 
Web Cookies
Web CookiesWeb Cookies
Web Cookiesapwebco
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introductionProgrammer Blog
 
Who is Afraid of Cookies?
Who is Afraid of Cookies?Who is Afraid of Cookies?
Who is Afraid of Cookies?Asaf Gery
 
PHP - Getting good with cookies
PHP - Getting good with cookiesPHP - Getting good with cookies
PHP - Getting good with cookiesFirdaus Adib
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erickokelloerick
 

What's hot (20)

Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Introduction to php web programming - sessions and cookies
Introduction to php   web programming - sessions and cookiesIntroduction to php   web programming - sessions and cookies
Introduction to php web programming - sessions and cookies
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
 
PHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and AuthenticationPHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and Authentication
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Internet Cookies
Internet CookiesInternet Cookies
Internet Cookies
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Web Cookies
Web CookiesWeb Cookies
Web Cookies
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
Php session
Php sessionPhp session
Php session
 
Who is Afraid of Cookies?
Who is Afraid of Cookies?Who is Afraid of Cookies?
Who is Afraid of Cookies?
 
PHP - Getting good with cookies
PHP - Getting good with cookiesPHP - Getting good with cookies
PHP - Getting good with cookies
 
Cookie
CookieCookie
Cookie
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
ASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and CookiesASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and Cookies
 

Viewers also liked

Viewers also liked (13)

EVALUACIÓN
EVALUACIÓNEVALUACIÓN
EVALUACIÓN
 
Hackers
HackersHackers
Hackers
 
Hacking
Hacking Hacking
Hacking
 
Hacking
HackingHacking
Hacking
 
Chap ii.BCD code,Gray code
Chap ii.BCD code,Gray codeChap ii.BCD code,Gray code
Chap ii.BCD code,Gray code
 
Baking cookies
Baking cookiesBaking cookies
Baking cookies
 
Hacker&cracker
Hacker&crackerHacker&cracker
Hacker&cracker
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Virus (Trojan Horse and Salami Attack)
Virus (Trojan Horse and Salami Attack)Virus (Trojan Horse and Salami Attack)
Virus (Trojan Horse and Salami Attack)
 
Ipv4 and Ipv6
Ipv4 and Ipv6Ipv4 and Ipv6
Ipv4 and Ipv6
 
Hackers ESP
Hackers ESPHackers ESP
Hackers ESP
 
Ipv4 vs Ipv6 comparison
Ipv4 vs Ipv6 comparisonIpv4 vs Ipv6 comparison
Ipv4 vs Ipv6 comparison
 
IPv4 and IPv6
IPv4 and IPv6IPv4 and IPv6
IPv4 and IPv6
 

Similar to Cookies and Session

Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessionssalissal
 
Customized Browser Displaying Multiple Sessions in a Carousel View
Customized Browser Displaying Multiple Sessions in a Carousel ViewCustomized Browser Displaying Multiple Sessions in a Carousel View
Customized Browser Displaying Multiple Sessions in a Carousel ViewMike Taylor
 
Openam misc
Openam miscOpenam misc
Openam miscJose R
 
CMS Website Security Threat Protection Oriented Analyzer System
CMS Website Security Threat Protection Oriented Analyzer SystemCMS Website Security Threat Protection Oriented Analyzer System
CMS Website Security Threat Protection Oriented Analyzer SystemEditor IJCATR
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptSreejithVP7
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)kunjan shah
 
Web Browser Privacy and Security
Web Browser Privacy and SecurityWeb Browser Privacy and Security
Web Browser Privacy and SecurityDaVidSilenceKawlni
 
Proxy Caches and Web Application Security
Proxy Caches and Web Application SecurityProxy Caches and Web Application Security
Proxy Caches and Web Application Security Tim Bass
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfHumphreyOwuor1
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application SecurityNelsan Ellis
 
E Commerce Analytics Demandware
E Commerce Analytics DemandwareE Commerce Analytics Demandware
E Commerce Analytics Demandwareloripelletier
 

Similar to Cookies and Session (20)

S8-Session Managment
S8-Session ManagmentS8-Session Managment
S8-Session Managment
 
Php sessions
Php sessionsPhp sessions
Php sessions
 
Cookies-PHP
Cookies-PHPCookies-PHP
Cookies-PHP
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
 
Customized Browser Displaying Multiple Sessions in a Carousel View
Customized Browser Displaying Multiple Sessions in a Carousel ViewCustomized Browser Displaying Multiple Sessions in a Carousel View
Customized Browser Displaying Multiple Sessions in a Carousel View
 
Openam misc
Openam miscOpenam misc
Openam misc
 
Sessions&cookies
Sessions&cookiesSessions&cookies
Sessions&cookies
 
CMS Website Security Threat Protection Oriented Analyzer System
CMS Website Security Threat Protection Oriented Analyzer SystemCMS Website Security Threat Protection Oriented Analyzer System
CMS Website Security Threat Protection Oriented Analyzer System
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.pptLecture 11 - PHP - Part 5 - CookiesSessions.ppt
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
 
Download It
Download ItDownload It
Download It
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)
 
Web Browser Privacy and Security
Web Browser Privacy and SecurityWeb Browser Privacy and Security
Web Browser Privacy and Security
 
070308-simmons.ppt
070308-simmons.ppt070308-simmons.ppt
070308-simmons.ppt
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 
Session tracking In Java
Session tracking In JavaSession tracking In Java
Session tracking In Java
 
Proxy Caches and Web Application Security
Proxy Caches and Web Application SecurityProxy Caches and Web Application Security
Proxy Caches and Web Application Security
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 
E Commerce Analytics Demandware
E Commerce Analytics DemandwareE Commerce Analytics Demandware
E Commerce Analytics Demandware
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 

Cookies and Session

  • 2. YOU HAVE ZERO PRIVACY ANYWAY Scott McNealy (Sun Microsystems)
  • 3. What is Cookie?  A cookie is a text-only string created by the website you navigate and gets entered into the memory of the browser.  If the lifetime of this value is set to be longer than the time you spend at that site, then this string is saved to file for future reference.
  • 4. Historical Brief  Lou Montulli, protocols manager in Netscape's client product division, wrote the cookies specification for Navigator 1.0.  Netscape Navigator 1.0 the first browser to use the technology.
  • 5. Cookie Anatomy  A Cookie can have 6 parameters passed to it  Name (Mandatory)  Value (Mandatory)  Expiration Date (If not set the default is end of session).  Path  Domain  Secure Connected Required
  • 6. Cookie Anatomy – Expiration Date  The expires parameter lets you determine the lifetime of the cookie.  If not set explicitly, then it defaults to end-of- session.  The length of a session is the length of time that the browser is open for (even if the user is no longer at that site).
  • 7. Cookie Anatomy – Path  It sets the URL path the cookie is valid within.  Pages outside of that path cannot read or use the cookie.
  • 8. Cookie Anatomy – Domain  If a site uses multiple servers within a domain then it is important to make the cookie accessible to pages on any of these servers.  Cookies can be assigned to individual machines, or to an entire Internet domain.  The only restrictions on this value is that it must contain at least two dots (.myserver.com, not myserver.com) for the normal top-level domains, or three dots for the "extended" domains (.myserver.ny.us, not myserver.ny.us)  The server issuing the cookie must be a member of the domain that it tries to set in the cookie.That is, a server called www.myserver.com cannot set a cookie for the domain www.yourserver.com.The security implications should be obvious  If Domain is not set explicitly, then it defaults to the full domain of the document creating the cookie.
  • 9. Cookie Anatomy – Secure  False by default; only used in HTTPS websites.
  • 10. Create Cookie  In PHP use the function: setcookie  Setcookie takes the 6 parameters  Name  Value  Expire Date  Path  Domain  Secure
  • 11. Retrieving a Cookie Value  Cookies can be read on the browser side or the server side. Again, the determining factor is the language used.  The main limit on retrieving a cookie is that you can only retrieve cookies that are valid for the document your script resides in.That is, a script on www.myserver.com cannot read cookies from www.yourserver.com.  Also for subdirectories within your site.A cookie valid for /dirOne cannot be read by a script in /dirTwo.This is mainly governed on the browser side, as browsers know the URL that they are accessing, and only transmit cookies for that server across the connection.
  • 12. Retrieving Cookie (PHP)  Use the variable $_COOKIE[‘name’]
  • 13. Clearing Cookie Value  Set the cookie's value to null.  Set the cookie's expiration date to some time in the past.
  • 14. What is a session?  You are working with an application.You open it, make some changes, and then you close it.That is a session.
  • 15. How session works?  Each user accessing the website has a unique ID assigned to him managed by PHP.  Session Stores the information on the server rather than the client side like in Cookies.
  • 16. What is $_SESSION  It is a special array used to store information across the page requests a user makes during his visit to your website or web application.
  • 17. Starting Session  session_start() starts the session between the user and the server, and allows values stored in $_SESSION to be accessible in other scripts later on.
  • 18. Killing Session Variables  To end single session variable use unset(‘session variable’)  To unset all of the session’s values, you can use the session_unset() function.  It is very important to clean up after yourself to ensure maximum security when dealing with potentially sensitive information.  To avoid having a huge amount of stale session data sitting on the server.
  • 19. Terminate Session  session_destroy() is responsible for terminating the session so you can no more access/store session variables in the array $_SESSION.
  • 20. Session Security Tips  SettingTimeout  Regenerate Session ID  Destroy Session  Use Permanent storage
  • 21. Session Timeout  Timing-out sessions is a very important action if you are dealing with users logged in to your website or application. If a user logs in to your site in an Internet café and then leaves the computer and café without logging out, how do you stop the next user on that computer from still having access to the previous user’s session?
  • 22. Regenerate Session ID  The session_regenerate_id() function creates a new unique-ID for to represent the current user’s session.  This should be regenerated time any important authentication action is performed, such as logging in or updating user profile data.  Giving the sessions a new ID after such actions make your application more secure by reducing the risk of a specific attack known as “Session Hijacking.”
  • 23. Destroy Session  This stops attackers from hijack the stale session, again increasing the session-related security of your web site.
  • 24. Use Permanent Storage  Use a database to store data at the earliest moment you know the data will be persistent; don’t let it stay as part of the session for too long as this opens it up to possible attack. Really think about whether the data belongs should be stored in $_SESSION because session data is meant to be transient.
  • 25. Session Hacking  Session Fixation  Prediction  Capture  Fixation -- Exclude  Session Hijacking
  • 26. Session Fixation (Prediction)  Rarely used.  Prediction refers to guessing a valid session identifier.With PHP's native session mechanism, the session identifier is extremely random, and this is unlikely to be the weakest point in your implementation.
  • 27. Session Fixation (Capture)  Most Common.  Because session identifiers are typically propagated in cookies or as GET variables, the different approaches focus on attacking these methods of transfer.  While there have been a few browser vulnerabilities regarding cookies, these have mostly been Internet Explorer, and cookies are slightly less exposed than GET variables.  Thus, for those users who enable cookies, you can provide them with a more secure mechanism by using a cookie to propagate the session identifier.
  • 28. Sesson Hijacking  Most common session attack  Session hijacking refers to all attacks that attempt to gain access to another user's session.  If your session mechanism only consists of session_start(), you are vulnerable, although the exploit isn't as simple.
  • 29. Session Hijacking  Rather than focusing on keeping the session identifier from being captured, focus on how to make such a capture less problematic.  The goal is to complicate impersonation, since every complication increases security.  With the most simplistic session mechanism, a valid session identifier is all that is needed to successfully hijack a session. In order to improve this, we need to see if there is anything extra in an HTTP request that we can use for extra identification

Editor's Notes

  1. The path parameter is potentially the most useful of the 4 optional cookie settings. It sets the URL path the cookie is valid within. Pages outside of that path cannot read or use the cookie.  ... path=/promo ...If Path is not set explicitly, then it defaults to the URL path of the document creating the cookie. 
  2. Domain  The domain parameter takes the flexibility of the path parameter one step further. If a site uses multiple servers within a domain the it is important to make the cookie accessible to pages on any of these servers.  ... domain=www.myserver.com ...Cookies can be assigned to individual machines, or to an entire Internet domain. The only restrictions on this value is that it must contain at least two dots (.myserver.com,not myserver.com) for the normal top-level domains, or three dots for the "extended" domains (.myserver.ny.us, not myserver.ny.us)  IMPORTANT: The server issuing the cookie must be a member of the domain that it tries to set in the cookie. That is, a server called www.myserver.com cannot set a cookie for the domain www.yourserver.com. The security implications should be obvious. 
  3. 4.3 Retrieving a Cookie Value  For the most part, retrieving cookies does not require reading the HTTP Cookie: header. Most languages read this header for you and make it accessible through a variable or object.  Cookies can be read on the browser side or the server side. Again, the determining factor is the language used.  The main limit on retrieving a cookie is that you can only retrieve cookies that are valid for the document your script resides in. That is, a script on www.myserver.com cannot read cookies from www.yourserver.com. This is also true for subdirectories within your site. A cookie valid for /dirOne cannot be read by a script in /dirTwo. This is mainly governed on the browser side, as browsers know the URL that they are accessing, and only transmit cookies for that server across the connection.
  4. 4.4 Clearing a Cookie Value  When programming a Web site, there are many reasons that you may need to erase a cookie you have created. Often it is because the cookie is no longer needed, or the scheme of your cookie has been altered, and requires resetting.  The two main steps to clearing a cookie you have created are: Set the cookie's value to null. Set the cookie's expiration date to some time in the past. The reason you must do both is that simply setting the expiration to a past time will not change it's value until the browser is closed. That is, all cookie names, values, expirations, etc are resolved once the browser program has been closed. Setting the cookie to null allows you to properly test for the cookie until that resolution.
  5. You are working with an application. You open it, make some changes, and then you close it.
  6. While there may be many users accessing the site at the same time, each with his own session, it’s thanks to unique IDs assigned and managed by PHP for each session that allows each user’s session to be available only to himself. Session information is stored on the server rather than the user’s computer (as cookie data is stored), which makes sessions more secure than traditional cookies for passing information between page requests.
  7. $_SESSION is a special array used to store information across the page requests a user makes during his visit to your website or web application. The most fundamental way to explain what a sessions is like is to imagine the following scenario:
  8. Ending a Session As important as it is to begin a session, so it is to end one. Even though a session is only a temporary way to store data, it is very important to clean up after yourself to ensure maximum security when dealing with potentially sensitive information. It is also good practice and will avoid having a huge amount of stale session data sitting on the server. To delete a single session value, you use the unset() function:
  9. <?php session_start(); // set time-out period (in seconds) $inactive = 600; // check to see if $_SESSION["timeout"] is set if (isset($_SESSION["timeout"])) { // calculate the session's "time to live" $sessionTTL = time() - $_SESSION["timeout"]; if ($sessionTTL > $inactive) { session_destroy(); header("Location: /logout.php"); } } $_SESSION["timeout"] = time();
  10. <?php session_start(); if ($_POST["username"] == "admin" && $_POST["password"] == sha1("password")) { $_SESSION["authorized"] = true; session_regenerate_id(); }
  11. It is unwise to rely on anything at the TCP/IP level, such as IP address, because these are lower level protocols that are not intended to accommodate activities taking place at the HTTP level. A single user can potentially have a different IP address for each request, and multiple users can potentially have the same IP address.