Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Cookie attribute injection: name/path/domain unescaped in pp_to_header

Open
#1,809 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
perl
Domain
backend, security

Research direction

Start with lib/Dancer2/Core/Cookie.pm:51-66 and trace both pp_to_header and xs_to_header, including the HTTP::XSCookies::bake_cookie path. Confirm how name, path, and domain handle semicolons, commas, whitespace, and control characters, then make the two paths reject invalid input consistently. Done means cookie attributes cannot be injected through these fields and both implementations agree.

Written by the indexing model from the issue text.

Description

Bug

Severity: low (requires application cooperation) · Status: reasoned from code

lib/Dancer2/Core/Cookie.pm:51-66:

my $value = join( '&', map uri_escape($_), $self->value );   # value: escaped
my @headers = $self->name . '=' . $value;                    # name:  raw
push @headers, "Path=" . $self->path          if $self->path;    # raw
push @headers, "Domain=" . $self->domain      if $self->domain;  # raw

The value is uri_escaped, but name, path and domain are concatenated raw. A ; in an application-supplied path, domain or name injects arbitrary cookie attributes (Domain=, Path=, Secure, SameSite=).

Reaching it requires the application to build a cookie from user input, hence low.

Suggested fix

Reject rather than silently mangle, since a ; in any of these is always a programming error:

for my $attr (qw< name path domain >) {
    my $v = $self->$attr;
    defined $v && $v =~ /[;,\s[:cntrl:]]/
        and croak "Invalid character in cookie $attr: '$v'";
}

Worth checking alongside

The XS path (xs_to_header, delegating to HTTP::XSCookies::bake_cookie) may already handle some of this. Which path runs depends on whether HTTP::XSCookies is installed, so the two should be made to agree — otherwise this is another install-dependent behaviour difference.

Dominant language
Perl
Stars
604
Forks
290
Avg merge
3d 7h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PerlDancer/Dancer2

All issues in PerlDancer/Dancer2

Similar issues

More Perl issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.