blib/lib/Dancer/Plugin/SecureSessionID.pm

filter: Statementstmt 100% 39 / 39 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 98.0% 51 / 52 CC 2 SCAR 1.5
CC
2
Cov
98%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 package Dancer::Plugin::SecureSessionID;
2  
3 3 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Dancer::Session::Abstract ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Crypt::Random ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Dancer::Plugin::SecureSessionID - Dancer-Plugin-SecureSessionID
15  
16 =head1 VERSION
17  
18 Version 0.01
19  
20 =cut
21  
22 3 our $VERSION = '0.01';
23  
24 =head1 SYNOPSIS
25  
26 use Dancer::Plugin::SecureSessionID;
27  
28 use_secure_session_id;
29  
30 =head1 DESCRIPTION
31  
32 This plugin overrides the C<build_id()> method in L<Dancer::Session::Abstract|Dancer::Session::Abstract> and make use of L<Crypt::Random|Crypt::Random> to get really secure random session ids.
33  
34 =head1 METHODS
35  
36 =head2 C<< use_secure_session_id([ %options ]) >>
37  
38 The options are passed into C<makerandom_octet(...)>, so any option described in L<Crypt::Random|Crypt::Random> are valid here. The defaults are Strength=1 and Length=16. These options can be set with plugin settings, too.
39  
40 use_secure_session_id(Length => 20, Uniform => 1, Skip => 512);
41  
42 same as:
43  
44 plugins:
45 SecureSessionID:
46 Length: 20
47 Uniform: 1
48 Skip: 512
49  
50 The result is encoded with C<base64url()>. A length of 16 random bytes results in 22 characters.
51  
52 =cut
53  
54 register use_secure_session_id => sub {
55 my %options = (
56 Length => 16,
57 Strength => 1,
58 1 ▶ %{ plugin_setting || {} },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
plugin_setting() or {} 0 1 1
59 @_
60 );
61 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
62 1 undef *{'Dancer::Session::Abstract::build_id'};
63 1 *{'Dancer::Session::Abstract::build_id'} = sub {
64 1 ▶ my $r = Crypt::Random::makerandom_octet(%options);
Subroutine __ANON__: called CC=1 SCAR=0.0
65 1 return MIME::Base64::encode_base64url($r,'');
66 1 };
67 3 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
68 3 };
69  
70 =head1 SECURITY WARNING
71  
72 Any session module which does not override C<build_id()> make profit from this plugin. This behaviour may change in future. Don't rely on it without auditing the source code of the affected session modules. By now, both the Simple and YAML session engines (shipped with the Dancer package) do not override C<build_id> so this plugin works as expected.
73  
74 Addtionally, mind the section about blocking behaviour in the documentation of L<Crypt::Random|Crypt::Random>. If you app blocks, you can set the C<Strength> option to 0. This may be a lack of security but it helps to improve performance. Since your app cause network traffic, the entropy pool will be recharched often enough to never get blocked. See also L<the manpage of your random device|random(4)>.
75  
76 =head1 AUTHOR
77  
78 David Zurborg, C<< <zurborg@cpan.org> >>
79  
80 =head1 BUGS
81  
82 Please report any bugs or feature requests trough my project management tool
83 at L<http://development.david-zurb.org/projects/libdancer-plugin-securesessionid/issues/new>. I
84 will be notified, and then you'll automatically be notified of progress on
85 your bug as I make changes.
86  
87 =head1 SUPPORT
88  
89 You can find documentation for this module with the perldoc command.
90  
91 perldoc Dancer::Plugin::SecureSessionID
92  
93 You can also look for information at:
94  
95 =over 4
96  
97 =item * Redmine: Homepage of this module
98  
99 L<http://development.david-zurb.org/projects/libdancer-plugin-securesessionid>
100  
101 =item * RT: CPAN's request tracker
102  
103 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-SecureSessionID>
104  
105 =item * AnnoCPAN: Annotated CPAN documentation
106  
107 L<http://annocpan.org/dist/Dancer-Plugin-SecureSessionID>
108  
109 =item * CPAN Ratings
110  
111 L<http://cpanratings.perl.org/d/Dancer-Plugin-SecureSessionID>
112  
113 =item * Search CPAN
114  
115 L<http://search.cpan.org/dist/Dancer-Plugin-SecureSessionID/>
116  
117 =back
118  
119 =head1 COPYRIGHT & LICENSE
120  
121 Copyright 2014 David Zurborg, all rights reserved.
122  
123 This program is released under the following license: open-source
124  
125 =cut
126  
127 3 register_plugin;
128 3 1;
↑ Summary