Add failing test case for double cookie setting#62
Open
aeneasr wants to merge 2 commits intojustinas:masterfrom
Open
Add failing test case for double cookie setting#62aeneasr wants to merge 2 commits intojustinas:masterfrom
aeneasr wants to merge 2 commits intojustinas:masterfrom
Conversation
Contributor
Author
63db8e2 to
3dd5c4d
Compare
Contributor
Author
|
ping @justinas |
justinas
reviewed
Mar 9, 2021
Owner
justinas
left a comment
There was a problem hiding this comment.
Sorry for sleeping on this! Just a few comments from my side.
| defer cmMutex.Unlock() | ||
|
|
||
| ctx, ok := contextMap[req] | ||
| if !ok { |
Owner
There was a problem hiding this comment.
I think it would be okay to assume context already exists here, like Reason() does.
Lines 87 to 90 in 4d86df7
|
|
||
| ctx, ok := contextMap[req] | ||
|
|
||
| if !ok { |
Owner
There was a problem hiding this comment.
Same here, could probably assume that when ctxWasSent is called, the context is already present.
| n.RegenerateToken(w, r) | ||
| })) | ||
|
|
||
| r := &http.Request{Method: "GET", URL: &url.URL{ |
| } | ||
|
|
||
| func TestNoDoubleCookie(t *testing.T) { | ||
| var n *CSRFHandler |
Owner
There was a problem hiding this comment.
Nitpick: separate declaration not needed, just do n := New(...)?
Contributor
Author
|
Thank you for the review, I'll try to address them as soon as I have a couple of free minutes! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem is that
ServeHTTPdetects that the cookie is missing. So it callsRegenerateToken()to create a new token. Because the downstream handler doesn't know that (and really has no way of currently knowing), it also callsRegenerateToken(). This then adds a second cookie to the HTTP response, causing this behavior.See #61