| 1 | 1 | ▶ | use 5.006; use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Plack::Middleware::SignedCookies; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '1.204'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | BEGIN { require Plack::Middleware; our @ISA = 'Plack::Middleware' } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Plack::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Plack::Util::Accessor qw( secret secure httponly ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Digest::SHA (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 65 | ▶ | sub _hmac { y{+/}{-~}, return $_ for &Digest::SHA::hmac_sha256_base64 } | ||||||||||||||||||||||||||
|
Subroutine
_hmac: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | my $length = length _hmac 'something', 'something'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 9 | ▶ | sub call { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 9 | my ( $self, $env ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 9 | my $secret = $self->secret; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 9 | my $orig = delete $env->{'HTTP_COOKIE'}; | |||||||||||||||||||||||||||
| 23 | 9 | ▶ | $env->{'signedcookies.orig'} = $orig if defined $orig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | my $cookie = | ||||||||||||||||||||||||||||
| 26 | join '; ', | ||||||||||||||||||||||||||||
| 27 | 21 | ▶ | grep { s/[ \t]*=[ \t]*/=/; s/[ \t]*([-~A-Za-z0-9]{$length})\z//o and $1 eq _hmac $_, $secret } | ||||||||||||||||||||||||||
|
Condition66%2/3
s/[ \t]*([-~A-Za-z0-9]{$length})\z//o && $1 eq _hmac($_, $secret)
MC/DC50%1/2
s/[ \t]*([-~A-Za-z0-9]{$length})\z//o && $1 eq _hmac($_, $secret)
s/[ \t]*([-~A-Za-z0-9]{$length})\z//o
$1 eq _hmac($_, $secret)
Truth table66%2/3
A && B
A= s/[ \t]*([-~A-Za-z0-9]{$length})\z//oB= $1 eq _hmac($_, $secret)
| |||||||||||||||||||||||||||||
| 28 | 9 | ▶ | map { defined && /\A[ \t]*(.*[^ \t])/s ? split /[ \t]*;[ \t]*/, "$1" : () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_ and /\A[ \t]*(.*[^ \t])/s
MC/DC50%1/2
defined $_ and /\A[ \t]*(.*[^ \t])/s
defined $_
/\A[ \t]*(.*[^ \t])/s
Truth table66%2/3
A and B
A= defined $_B= /\A[ \t]*(.*[^ \t])/s
| |||||||||||||||||||||||||||||
| 29 | $orig; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 9 | ▶ | $env->{'HTTP_COOKIE'} = $cookie if '' ne $cookie; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 9 | ▶ | return Plack::Util::response_cb( $self->app->( $env ), sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 34 | 9 | my $do_sign; | |||||||||||||||||||||||||||
| 35 | 9 | for ( @{ $_[0][1] } ) { | |||||||||||||||||||||||||||
| 36 | 90 | ▶ | if ( $do_sign ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 45 | ▶ | my $flags = s/(;.*)//s ? $1 : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 45 | s/\A[ \t]+//, s/[ \t]+\z//, s/[ \t]*=[ \t]*|\z/=/; # normalise | |||||||||||||||||||||||||||
| 39 | 45 | $_ .= ' ' . _hmac( $_, $secret ) . $flags; | |||||||||||||||||||||||||||
| 40 | 45 | ▶ | $_ .= '; secure' if $self->secure and $flags !~ /;[ \t]* secure [ \t]* (?![^;])/ix; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->secure and not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi
MC/DC100%2/2
$self->secure and not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi
$self->secure
not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi
Truth table100%3/3
A and not(B)
A= $self->secureB= not $flags =~ /;[ \t]* secure [ \t]* (?![^;])/xi
| |||||||||||||||||||||||||||||
| 41 | 45 | ▶ | $_ .= '; HTTPonly' if $self->httponly and $flags !~ /;[ \t]* httponly [ \t]* (?![^;])/ix; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->httponly and not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi
MC/DC50%1/2
$self->httponly and not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi
$self->httponly
not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi
Truth table66%2/3
A and not(B)
A= $self->httponlyB= not $flags =~ /;[ \t]* httponly [ \t]* (?![^;])/xi
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 90 | ▶ | $do_sign = defined $do_sign ? undef : 'set-cookie' eq lc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 9 | } ); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub prepare_app { | ||||||||||||||||||||||||||
|
Subroutine
prepare_app: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | 1 | ▶ | defined $self->httponly or $self->httponly( 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | defined $self->secret or $self->secret ( join '', map { chr int rand 256 } 1..17 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | 1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||