Security.com

cookie poisoning

By Rahul Awati

What is cookie poisoning?

Cookie poisoning is a type of cyber attack in which a bad actor hijacks, forges, alters or manipulates a cookie to gain unauthorized access to a user's account, open a new account in the user's name or steal the user's information for purposes such as identity theft. Cookie poisoning is also known as session hijacking.

To grasp the concept of cookie poisoning, it is essential to understand the fundamentals of cookies and how they work.

A cookie is a piece of information that gets added to a user's hard disk when they visit a website. It records their preferences as they use the website and is retrieved later by websites and web servers to do the following:

There are two common types of cookies:

  1. Session, or nonpersistent, cookies last only as long as the user's website session and expire when the user leaves the website.
  2. Persistent cookies last beyond the life of a single session. They are created to recognize users when they return to a website and to deliver a personalized user experience with every visit.

How do cookies work?

As mentioned earlier, the data stored in the cookie lets the web server know the history of the website's interaction with a particular user. This enables the website to display the correct information for that user.

Let's visualize a scenario to understand the role of cookies:

  1. A user enters login credentials on a website.
  2. The site's server verifies the credentials and authenticates the login.
  3. Subsequently, the server logs the session in a database, and a cookie containing the session ID is returned to the browser.
  4. The process of verifying the session ID in the cookie data with the database continues on every subsequent request until the user logs out.
  5. Once the user logs out, the session is automatically destroyed on the client and server
  6. However, the cookie data continues to remain on the user's hard disk -- meaning the cookie persists -- if they have checked the Remember me or Keep me logged in options.

How cookie poisoning works

Cookie poisoning happens when unauthorized persons (attackers) can manipulate cookies due to the poor security infrastructure of a website. By editing or manipulating the cookie, the attacker can gain access to the user data stored in the cookie.

Cookie poisoning attacks are dangerous because they enable attackers to use the data stored inside cookies to gain unauthorized access to users' accounts or to steal their identities.

Cookie poisoning through cross-site scripting (XSS)

Cross-site scripting, commonly known as XSS, is one of the most popular ways to access and manipulate cookie data. Usually, attackers find a page that is vulnerable to XSS injection. By inserting a malicious script into the page, they can get the page to send them the session cookies of everyone who views the page. This way, they can gain access to the data of all these users.

Since the stolen cookie enables the attacker to mimic its real owner, attackers can stay logged in to their victims' accounts without the victims realizing it. Moreover, attackers don't need to enter a password to access victim accounts. This is why XSS is so widely used in cookie poisoning attacks and why it is such an effective attack vector.

Session hijacking, session spoofing and session fixation

Cookie poisoning attacks usually target user session cookies. Cookie-based attacks against sessions aim to fool the web server into thinking that the attacker is the legitimate user.

Examples of such attacks include the following:

Types of cookie poisoning attacks

Apart from XSS, cookie poisoning attacks can also be perpetrated through other methods, such as the following:

How to prevent cookie poisoning

Unless security measures are in place, an attacker can examine a cookie to determine its purpose and edit it to get user information from the website that sent the cookie. To avoid cookie poisoning, maintaining proper cookie hygiene is vital.

Here's how users can prevent -- or at least minimize -- cookie poisoning attacks:

Websites that use cookies should also protect them via encryption before they are sent to a user's computer. A digital signature should be created to validate the content in all future communications between the user and the web server. If the content is tampered with, the signature will no longer match the content, and access by the server will be denied.

See how to use a public key and private key in digital signatures and what the loss of third-party cookies means for IT departments.

23 Nov 2021

All Rights Reserved, Copyright 2000 - 2024, TechTarget | Read our Privacy Statement