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.
Summary
RequestHandler.set_cookiedid not validate themax_ageargument. If an application passes an attacker-influenced string asmax_age, the attacker can inject additional attributes (such asPath,Domain, orSecure) into theSet-Cookieheader. This is a gap in the validation added in Tornado 6.5.5 and extended in 6.5.8, which covered the otherset_cookiearguments but notmax_age.Impact
Applications are affected only if they pass a value derived from untrusted input as the
max_ageargument toset_cookie(or toset_signed_cookie/set_secure_cookieorclear_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-chosenDomainattribute. 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. Otherset_cookiearguments are not affected.Patches
Fixed in Tornado 6.6.
max_ageis now converted withint(), so non-numeric values raise an exception instead of being written to the header.Workarounds
Convert
max_ageto an integer (for example withint()) before passing it toset_cookie.Credit
Reported by zhangyan8216.