A cookie is set without secure or without httponly

tx0/python:cookie-without-flagsstrictwarningsecurity, cwe-614, cwe-1004

What it finds

A cookie without the Secure flag is also sent over plain HTTP, where anyone on the way can read it, and one without HttpOnly can be read by scripts on the page, so a single injected script can steal a session. Reported are set_cookie calls that do not pass secure or httponly and no **kwargs, with at least a name and a value. Cookies that scripts must read on purpose can pass httponly=False to say so.

From the rule's source, cookie_without_flags.rs.

Example from the rule's tests
def login(response, token):    response.set_cookie("session", token)tx0 reports: this cookie is set without secure and httponly    response.set_cookie("session", token, secure=True)tx0 reports: this cookie is set without httponly    response.set_cookie("theme", "dark", secure=True, httponly=False)    jar.set_cookie(cookie)
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:cookie-without-flags" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:cookie-without-flags] reason="..."

tx0 explain tx0/python:cookie-without-flags shows the same in the terminal. Found a false positive? Report it.