Lets learn "What are HTTP Cookies?"
So in this tutorial we will going to learning about cookies , Web cookies .
So do you know how it is possible that u needn't login every time of sites like facebook , gmail etc.
Once u logged in , u needn't login again until or unless u logout.
But in case of banking sites every time you visit u need to login.
How is this done ?
The answer to this is cookies .
What are cookies ?
A HTTP cookie (also called web cookie, Internet cookie, browser cookie or simply cookie) is a small piece of data sent from a website and stored on the user's computer by the user's web browser while the user is browsing. Cookies were designed to be a reliable mechanism for websites to remember stateful information (such as items added in the shopping cart in an online store) or to record the user's browsing activity (including clicking particular buttons, logging in, or recording which pages were visited in the past).
So cookies are some piece of data that is returned by the server when request to server is made (like login request) and this piece of data is saved by web browser and sent with every request (as a cookie parameter) to the same website (to which cookie is related).
If the cookies are stored in user web browser , so definitely it is possible for the user to see this .
Lets see how to see the cookies stored in browser for any site .
Download a cookie manager , which is an extension in chrome (icon is of fourth number from left in the image above ). You can download from here .
Once u add the extension to chrome , visit any site for which u want to see the cookies and after the site completes loading , open the cookie manager from chrome>tools>Extensions>Cookie Manager options to see the cookies .
For e.g : Lets see the cookies for www.flipkart.com
After login in the flipkart.com , go to cookies manager and search www.flipkart.com .
Now in flipkart.com cookie named as SN stores the session for the user (i.e it is the main cookie which identifies which and wheather user is logged in or not). Lets see this .
First lets talk about the different attributes stored for cookies as shown in above image .
1. Domain Name : It defines the name for which this cookie is related (.flipkart.com in our case) .
2. Path : it defines the path address for the cookie.
3. Name : It defines the name of the cookie (SN in our case).
4. Value : It is the value for the cookie .
5. Expires : It defines the expiry time for the cookie (date + time).
6. Session : It is checked if cookie is a session cookie as opposed to a persistent cookie with the expireation date .
7. Host-Only : It defines that this cookie is only read by the sites which is having the domain .flipkart.com(as specified in Domain name) .
8. Read-Only : It defines that wheather cookie can be overwrite using client-side javascript or not .
If it is checked , then cookie is only readable , javascript can't overwrite it.
9. Secure / HttpOnly : It defines that wheather it is possible to access the cookie by javascript (like document.cookies provide the cookies in javascript) but if Secure is checked , javascript will unable to access the required cookie .
And That's all about the cookie attributes ...
Now let me show you the magic of cookies...
* Open the flipkart.com and login there .
* Open the cookie manager to see the flipkart.com cookies .
* As SN is the session cookie for flipkart , just modify the cookie (either delete , replace or insert new characters) and save it .
* Now refresh the flipkart.com and you will see that you'll automatically get logged out .
* This is the power of cookie .
And even if you are able to access the cookie of any of your friend (like SN cookie of flipkart.com) , just copy and paste that cookie in cookie manager and refresh the page . You will able to login as your friend(whose cookie u have captured) . This is known as Session Hijacking .
So....
Hope you like this short tutorial on HTTP cookies .
Stay tuned for upcoming tutorials .
For any problem or queries, please comment below...
1. Domain Name : It defines the name for which this cookie is related (.flipkart.com in our case) .
2. Path : it defines the path address for the cookie.
3. Name : It defines the name of the cookie (SN in our case).
4. Value : It is the value for the cookie .
5. Expires : It defines the expiry time for the cookie (date + time).
6. Session : It is checked if cookie is a session cookie as opposed to a persistent cookie with the expireation date .
7. Host-Only : It defines that this cookie is only read by the sites which is having the domain .flipkart.com(as specified in Domain name) .
8. Read-Only : It defines that wheather cookie can be overwrite using client-side javascript or not .
If it is checked , then cookie is only readable , javascript can't overwrite it.
9. Secure / HttpOnly : It defines that wheather it is possible to access the cookie by javascript (like document.cookies provide the cookies in javascript) but if Secure is checked , javascript will unable to access the required cookie .
And That's all about the cookie attributes ...
Now let me show you the magic of cookies...
* Open the flipkart.com and login there .
* Open the cookie manager to see the flipkart.com cookies .
* As SN is the session cookie for flipkart , just modify the cookie (either delete , replace or insert new characters) and save it .
* Now refresh the flipkart.com and you will see that you'll automatically get logged out .
* This is the power of cookie .
And even if you are able to access the cookie of any of your friend (like SN cookie of flipkart.com) , just copy and paste that cookie in cookie manager and refresh the page . You will able to login as your friend(whose cookie u have captured) . This is known as Session Hijacking .
So....
Hope you like this short tutorial on HTTP cookies .
Stay tuned for upcoming tutorials .
For any problem or queries, please comment below...
Comments
Post a Comment