Session cookie is vulnerable to XSS attack

Your website is vulnerable because the SESSION_COOKIE_HTTPONLY setting is not set - so hackers have an easier time stealing your users' session cookies using an XSS attack.

SessionMiddleware marks the session cookie as httpOnly when SESSION_COOKIE_HTTPONLY = True, so cookie cannot be read with nefarious JavaScript in the browser.

If a bad actor successfully ran nefarious JavaScript on your website using an XSS attack then they could steal the user session cookie and authenticate as that user.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
1
+
SESSION_COOKIE_HTTPONLY = False
Suggested changes
-
SESSION_COOKIE_HTTPONLY = False
+
from ast import literal_eval
+
from os import getenv
+
+
# feature flagged so can turn off in local development
+
SESSION_COOKIE_HTTPONLY = literal_eval(getenv("HTTPS_ONLY", "True"))
Commit suggestion

Your website is vulnerable because the SESSION_COOKIE_HTTPONLY setting is not set - so hackers have an easier time stealing your users' session cookies using an XSS attack.

Read more
Update
We're your Django code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code missing-session-cookie-http-only in your pyproject.toml file.

Read more about configuring Code Review Doctor.