Skip to content

Cookie attribute injection via the max_age argument to set_cookie

Low
bdarnell published GHSA-c6v4-qj2h-f748 Oct 22, 2026

Package

pip tornado (pip)

Affected versions

<6.6

Patched versions

6.6.0

Description

Summary

RequestHandler.set_cookie did not validate the max_age argument. If an application passes an attacker-influenced string as max_age, the attacker can inject additional attributes (such as Path, Domain, or Secure) into the Set-Cookie header. This is a gap in the validation added in Tornado 6.5.5 and extended in 6.5.8, which covered the other set_cookie arguments but not max_age.

Impact

Applications are affected only if they pass a value derived from untrusted input as the max_age argument to set_cookie (or to set_signed_cookie/set_secure_cookie or clear_cookie, which call it) without converting it to an integer first. For example, set_cookie("sid", value, max_age="86400; Domain=example.com") produces a cookie with an attacker-chosen Domain attribute. An attacker could use this to change the scope of the cookie, for example by widening it to a parent path or to other subdomains.

Applications that pass an integer, or a value already converted with int(), are not affected. Other set_cookie arguments are not affected.

Patches

Fixed in Tornado 6.6. max_age is now converted with int(), so non-numeric values raise an exception instead of being written to the header.

Workarounds

Convert max_age to an integer (for example with int()) before passing it to set_cookie.

Credit

Reported by zhangyan8216.

Severity

Low

CVE ID

No known CVE

Weaknesses

Improper Neutralization of Special Elements in Output Used by a Downstream Component

The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component. Learn more on MITRE.

Improper Neutralization of CRLF Sequences in HTTP Headers

The product receives data from an HTTP agent/component (e.g., web server, proxy, browser, etc.), but it does not neutralize or incorrectly neutralizes CR and LF characters before the data is included in outgoing HTTP headers. Learn more on MITRE.

Credits