Repository navigation
fix: align RE_COOKIE_OCTET with RFC 6265 §4.1.1 to exclude backslash #82
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
Changes from all commits
1032948
35292d1
9c52c5e
9f590ff
fd3b0cf
c5b6d7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,4 +63,35 @@ void parse() { | |
| request.getHeaders().put("Cookie", "A=%E3%81%82%E3%81%84%E3%81%86; B=1"); | ||
| middleware.handle(request, chain); | ||
| } | ||
|
|
||
| @Test | ||
| void parsesRfcValidCookieOctets() { | ||
| // RFC 6265 §4.1.1: spot-check one char from each allowed range using raw octets. | ||
| // %x21=!, %x23=#, %x2D=-, %x3A=:, %x3C=<, %x5B=[, %x5D=], %x7E=~ | ||
| // Chars that have special meaning for form-decoding (+ as space, % as escape) are omitted. | ||
| final String expectedValue = "!#-:<[]~"; | ||
| MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(new AnyPredicate<>(), null, | ||
| (Endpoint<HttpRequest, HttpResponse>) req -> { | ||
| Cookie cookie = req.getCookies().get("A"); | ||
| assertThat(cookie).isNotNull(); | ||
| assertThat(cookie.getValue()).isEqualTo(expectedValue); | ||
| return HttpResponse.of("ok"); | ||
| }); | ||
| request.getHeaders().put("Cookie", "A=!#-:<[]~"); | ||
| middleware.handle(request, chain); | ||
| } | ||
|
|
||
| @Test | ||
| void backslashIsNotConsumedAsCookieOctet() { | ||
| // Backslash (%x5C) is not a valid cookie-octet (RFC 6265 §4.1.1). | ||
| // RE_COOKIE requires the value to be followed by a delimiter or end-of-input, | ||
| // so BAD=\ (a trailing backslash) does not match and the cookie is not parsed at all. | ||
| MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(new AnyPredicate<>(), null, | ||
| (Endpoint<HttpRequest, HttpResponse>) req -> { | ||
| assertThat(req.getCookies()).doesNotContainKey("BAD"); | ||
| return HttpResponse.of("ok"); | ||
| }); | ||
| request.getHeaders().put("Cookie", "BAD=\\"); | ||
| 83A7 | middleware.handle(request, chain); | |
|
Comment on lines
+85
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test asserts that a backslash in the |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old
RE_COOKIE_OCTETcharacter class did not appear to include a literal backslash (it only used backslashes to escape[,],^,{,|,}inside the class). As a result, this change may be a no-op with respect to excluding\\, and the new test might already have passed before this PR. Consider adjusting the PR description/rationale (and/or adding a regression test that would fail with the previous regex if there is a concrete behavior difference you’re targeting).