What is a cookie, and what are they used for?
Tags: webdev, productivity, news, security
Published: 2022-12-26 21:28:05

If you are reading this, you are probably wondering what a cookie is. First, this cookie is not edible. It is a programming word, and it was derived from the actual name of the “edible cookie.” It is popularly known as “internet cookies” or “computer cookies.”


![texts informing visitors on a site about cookies](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d37xmd0mlrd2skjxi44l.png)

## What is a cookie?
Cookies are texts in a file stored in a web browser. The web server of the site you are on creates them. So they can store your information if you are visiting the site for the first time. Next time, if you visit the same site. Their web server will retrieve the cookies to serve you a personalized page. The web server uses your cookie information to track the content that should be served to you. Cookies may contain information like your login details or your last saved operation.

## Why is it called a cookie?
According to [Wikipedia](https://en.m.wikipedia.org/wiki/HTTP_cookie), Cookie as a programming word was first created by a Netscape employee, Lou Montelli. He got the idea from “magic cookies.” This is a programming term for data programs that were not altered. The name “magic cookie” was gotten from a fortune cookie that had a message attached to it.

That was how “cookie” became a programming word.

## What are cookies used for?

- Cookies are used to store a set of strings that are unique to every user on the site. That way, they can record their operations on the site.

- Cookies are used to provide a customized experience for every user. Each user gets a personalized experience of the site using cookies. That way, when a user wants to log in, their username and password could pop up.

- Cookies are also used to track a user’s operations on a site. Most shopping sites use cookies that can track their users’ activities on their sites. So they make recommendations based on their users’ past operations.

- Cookies are used to authenticate users and determine if they are humans. Some sites analyze the cookie information on their users’ browsers when they want to log in. That way, they can confirm if it’s a bot or a human.

- Cookies are used to tailor the specific functionality that should be rendered to a user, but they are also used to access user privacy. You could choose to accept cookies or not. But not accepting them would limit the site’s functionality. Some websites deny you access when you refuse to accept their cookies.

## Types of cookies
There are two types of cookies based on their usage: first-party cookies and third-party cookies.

First-party cookies are cookies made by the website you are on. Unless the site you are on is a spammy site, first-party cookies are safer.

While

Third-party cookies are cookies made by third-party sites for the primary site. These third-party sites display ads on the primary site with cookies to track users.

## Security concerns about cookies
When people found out cookies were used to track users’ activities on the sites. Some did not accept it. Some countries have introduced laws to keep cookies in check. These laws such as the [European Union General Data Protection Regulation (GDPR)](https://gdpr.eu/what-is-gdpr/) and the [California Consumer Privacy Act (CPA)](https://en.m.wikipedia.org/wiki/California_Consumer_Privacy_Act) require websites to obtain permission from their users before using cookies and to provide information on how they use these cookies. Hence the “accept cookies” on many sites.

Cookies are saved in your browser, but this means an attacker could access your browsing data, including your cookies, and use the information to launch an attack. An attacker could inject malicious text to grant them access. They could inject a different text in a login cookie to redirect a user to a similar website and get access to their private information.

That is why security researchers always urge users to clear their browsing data and history, especially when they are on a site that could spam them.

## Summary
Internet cookies were created to enhance the browsing experience of site visitors. Cookies are harmless, and both reputable and non-reputable sites use them. Attackers can use cookies to gain unauthorized access to a site.

Always endeavour to clear your browsing data, especially if you are on a site with too many ads or a spammy site. To clear your browsing data, check out this article on [how to clear your browsing data in any browser](https://www.google.com/amp/s/www.howtogeek.com/304218/how-to-clear-your-history-in-any-browser/amp/).