Home » Vulnerabilities Knowledge Base » How To Prevent Cookie Injection Attack
Cookies are small data files sent by a web server to a browser to track user activity or maintain sessions. Each time the user revisits or navigates the site, the browser sends the cookie back, allowing the server to identify and remember the user.
In cookie injection attack, hackers steal or manipulate cookies to gain unauthorized access to sensitive data. Using methods like SQL Injection or Cross-Site Scripting (XSS), attackers can read or modify cookies stored in cleartext, Base64, or hashed formats to inject malicious queries.
Cookie injection/stealing: attackers use XSS, SQLi, or other flaws to read, modify, or forge cookies (especially those stored in cleartext, Base64, or serialized form) to hijack sessions or inject malicious data.
Unauthorised account/session takeover, data theft or tampering, impersonation, and broader compromise of application integrity and user privacy.
Always validate and sanitize cookie-related input on the server.
Set cookie flags: HttpOnly, Secure, SameSite.
Store minimal sensitive data in cookies; use server-side session storage.
Use unpredictable, encrypted/randomized tokens and send cookies via HTTP headers only.
Content Sniffing
Certain browsers, try to determine the content type and encoding of the response even when these properties are defined correctly...
Content Sniffing
Certain browsers, try to determine the content type and encoding of the response even when these properties are defined correctly...
Content Sniffing
Certain browsers, try to determine the content type and encoding of the response even when these properties are defined correctly...
Content Sniffing
Certain browsers, try to determine the content type and encoding of the response even when these properties are defined correctly...