Summary
CGI::Cookie versions before 5.00 can place unvalidated path, domain, and expires values directly into a Set-Cookie header. If an application builds these values from request data, an attacker may be able to inject additional cookie attributes, potentially changing how the browser handles the cookie.
Affected context
The issue occurs when an application uses affected CGI::Cookie versions to create cookies and supplies path, domain, or expires values that are influenced by request data. Those values are written into the Set-Cookie header without checking for semicolons or control characters, which may allow additional cookie attributes to be introduced.
Exploit preconditions
- Attack surface: An application endpoint that creates or updates cookies
- Required access: Ability to influence request data used for cookie attributes
- Trigger point: The application emits a Set-Cookie header using the affected library
- Why exploitation is possible: Attribute values are inserted into the header without adequate validation or neutralization
Why this happens
The library writes path, domain, and expires values into a Set-Cookie header without preventing characters that can delimit or alter cookie attributes. This is an output-neutralization failure mapped to CWE-116: Improper Encoding or Escaping of Output. When values are derived from untrusted input, the header may be interpreted differently than the application intended.
Potential impact
- An attacker may be able to add or alter cookie attributes, such as Domain or SameSite.
- Cookie scope or browser handling may differ from the application's intended policy.
- Depending on application behavior, altered cookie handling could contribute to session-related security risks.
General mitigation guidance
Defensive approaches focus on preventing untrusted data from changing the structure of response headers.
- Use cookie APIs and serialization behavior that safely handle attribute values.
- Validate attribute values against narrowly defined formats and reject delimiters or control characters where they are not valid.
- Prefer fixed, application-controlled cookie attributes over values derived from request data.
- Apply least privilege to the data and code paths that can set cookies, and use secure-by-default cookie policies where appropriate.
How teams detect issues like this
Review cookie creation paths for request-derived values passed into path, domain, or expires attributes. Static analysis can flag unsanitized data flowing into Set-Cookie header construction, while code review can check whether validation occurs before serialization. Policy checks may require approved cookie-setting APIs and reject control characters or unexpected delimiters in attribute values.

