line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ark::Plugin::Session::State::Cookie; |
2
|
7
|
|
|
7
|
|
3592
|
use strict; |
|
7
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
214
|
|
3
|
7
|
|
|
7
|
|
38
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
184
|
|
4
|
7
|
|
|
7
|
|
35
|
use Ark::Plugin 'Session'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
41
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has cookie_name => ( |
7
|
|
|
|
|
|
|
is => 'rw', |
8
|
|
|
|
|
|
|
isa => 'Str', |
9
|
|
|
|
|
|
|
lazy => 1, |
10
|
|
|
|
|
|
|
default => sub { |
11
|
|
|
|
|
|
|
my $self = shift; |
12
|
|
|
|
|
|
|
$self->class_config->{cookie_name} || lc(ref $self->app) . '_session'; |
13
|
|
|
|
|
|
|
}, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has cookie_domain => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
19
|
|
|
|
|
|
|
lazy => 1, |
20
|
|
|
|
|
|
|
default => sub { |
21
|
|
|
|
|
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
$self->class_config->{cookie_domain}; |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has cookie_path => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
29
|
|
|
|
|
|
|
lazy => 1, |
30
|
|
|
|
|
|
|
default => sub { |
31
|
|
|
|
|
|
|
my $self = shift; |
32
|
|
|
|
|
|
|
$self->class_config->{cookie_path}; |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has cookie_expires => ( |
38
|
|
|
|
|
|
|
is => 'rw', |
39
|
|
|
|
|
|
|
lazy => 1, |
40
|
|
|
|
|
|
|
default => sub { |
41
|
|
|
|
|
|
|
my $self = shift; |
42
|
|
|
|
|
|
|
exists $self->class_config->{cookie_expires} |
43
|
|
|
|
|
|
|
? $self->class_config->{cookie_expires} |
44
|
|
|
|
|
|
|
: exists $self->app->config->{'Plugin::Session'}->{expires} |
45
|
|
|
|
|
|
|
? $self->app->config->{'Plugin::Session'}->{expires} |
46
|
|
|
|
|
|
|
: '+1d'; # 1day |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has cookie_secure => ( |
51
|
|
|
|
|
|
|
is => 'rw', |
52
|
|
|
|
|
|
|
isa => 'Bool', |
53
|
|
|
|
|
|
|
lazy => 1, |
54
|
|
|
|
|
|
|
default => sub { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
$self->class_config->{cookie_secure} || 0; |
57
|
|
|
|
|
|
|
}, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has cookie_httponly => ( |
61
|
|
|
|
|
|
|
is => 'rw', |
62
|
|
|
|
|
|
|
isa => 'Bool', |
63
|
|
|
|
|
|
|
lazy => 1, |
64
|
|
|
|
|
|
|
default => sub { |
65
|
|
|
|
|
|
|
my $self = shift; |
66
|
|
|
|
|
|
|
$self->class_config->{cookie_httponly} || 0; |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has cookie_samesite => ( |
71
|
|
|
|
|
|
|
is => 'rw', |
72
|
|
|
|
|
|
|
isa => 'Str', |
73
|
|
|
|
|
|
|
lazy => 1, |
74
|
|
|
|
|
|
|
default => sub { |
75
|
|
|
|
|
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
$self->class_config->{cookie_samesite} || ''; |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
has cookie_remove_marker => ( |
81
|
|
|
|
|
|
|
is => 'rw', |
82
|
|
|
|
|
|
|
isa => 'Bool', |
83
|
|
|
|
|
|
|
default => 0, |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has update_cookie => ( |
87
|
|
|
|
|
|
|
is => 'rw', |
88
|
|
|
|
|
|
|
isa => 'HashRef', |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
around 'get_session_id' => sub { |
92
|
|
|
|
|
|
|
my $next = shift; |
93
|
|
|
|
|
|
|
my $prev = $next->(@_); |
94
|
|
|
|
|
|
|
return $prev if $prev; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my ($self) = @_; |
97
|
|
|
|
|
|
|
my $request = $self->context->request; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
unless ($self->cookie_remove_marker) { |
100
|
|
|
|
|
|
|
if ( my $cookie = $request->cookies->{ $self->cookie_name } ) { |
101
|
|
|
|
|
|
|
my $sid = ref $cookie ? $cookie->value : $cookie; |
102
|
|
|
|
|
|
|
$self->log( debug => q[Found sessionid "%s" in cookie], $sid ); |
103
|
|
|
|
|
|
|
return $sid if $sid; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return; |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
around 'set_session_id' => sub { |
111
|
|
|
|
|
|
|
my $next = shift; |
112
|
|
|
|
|
|
|
my ($self, $sid) = @_; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$self->update_cookie( $self->make_cookie($sid) ); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$next->(@_); |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
around 'remove_session_id' => sub { |
120
|
|
|
|
|
|
|
my $next = shift; |
121
|
|
|
|
|
|
|
my ($self, $sid) = @_; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$self->session_id(undef); |
124
|
|
|
|
|
|
|
$self->cookie_remove_marker(1); |
125
|
|
|
|
|
|
|
$self->update_cookie( |
126
|
|
|
|
|
|
|
$self->make_cookie( $sid, { expires => 0 } ) |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$next->(@_); |
130
|
|
|
|
|
|
|
}; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
around 'finalize_session' => sub { |
133
|
|
|
|
|
|
|
my $next = shift; |
134
|
|
|
|
|
|
|
my ($self, $res) = @_; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $cookie = $self->update_cookie; |
137
|
|
|
|
|
|
|
my $sid = $self->get_session_id; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
if (!$cookie && $sid) { |
140
|
|
|
|
|
|
|
$cookie = $self->make_cookie($sid); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
if ($cookie) { |
144
|
|
|
|
|
|
|
$res->cookies->{ $self->cookie_name } = $cookie; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$next->(@_); |
148
|
|
|
|
|
|
|
}; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub make_cookie { |
151
|
67
|
|
|
67
|
0
|
160
|
my ($self, $sid, $attrs) = @_; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $cookie = { |
154
|
|
|
|
|
|
|
value => $sid, |
155
|
|
|
|
|
|
|
expires => $self->cookie_expires, |
156
|
|
|
|
|
|
|
secure => $self->cookie_secure, |
157
|
|
|
|
|
|
|
httponly => $self->cookie_httponly, |
158
|
|
|
|
|
|
|
$self->cookie_samesite ? (samesite => $self->cookie_samesite) : (), |
159
|
|
|
|
|
|
|
$self->cookie_domain ? (domain => $self->cookie_domain) : (), |
160
|
|
|
|
|
|
|
$self->cookie_path ? (path => $self->cookie_path) : (), |
161
|
67
|
100
|
|
|
|
348
|
%{ $attrs || {} }, |
|
67
|
50
|
|
|
|
621
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
162
|
|
|
|
|
|
|
}; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |