Cookies
Last updated: 21 March 2025
When setting cookies you should consider their purpose and specify attribute values that reduce security risks. External facing websites that make use of cookies to store data on a user's device must abide by the Privacy and Electronic Communications Regulations 2003.
Requirement(s)
- You MUST detail cookies in a cookie policy
- You MUST determine what cookies are essential
- You MUST gain consent from external users
- You MUST use the HttpOnly attribute when possible
- You MUST use the Secure attribute
- You MUST scope cookies appropriately
You MUST detail cookies in a cookie policy
Any cookies that may be created during an external user’s interaction with a website must be detailed in a cookie policy. This must include the name of the cookies, what they are used for, and how long they will be stored.
You MUST determine what cookies are essential
If a cookie is required to perform an action that an external user has requested, for example to track that they have successfully authenticated, then it is termed an essential cookie. These do not require consent from the user but must still be detailed in a cookie policy.
You MUST gain consent from external users
For external facing websites, you must gain consent from the user prior to storing any non-essential cookies. The guidance from the ICO specifies:
You MUST use the HttpOnly attribute when possible
When setting cookies, the HttpOnly attribute can help reduce the risk of cross-site scripting (XSS) attacks by preventing Javascript code from being able to access its content. This form of attack is common and has persistently featured in the OWASP Top 10, which monitors the most significant security risks to web applications.
You MUST use the Secure attribute
When setting cookies, the Secure attribute specifies that the browser should only send the cookie back to requests using the HTTPS protocol. This makes it more difficult for unauthorised parties to observe the value of the cookie when it is sent from the user’s device to the server.
You MUST scope cookies appropriately
When setting cookies, the Domain and Path attributes describe the URLs to which the cookies should be sent. By specifying appropriate values for these attributes you can reduce the risk of cookies being sent unnecessarily to other websites on the same domain that do not need them.