You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SimpleCookie.js_output is vulnerable to HTML injection #90309
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-12-22.13:26:50.501>labels= ['type-security', 'library', '3.11']
title='SimpleCookie.js_output is vulnerable to HTML injection'updated_at=<Date2021-12-22.13:26:50.501>user='https://bugs.python.org/trungpaaa'
In /Lib/http/cookies.py, the output from SimpleCookie.js_output might be parsed as HTML if it contained < and >.
from http import cookies
c = cookies.SimpleCookie()
c["fig"] = "newton</script><script>alert(document.domain)</script>";
// c.js_output()
<script type="text/javascript">
<!-- begin hiding
document.cookie = "fig=\"newton</script><script>alert(document.domain)</script>\"";
// end hiding -->
</script>
We can't simply escape all the special characters because the encoding method is treated differently depending on the document types. For example, the following snippet (from The Tangled Web) is safe in HTML but not in XHTML:
<script type="text/javascript">
var tmp = 'I am harmless! '+alert(1);// Or am I?';
</script>
To avoid messing with the encoding methods, we could encode the cookie string in base64 and let the browser decode it.
I have not found any use of that method on GitHub. Only forks of the stdlib and typeshed, and variables with accidentally same name.
It seems that it was written when support of <script> in browsers was rare. I do not think that "<!-- begin hiding" is valid JavaScript. This code will likely does not work in modern browsers.
Activity
trungpaaa commentedon Dec 22, 2021
In /Lib/http/cookies.py, the output from SimpleCookie.js_output might be parsed as HTML if it contained < and >.
We can't simply escape all the special characters because the encoding method is treated differently depending on the document types. For example, the following snippet (from The Tangled Web) is safe in HTML but not in XHTML:
To avoid messing with the encoding methods, we could encode the cookie string in base64 and let the browser decode it.
After searching around on Github, I think this function is rarely used so making it deprecated is also an option.
serhiy-storchaka commentedon Apr 9, 2026
I have not found any use of that method on GitHub. Only forks of the stdlib and typeshed, and variables with accidentally same name.
It seems that it was written when support of
<script>in browsers was rare. I do not think that "<!-- begin hiding" is valid JavaScript. This code will likely does not work in modern browsers.I support deprecation of
js_output().sethmlarson commentedon Apr 10, 2026
I also support deprecation of this function.
pythongh-90309: Base64-encode cookie values embedded in JS
gh-90309: Base64-encode cookie values embedded in JS
[3.14] gh-90309: Base64-encode cookie values embedded in JS (GH-148889)
[3.13] gh-90309: Base64-encode cookie values embedded in JS (GH-148888)
pythongh-90309: Base64-encode cookie values embedded in JS
Update python315 to version 3.15.0~a8 / rev 12 via SR 1349644
Update python310 to version 3.10.20 / rev 77 via SR 1349663
Update python315 to version 3.15.0~a8 / rev 13 via SR 1349863
Update python313 to version 3.13.13 / rev 41 via SR 1349656
Update python312 to version 3.12.13 / rev 49 via SR 1360565
[CVE-2026-6019] Base64-encode cookie values embedded in JS
[CVE-2026-6019] Base64-encode cookie values embedded in JS
[CVE-2026-6019] Base64-encode cookie values embedded in JS
[CVE-2026-6019] Base64-encode cookie values embedded in JS
[CVE-2026-6019] Base64-encode cookie values embedded in JS
[CVE-2026-6019] Base64-encode cookie values embedded in JS