Inbound cookie values are silently truncated at '&'
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start at lib/Dancer2/Core/Request.pm:632 and reproduce the truncation with the provided Perl command, then trace pp_to_header's multi-value cookie encoding. Compare the XS path via HTTP::XSCookies::crush_cookie with the Plack fallback, and review Cookie/value before deciding how inbound values should be handled. Done means the decision is implemented or documented with an unsplit accessor, and both parsing paths behave consistently.
Written by the indexing model from the issue text.
Description
Status: confirmed against main @ 21bc21d9
lib/Dancer2/Core/Request.pm:632:
value => is_arrayref($value) ? $value : [ split '&', $value ]
This split is an artifact of pp_to_header joining our own multi-value cookies with & — but it is applied to every inbound cookie, including those set by other frameworks, a CDN, or a JavaScript SDK. & is a legal cookie-octet under RFC 6265, and Cookie stringifies to its first value.
Reproduction
perl -Ilib -e 'use Dancer2::Core::Request;
my $r = Dancer2::Core::Request->new(env=>{REQUEST_METHOD=>"GET",PATH_INFO=>"/",QUERY_STRING=>"",
HTTP_COOKIE=>"sid=abc&def", "psgi.url_scheme"=>"http",SERVER_NAME=>"l",SERVER_PORT=>80});
print "sid=[", $r->cookies->{sid}, "] values=(", join("|", $r->cookies->{sid}->values), ")\n"'
sid=[abc] values=(abc|def)
So cookie('sid') silently returns abc for a cookie whose value is abc&def.
This needs a decision, not just a patch
There is no clean back-compatible fix, because Dancer2's own multi-value cookies genuinely are encoded this way and existing applications depend on the split. Options, in order of preference:
- Only split when every resulting element round-trips through
uri_escape— i.e. when the value actually looks like somethingpp_to_headerproduced. - Failing that, document the limitation prominently on
Cookie/valueand provide an unsplit accessor (raw_value).
Worth checking alongside
The XS path (HTTP::XSCookies::crush_cookie) and the Plack fallback may differ in their url-decoding before this split runs — another install-dependent behaviour difference. Both need verifying against whatever is decided.
- Dominant language
- Perl
- Stars
- 604
- Forks
- 290
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PerlDancer/Dancer2
-
Add .gitattributes so share/skel keeps LF on a Windows git checkoutPossibly taken @sadhana-s-codez claimed this 11 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
PerlDancer/Dancer2#1854 · 1 comment ·
Maintainers usually reply within 2 days
-
dancer2 gen -c writes the Dockerfile outside the app directoryMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
PerlDancer/Dancer2#1851 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PerlDancer/Dancer2#1850 ·
Maintainers usually reply within 2 days
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
PerlDancer/Dancer2#1820 ·
Maintainers usually reply within 2 days
-
Enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
PerlDancer/Dancer2#1819 ·
Maintainers usually reply within 2 days
All issues in PerlDancer/Dancer2
Similar issues
-
✏️ Editing - Tags
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
openfoodfacts/openfoodfacts-server#15127 ·
Maintainers usually reply within 1 day
-
FIDO2 (ecdsa-sk / ed25519-sk) ingress keys rejected: missing in get_supported_ssh_algorithms_listOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ovh/the-bastion#695 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
darold/pgFormatter#425 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
observablt-ci
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
elastic/golang-crossbuild#840 ·
Maintainers usually reply within 1 day