Skip to content
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

signedCookie is unlikely to be used correctly #70

Open
ahupp opened this issue Jun 11, 2020 · 1 comment
Open

signedCookie is unlikely to be used correctly #70

ahupp opened this issue Jun 11, 2020 · 1 comment

Comments

@ahupp
Copy link

ahupp commented Jun 11, 2020

cookie-parser's signedCookie function has the following behavior when it encounters an unsigned value:

"If the value was not signed, the original value is returned."

This is subtle behavior, and it seems unlikely that a caller would actually know to check that the return value was different from what was passed in. If the caller depends on the signature mechanism to prevent tampering this could be a serious problem.

A cursory check shows all 3 callers on github are not checking the return value:

https://github.com/search?q=%22cookieparser.signedCookie%22+-path%3AcookieParser&type=Code&ref=advsearch&l=&l=

I'd suggest changing the API to return false if passed a non-signature cookie value, similar to failing the signature check.

@devinc
Copy link

devinc commented Feb 27, 2021

I agree that this behavior should change. The docs do explain the behavior (and it is of course used correctly internally), but I did a bit more searching and have found many projects that do not properly check the return value. Several of those projects I looked at were using it with some kind of session identifier that in some cases had pretty limited entropy. This is an auth bypass for those projects.

I also believe that having it return false when passed an unsigned cookie shouldn't break too much existing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants