@@ -4,10 +4,11 @@ package Dancer::Cookie;
44use strict;
55use warnings;
66
7+ use Carp;
78use URI::Escape;
89
910use base ' Dancer::Object' ;
10- __PACKAGE__ -> attributes( qw/ name expires domain path secure http_only/ );
11+ __PACKAGE__ -> attributes( qw/ name expires domain path same_site secure http_only/ );
1112
1213sub init {
1314 my ($self , %args ) = @_ ;
@@ -22,6 +23,16 @@ sub init {
2223 $self -> expires($time );
2324 }
2425 $self -> path(' /' ) unless defined $self -> path;
26+
27+ # If we have a same_site attribute, ensure it's sane:
28+ if (my $same_site = $self -> same_site) {
29+ if ($same_site !~ m { ^(Strict|Lax|None)$} ) {
30+ Carp::croak(
31+ " Invalid same_site value '$same_site '"
32+ . " - must be 'Strict', 'Lax' or 'None', see RFC6265bis"
33+ );
34+ }
35+ }
2536}
2637
2738sub to_header {
@@ -35,10 +46,11 @@ sub to_header {
3546 $name =~ s / [=,; \t\r\n\013\014 ]// mg ;
3647
3748 my @headers = $name . ' =' . $value ;
38- push @headers , " path=" . $self -> path if $self -> path;
39- push @headers , " expires=" . $self -> expires if $self -> expires;
40- push @headers , " domain=" . $self -> domain if $self -> domain;
41- push @headers , " Secure" if $self -> secure;
49+ push @headers , " path=" . $self -> path if $self -> path;
50+ push @headers , " expires=" . $self -> expires if $self -> expires;
51+ push @headers , " domain=" . $self -> domain if $self -> domain;
52+ push @headers , " Secure" if $self -> secure;
53+ push @headers , " SameSite=" . $self -> same_site if $self -> same_site;
4254 push @headers , ' HttpOnly' unless $no_httponly ;
4355
4456 return join ' ; ' , @headers ;
0 commit comments