-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookie totally breaks if the client sets a bare cookie #2835
Comments
Are you aware if this cookie format is allowed by any specs, or if it simply a quirk that the browser can send it like that? Browsers otherwise do some formatting on document.cookie and don't simply pass the string. Malformed cookie headers could be used for exploiting parsers which understand them in different ways, potentially altering content of another cookie, so we try to make Sanic err on the side of rejection all of it rather than potentially return manipulated values, although it is noted that setting a cookie to prevent other cookies being parsed can also be exploited. Should we simply skip the "bare cookie" and still try to read the rest, or store it as a |
See httpwg/http-extensions#159 and httpwg/http-extensions#1018. It seems that The impact to my website is that if a frontend script accidentially sets things like |
I believe Sanic since 23.3 should simply ignore that one cookie and not the rest (because we re-did cookie parsing for that release), so you should be fine simply upgrading to the latest. However, since the specs call for allowing it, I've made a PR to have 23.9 or 23.12 onwards also reading the value of cookies that are nameless (empty string, not None, to avoid breakage). The new patch supports both |
Thanks for a high quality bug report! If you are interested on development itself, we would love your PRs on Sanic. There are a lot of minor things like this to look at. Let us know if the 23.x releases already solve the issue. |
Is there an existing issue for this?
Describe the bug
A cookie may be not in the
key=value
format. For example. if the JS code runsdocument.cookie = "bad"
, it becomes:I don't know how to call it. I will use the term "bare cookie" in this report. In the following requests with a bare cookie, the Cookie HTTP header becomes:
Cookie: key=value; bad
It seems that Sanic cannot parse the header with bare cookies, and will throw all cookies (including the legimit
key=value
pair) away. See the code snippet below.Code snippet
Then visit
http://127.0.0.1:4321/
in Chrome. The page shows:Expected Behavior
The page should show:
How do you run Sanic?
As a script (
app.run
orSanic.serve
)Operating System
Windows
Sanic Version
22.12.0
Additional context
I am using the latest stable Chrome (117.0.5938.150) to reproduce this.
The text was updated successfully, but these errors were encountered: