Skip to content

Conversation

@jaclarke
Copy link
Member

If there are invalid cookies in the request to any of the http endpoints, the server returns a not very helpful HttpParserCallbackError: User callback error error message.

As only the auth ext endpoints actually read the cookies, defer parsing the cookie header until the request is being handled by the auth ext, and return a better error message in the case of a CookieError.

Copy link
Contributor

@scotttrinh scotttrinh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to address my question right this second, since it'll be hard to even test for this until we see what the exception actually says to know what code path we're hitting. So :shipit:

Comment on lines 143 to 147
except http.cookies.CookieError as ex:
raise errors.InvalidData(
f'invalid cookies header: {ex}, '
f'try clearing cookies and trying again'
)
Copy link
Contributor

@scotttrinh scotttrinh Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems better than the status quo, for sure! I wonder if we can do one better and actually ignore and clear out bad cookies based on the error? Conceptually, I always feel like cookies are things owned by the server, not by the client. If course, it's possible that the cookies are just completely mangled to the point where it's impossible to even know which key needs to be cleared.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our error pages should be a bit richer / nicely designed, but also have a JS snippet that can nuke cookies and any other local state (this error page could just do that, right?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always feel like cookies are things owned by the server

Normally, yes. But for local instances we're using localhost, and the users app is likely also using localhost, so we effectively share cookies with their app. It feels like we're just going to cause more weird, hard to debug, problems if we start destroying cookies when the users app has a bug that causes it to set bad cookies.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the best approach is to have some custom cookie parsing that just ignores invalid cookies (we can log a warning), as we only need to read the known good cookies we set anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've updated it to ignore invalid cookies: 2f060fd

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The downside of ignoring invalid cookies is that you don't know it's messed up, right? I guess another approach is to lazily load cookies at the point when we need them and to do it selectively rather than populating a whole cookie jar, just ask for the morsels we need? Because then if something is messed up, there is clearly a bug. This isn't a blocker, though: this is still superior to the status quo in every way.

@msullivan
Copy link
Member

Should we merge this?

@mmastrac
Copy link
Contributor

Can we send back Clear-Site-Data: "cache", "cookies" when this fails?

@scotttrinh scotttrinh force-pushed the defer-cookies-loading branch from 2f060fd to e8d8cf2 Compare October 31, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants