Dancer-Session-Cookie-0.22/000755 000765 000024 00000000000 12152266243 015716 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/Changes000644 000765 000024 00000004256 12152266243 017220 0ustar00davidstaff000000 000000 Revision history for Dancer-Session-Cookie 0.22 2013-05-31 23:38:07 America/New_York [CHANGED] - Requires Session::Storage::Secure 0.007 for improved resistance to timing attacks 0.21 2013-05-08 22:33:10 America/New_York - Require Dancer 1.3113 and use its new features to fix more bugs that caused sessions to not be set or reset correctly 0.20 2013-04-25 11:41:22 America/New_York - Fix bug where session wasn't cleared correctly if route handler died while processing a request 0.19 2013-02-24 22:49:14 America/New_York - Fix bug with session_expires always expiring a cookie early 0.18 2013-02-16 00:16:32 America/New_York - Hack around Dancer bug that renders the request object headers repeatedly and locks out setting cookies after the first time 0.17 2013-02-07 15:36:58 America/New_York - Fix localhost address used in tests 0.16 2013-02-01 14:39:14 America/New_York - Now uses Session::Storage::Secure for encrypting and decrypting data; Legacy decryption is preserved in case old cookies need to be read. - Fix session destruction bug to ensure session is overwritten in the browser, not just no longer sent (David Golden) 0.15 2011-05-21 * skip test 02-configfile.t if YAML is not present FIX smoker test failure. (Alexis Sukrieh) 0.14 2011-03-12 [ Michael G. Schwern ] * Fix for Dancer > v1.3012 * Add support for session_secure to serve https only cookies. * Add missing MYMETA.yml * Make Dancer::Session::Cookie honor the session_name setting added to Dancer::Session::Abstract * Add session_cookie_path to control the path of the cookie. 0.13 Sun Nov 28 17:19:58 MSK 2010 Some documentation fixes. No functional change. 0.12 Thu Sep 16 13:29:09 MSD 2010 Fix a warning when testing against newer Dancer. No functional change. 0.11 Wed Feb 17 16:12:21 MSK 2010 Chase the ever-changing Dancer core :) No functional change. More tests. 0.1 Tue Feb 2 17:20:11 MSK 2010 First version separated from the Dancer core. No functional change. Dancer-Session-Cookie-0.22/dist.ini000644 000765 000024 00000000651 12152266243 017364 0ustar00davidstaff000000 000000 name = Dancer-Session-Cookie author = Alex Kapranoff author = Alex Sukria author = David Golden license = Perl_5 copyright_holder = Alex Kapranoff [@DAGOLDEN] :version = 0.036 AutoMetaResources.bugtracker.rt = 0 AutoMetaResources.bugtracker.github = user:dagolden stopwords = AES stopwords = Kirsopp stopwords = cryptographically stopwords = honoured stopwords = https Dancer-Session-Cookie-0.22/lib/000755 000765 000024 00000000000 12152266243 016464 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/LICENSE000644 000765 000024 00000043661 12152266243 016735 0ustar00davidstaff000000 000000 This software is copyright (c) 2013 by Alex Kapranoff. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Alex Kapranoff. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Alex Kapranoff. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Dancer-Session-Cookie-0.22/Makefile.PL000644 000765 000024 00000004273 12152266243 017676 0ustar00davidstaff000000 000000 use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Encrypted cookie-based session backend for Dancer", "AUTHOR" => "Alex Kapranoff , Alex Sukria , David Golden ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Dancer-Session-Cookie", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Dancer::Session::Cookie", "PREREQ_PM" => { "Crypt::CBC" => 0, "Crypt::Rijndael" => 0, "Dancer" => "1.3113", "Dancer::Cookie" => 0, "Dancer::Cookies" => 0, "Dancer::Session::Abstract" => 0, "MIME::Base64" => 0, "Session::Storage::Secure" => "0.007", "Storable" => 0, "String::CRC32" => 0, "Time::Duration::Parse" => 0, "base" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Dancer::ModuleLoader" => 0, "ExtUtils::MakeMaker" => 0, "File::Find" => 0, "File::Spec" => 0, "File::Spec::Functions" => 0, "File::Temp" => 0, "FindBin" => 0, "HTTP::Cookies" => 0, "HTTP::Date" => 0, "LWP" => 0, "LWP::UserAgent" => 0, "List::Util" => 0, "Test::Exception" => 0, "Test::More" => "0.96", "Test::NoWarnings" => 0, "Test::TCP" => 0 }, "VERSION" => "0.22", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { my $tr = delete $WriteMakefileArgs{TEST_REQUIRES}; my $br = $WriteMakefileArgs{BUILD_REQUIRES}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Dancer-Session-Cookie-0.22/MANIFEST000644 000765 000024 00000001000 12152266243 017036 0ustar00davidstaff000000 000000 Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Dancer/Session/Cookie.pm t/00-compile.t t/00-report-prereqs.t t/01-session.t t/02-configfile.t t/03-path.t t/04-session_name.t t/05-session_secure.t t/06-redirect.t t/data/config.yml t/redirect-session-dancer.t t/server.t t/session-stealing.t xt/author/critic.t xt/author/pod-spell.t xt/release/distmeta.t xt/release/minimum-version.t xt/release/pod-coverage.t xt/release/pod-syntax.t xt/release/portability.t xt/release/test-version.t Dancer-Session-Cookie-0.22/META.json000644 000765 000024 00000005701 12152266243 017342 0ustar00davidstaff000000 000000 { "abstract" : "Encrypted cookie-based session backend for Dancer", "author" : [ "Alex Kapranoff ", "Alex Sukria ", "David Golden " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.131490", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Dancer-Session-Cookie", "no_index" : { "directory" : [ "t", "xt", "examples", "corpus" ], "package" : [ "DB" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Meta" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Crypt::CBC" : "0", "Crypt::Rijndael" : "0", "Dancer" : "1.3113", "Dancer::Cookie" : "0", "Dancer::Cookies" : "0", "Dancer::Session::Abstract" : "0", "MIME::Base64" : "0", "Session::Storage::Secure" : "0.007", "Storable" : "0", "String::CRC32" : "0", "Time::Duration::Parse" : "0", "base" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "Dancer::ModuleLoader" : "0", "ExtUtils::MakeMaker" : "0", "File::Find" : "0", "File::Spec" : "0", "File::Spec::Functions" : "0", "File::Temp" : "0", "FindBin" : "0", "HTTP::Cookies" : "0", "HTTP::Date" : "0", "LWP" : "0", "LWP::UserAgent" : "0", "List::Util" : "0", "Test::Exception" : "0", "Test::More" : "0.96", "Test::NoWarnings" : "0", "Test::TCP" : "0" } } }, "provides" : { "Dancer::Session::Cookie" : { "file" : "lib/Dancer/Session/Cookie.pm", "version" : "0.22" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/dancer-session-cookie/issues" }, "homepage" : "https://metacpan.org/release/Dancer-Session-Cookie", "repository" : { "type" : "git", "url" : "git://github.com/dagolden/dancer-session-cookie.git", "web" : "https://github.com/dagolden/dancer-session-cookie" } }, "version" : "0.22", "x_contributors" : [ "Michael G. Schwern ", "Neil Kirsopp ", "Nick S. Knutov " ] } Dancer-Session-Cookie-0.22/META.yml000644 000765 000024 00000003132 12152266243 017166 0ustar00davidstaff000000 000000 --- abstract: 'Encrypted cookie-based session backend for Dancer' author: - 'Alex Kapranoff ' - 'Alex Sukria ' - 'David Golden ' build_requires: Dancer::ModuleLoader: 0 ExtUtils::MakeMaker: 0 File::Find: 0 File::Spec: 0 File::Spec::Functions: 0 File::Temp: 0 FindBin: 0 HTTP::Cookies: 0 HTTP::Date: 0 LWP: 0 LWP::UserAgent: 0 List::Util: 0 Test::Exception: 0 Test::More: 0.96 Test::NoWarnings: 0 Test::TCP: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.131490' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Dancer-Session-Cookie no_index: directory: - t - xt - examples - corpus package: - DB provides: Dancer::Session::Cookie: file: lib/Dancer/Session/Cookie.pm version: 0.22 requires: Crypt::CBC: 0 Crypt::Rijndael: 0 Dancer: 1.3113 Dancer::Cookie: 0 Dancer::Cookies: 0 Dancer::Session::Abstract: 0 MIME::Base64: 0 Session::Storage::Secure: 0.007 Storable: 0 String::CRC32: 0 Time::Duration::Parse: 0 base: 0 perl: 5.006 strict: 0 warnings: 0 resources: bugtracker: https://github.com/dagolden/dancer-session-cookie/issues homepage: https://metacpan.org/release/Dancer-Session-Cookie repository: git://github.com/dagolden/dancer-session-cookie.git version: 0.22 x_contributors: - 'Michael G. Schwern ' - 'Neil Kirsopp ' - 'Nick S. Knutov ' Dancer-Session-Cookie-0.22/README000644 000765 000024 00000006501 12152266243 016600 0ustar00davidstaff000000 000000 NAME Dancer::Session::Cookie - Encrypted cookie-based session backend for Dancer VERSION version 0.22 SYNOPSIS Your config.yml: session: "cookie" session_cookie_key: "this random key IS NOT very random" DESCRIPTION This module implements a session engine for sessions stored entirely in cookies. Usually only session id is stored in cookies and the session data itself is saved in some external storage, e.g. database. This module allows to avoid using external storage at all. Since server cannot trust any data returned by client in cookies, this module uses cryptography to ensure integrity and also secrecy. The data your application stores in sessions is completely protected from both tampering and analysis on the client-side. CONFIGURATION The setting session should be set to "cookie" in order to use this session engine in a Dancer application. See Dancer::Config. A mandatory setting is needed as well: session_cookie_key, which should contain a random string of at least 16 characters (shorter keys are not cryptographically strong using AES in CBC mode). Here is an example configuration to use in your config.yml: session: "cookie" session_cookie_key: "kjsdf07234hjf0sdkflj12*&(@*jk" Compromising session_cookie_key will disclose session data to clients and proxies or eavesdroppers and will also allow tampering, for example session theft. So, your config.yml should be kept at least as secure as your database passwords or even more. Also, changing session_cookie_key will have an effect of immediate invalidation of all sessions issued with the old value of key. session_cookie_path can be used to control the path of the session cookie. The default is /. The global session_secure setting is honoured and a secure (https only) cookie will be used if set. DEPENDENCY This module depends on Session::Storage::Secure. Legacy support is provided using Crypt::CBC, Crypt::Rijndael, String::CRC32, Storable and MIME::Base64. SEE ALSO See Dancer::Session for details about session usage in route handlers. See Plack::Middleware::Session::Cookie, Catalyst::Plugin::CookiedSession, "session" in Mojolicious::Controller for alternative implementation of this mechanism. SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone git://github.com/dagolden/dancer-session-cookie.git AUTHORS * Alex Kapranoff * Alex Sukria * David Golden CONTRIBUTORS * Michael G. Schwern * Neil Kirsopp * Nick S. Knutov COPYRIGHT AND LICENSE This software is copyright (c) 2013 by Alex Kapranoff. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Dancer-Session-Cookie-0.22/t/000755 000765 000024 00000000000 12152266243 016161 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/xt/000755 000765 000024 00000000000 12152266243 016351 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/xt/author/000755 000765 000024 00000000000 12152266243 017653 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/xt/release/000755 000765 000024 00000000000 12152266243 017771 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/xt/release/distmeta.t000644 000765 000024 00000000217 12152266243 021770 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::CPAN::Meta"; plan skip_all => "Test::CPAN::Meta required for testing META.yml" if $@; meta_yaml_ok(); Dancer-Session-Cookie-0.22/xt/release/minimum-version.t000644 000765 000024 00000000266 12152266243 023320 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_ok( qq{5.010} ); Dancer-Session-Cookie-0.22/xt/release/pod-coverage.t000644 000765 000024 00000000527 12152266243 022535 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Dancer-Session-Cookie-0.22/xt/release/pod-syntax.t000644 000765 000024 00000000212 12152266243 022257 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); Dancer-Session-Cookie-0.22/xt/release/portability.t000644 000765 000024 00000000332 12152266243 022516 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; options(test_one_dot => 0); run_tests(); Dancer-Session-Cookie-0.22/xt/release/test-version.t000644 000765 000024 00000000643 12152266243 022623 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 0.002004 BEGIN { eval "use Test::Version; 1;" or die $@; } my @imports = ( 'version_all_ok' ); my $params = { is_strict => 0, has_version => 1, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; Dancer-Session-Cookie-0.22/xt/author/critic.t000644 000765 000024 00000000435 12152266243 021317 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); Dancer-Session-Cookie-0.22/xt/author/pod-spell.t000644 000765 000024 00000000666 12152266243 021747 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006000 eval "use Test::Spelling 0.12; use Pod::Wordlist::hanekomu; 1" or die $@; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ AES Kirsopp cryptographically honoured https Alex Kapranoff kappa Sukria sukria David Golden dagolden Michael Schwern schwern Neil neil Nick Knutov nick lib Dancer Session Cookie Dancer-Session-Cookie-0.22/t/00-compile.t000644 000765 000024 00000003100 12152266243 020205 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use File::Find; use File::Temp qw{ tempdir }; my @modules; find( sub { return if $File::Find::name !~ /\.pm\z/; my $found = $File::Find::name; $found =~ s{^lib/}{}; $found =~ s{[/\\]}{::}g; $found =~ s/\.pm$//; # nothing to skip push @modules, $found; }, 'lib', ); sub _find_scripts { my $dir = shift @_; my @found_scripts = (); find( sub { return unless -f; my $found = $File::Find::name; # nothing to skip open my $FH, '<', $_ or do { note( "Unable to open $found in ( $! ), skipping" ); return; }; my $shebang = <$FH>; return unless $shebang =~ /^#!.*?\bperl\b\s*$/; push @found_scripts, $found; }, $dir, ); return @found_scripts; } my @scripts; do { push @scripts, _find_scripts($_) if -d $_ } for qw{ bin script scripts }; my $plan = scalar(@modules) + scalar(@scripts); $plan ? (plan tests => $plan) : (plan skip_all => "no tests to run"); { # fake home for cpan-testers local $ENV{HOME} = tempdir( CLEANUP => 1 ); like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" ) for sort @modules; SKIP: { eval "use Test::Script 1.05; 1;"; skip "Test::Script needed to test script compilation", scalar(@scripts) if $@; foreach my $file ( @scripts ) { my $script = $file; $script =~ s!.*/!!; script_compiles( $file, "$script script compiles" ); } } } Dancer-Session-Cookie-0.22/t/00-report-prereqs.t000644 000765 000024 00000003555 12152266243 021565 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec::Functions; use List::Util qw/max/; my @modules = qw( Crypt::CBC Crypt::Rijndael Dancer Dancer::Cookie Dancer::Cookies Dancer::ModuleLoader Dancer::Session::Abstract ExtUtils::MakeMaker File::Find File::Spec File::Spec::Functions File::Temp FindBin HTTP::Cookies HTTP::Date LWP LWP::UserAgent List::Util MIME::Base64 Session::Storage::Secure Storable String::CRC32 Test::Exception Test::More Test::NoWarnings Test::TCP Time::Duration::Parse base perl strict warnings ); # replace modules with dynamic results from MYMETA.json if we can # (hide CPAN::Meta from prereq scanner) my $cpan_meta = "CPAN::Meta"; if ( -f "MYMETA.json" && eval "require $cpan_meta" ) { ## no critic if ( my $meta = eval { CPAN::Meta->load_file("MYMETA.json") } ) { my $prereqs = $meta->prereqs; delete $prereqs->{develop}; my %uniq = map {$_ => 1} map { keys %$_ } map { values %$_ } values %$prereqs; $uniq{$_} = 1 for @modules; # don't lose any static ones @modules = sort keys %uniq; } } my @reports = [qw/Version Module/]; for my $mod ( @modules ) { next if $mod eq 'perl'; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e catfile($_, $file) } @INC; if ( $prefix ) { my $ver = MM->parse_version( catfile($prefix, $file) ); $ver = "undef" unless defined $ver; # Newer MM should do this anyway push @reports, [$ver, $mod]; } else { push @reports, ["missing", $mod]; } } if ( @reports ) { my $vl = max map { length $_->[0] } @reports; my $ml = max map { length $_->[1] } @reports; splice @reports, 1, 0, ["-" x $vl, "-" x $ml]; diag "Prerequisite Report:\n", map {sprintf(" %*s %*s\n",$vl,$_->[0],-$ml,$_->[1])} @reports; } pass; # vim: ts=2 sts=2 sw=2 et: Dancer-Session-Cookie-0.22/t/01-session.t000644 000765 000024 00000002073 12152266243 020251 0ustar00davidstaff000000 000000 use Test::More import => ['!pass']; use Test::Exception; use Test::NoWarnings; use strict; use warnings; use Dancer; use Dancer::ModuleLoader; BEGIN { plan tests => 11; use_ok 'Dancer::Session::Cookie' } my $session; throws_ok { $session = Dancer::Session::Cookie->create } qr/session_cookie_key must be defined/, 'requires session_cookie_key'; set session_cookie_key => 'test/secret*@?)'; lives_and { $session = Dancer::Session::Cookie->create } 'works'; is $@, '', 'Cookie session created'; isa_ok $session, 'Dancer::Session::Cookie'; can_ok $session, qw(init create retrieve destroy flush); my $value1 = $session->_cookie_value; ok defined($value1), 'cookie value is defined'; $session->{bar} = 'baz'; my $value2 = $session->_cookie_value; isnt $value2, $value1, "cookie value changed after storing data"; ok length($value2) > 20, 'length is a long string'; my $s = Dancer::Session::Cookie->retrieve($session->id); is_deeply $s, $session, 'session is retrieved'; $s = Dancer::Session::Cookie->retrieve('XXX'); is $s, undef, 'unknown session is not found'; Dancer-Session-Cookie-0.22/t/02-configfile.t000644 000765 000024 00000001344 12152266243 020674 0ustar00davidstaff000000 000000 use Test::More import => ['!pass']; use Test::Exception; #use Test::NoWarnings; use strict; use warnings; use Dancer; use Dancer::ModuleLoader; use Dancer::Session::Cookie; use FindBin; use File::Spec; eval "use YAML"; plan skip_all => "YAML is needed for this test" if $@; plan tests => 3; my $session; throws_ok { $session = Dancer::Session::Cookie->create } qr/session_cookie_key must be defined/, 'still requires session_cookie_key'; set confdir => "$FindBin::Bin/data"; ok(-r File::Spec->catfile(setting('confdir'), 'config.yml'), 'config.yml is available'); Dancer::Config::load(); lives_and { $session = Dancer::Session::Cookie->create } 'session key loaded from config.yml'; is $@, '', "Cookie session created"; Dancer-Session-Cookie-0.22/t/03-path.t000644 000765 000024 00000001140 12152266243 017516 0ustar00davidstaff000000 000000 #!/usr/bin/env perl use Test::More import => ['!pass']; use strict; use warnings; use Dancer; my $CLASS = 'Dancer::Session::Cookie'; use_ok $CLASS; note "test setup"; { set session_cookie_key => "The dolphins are in the jacuzzi"; } note "default path"; { my $session = Dancer::Session::Cookie->create; my %cookie = $session->_cookie_params; is $cookie{path}, "/"; } note "set the path"; { set session_cookie_path => "/some/thing"; my $session = Dancer::Session::Cookie->create; my %cookie = $session->_cookie_params; is $cookie{path}, "/some/thing"; } done_testing; Dancer-Session-Cookie-0.22/t/04-session_name.t000644 000765 000024 00000001220 12152266243 021245 0ustar00davidstaff000000 000000 #!/usr/bin/env perl use Test::More import => ['!pass']; use strict; use warnings; use Dancer; my $CLASS = 'Dancer::Session::Cookie'; use_ok $CLASS; note "test setup"; { set session_cookie_key => "The dolphins are in the jacuzzi"; } note "default session_name"; { my $session = $CLASS->create; is $session->session_name, "dancer.session"; } note "honors session_name setting"; { my $session = $CLASS->create; my $session_name = "stuff.session"; set session_name => $session_name; is $session->session_name, $session_name; my %cookie = $session->_cookie_params; is $cookie{name}, $session_name; } done_testing; Dancer-Session-Cookie-0.22/t/05-session_secure.t000644 000765 000024 00000001461 12152266243 021623 0ustar00davidstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use Dancer ':syntax'; use Dancer::Session::Cookie; use Test::More import => ["!pass"]; plan skip_all => "Dancer::Cookie->secure not supported in this version of Dancer" unless Dancer::Cookie->can("secure"); plan tests => 2; my $Session_Name = Dancer::Session::Cookie->session_name; note "session_secure off"; { set session_cookie_key => "secret squirrel"; set session => "cookie"; session foo => "bar"; my %cookie = session->_cookie_params; ok !$cookie{secure}, "secure off"; } note "session_secure on"; { delete Dancer::Cookies->cookies->{ $Session_Name }; set session_secure => 1; set session => "cookie"; session up => "down"; my %cookie = session->_cookie_params; ok $cookie{secure}, "secure on"; } Dancer-Session-Cookie-0.22/t/06-redirect.t000644 000765 000024 00000003062 12152266243 020373 0ustar00davidstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use Test::More import => ["!pass"]; plan skip_all => "Test::TCP required" unless eval { require Test::TCP; Test::TCP->import; 1; }; plan skip_all => "LWP required" unless eval { require LWP; }; test_tcp( client => sub { my $port = shift; require LWP::UserAgent; require HTTP::Cookies; my $ua = LWP::UserAgent->new; my $jar = HTTP::Cookies->new; $ua->cookie_jar( $jar ); my $res = $ua->get("http://127.0.0.1:$port/"); is $res->content, "login page"; }, server => sub { my $port = shift; use Dancer ':tests', ':syntax'; set port => $port; set appdir => ''; # quiet warnings not having an appdir set access_log => 0; # quiet startup banner set session_cookie_key => "John has a long mustache"; set session => "cookie"; hook before => sub { if ( !session('uid') && request->path_info !~ m{^/login} ) { return redirect '/login/'; } }; get '/logout/?' => sub { session 'uid' => undef; session->destroy; return redirect '/'; }; any '/login/?' => sub { return redirect '/' if session('uid'); return 'ok' if session('login'); session 'login' => undef; return 'login page'; }; dance; } ); done_testing; Dancer-Session-Cookie-0.22/t/data/000755 000765 000024 00000000000 12152266243 017072 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/t/redirect-session-dancer.t000644 000765 000024 00000002454 12152266243 023067 0ustar00davidstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use Test::More import => ["!pass"]; plan skip_all => "Test::TCP required" unless eval { require Test::TCP; Test::TCP->import; 1; }; plan skip_all => "LWP required" unless eval { require LWP; }; test_tcp( client => sub { my $port = shift; require LWP::UserAgent; require HTTP::Cookies; my $ua = LWP::UserAgent->new; my $jar = HTTP::Cookies->new; $ua->cookie_jar( $jar ); my $res = $ua->get("http://127.0.0.1:$port/xxx"); is $res->content, "/xxx"; }, server => sub { my $port = shift; use Dancer ':tests', ':syntax'; set port => $port; set appdir => ''; # quiet warnings not having an appdir set access_log => 0; # quiet startup banner set session_cookie_key => "John has a long mustache"; set session => "cookie"; get '/b' => sub { return session('abc'); }; hook 'before' => sub { my $a = request->path_info; if ( not request->path_info =~ m{^/(a|b|c)} ){ session abc => $a ; return redirect '/b'; } }; dance; } ); done_testing; Dancer-Session-Cookie-0.22/t/server.t000644 000765 000024 00000010343 12152266243 017655 0ustar00davidstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use Test::More 0.96 import => ["!pass"]; use File::Temp; use HTTP::Date qw/str2time/; plan skip_all => "Test::TCP required" unless eval { require Test::TCP; Test::TCP->import; 1; }; plan skip_all => "LWP required" unless eval { require LWP; require HTTP::Cookies; }; my $tempdir = File::Temp->newdir; sub find_cookie { my ($res, $name) = @_; $name ||= 'dancer.session'; my @cookies = $res->header('set-cookie'); for my $c (@cookies) { next unless $c =~ /\Q$name\E/; return $c; } return; } sub extract_cookie { my ($res, $name) = @_; my $c = find_cookie($res, $name) or return; my @parts = split /;\s+/, $c; my %hash = map { my ( $k, $v ) = split /\s*=\s*/; $v ||= 1; ( lc($k), $v ) } @parts; $hash{expires} = str2time( $hash{expires} ) if $hash{expires}; return \%hash; } my @configs = ( { label => 'default config', settings => {}, }, { label => 'alternate name', settings => { session_name => "my_app_session", }, }, { label => 'expires 300', settings => { session_expires => 300, }, }, { label => 'expires +1h', settings => { session_expires => "1 hour", }, }, ); for my $config ( @configs ) { test_tcp( client => sub { my $port = shift; subtest $config->{label} => sub { my $ua = LWP::UserAgent->new; my $cookie; # Simulate two different browsers with two different jars my @jars = (HTTP::Cookies->new, HTTP::Cookies->new); for my $jar (@jars) { $ua->cookie_jar( $jar ); my $res = $ua->get("http://127.0.0.1:$port/foo"); is $res->content, "hits: 0, last_hit: "; $cookie = extract_cookie($res, $config->{settings}{session_name}); ok $cookie, "session cookie set" or diag explain $res->header('set-cookie'); $res = $ua->get("http://127.0.0.1:$port/bar"); $cookie = extract_cookie($res, $config->{settings}{session_name}); is( $res->content, "hits: 1, last_hit: foo") or diag explain $res->header('set-cookie'); $res = $ua->get("http://127.0.0.1:$port/forward"); is $res->content, "hits: 2, last_hit: bar", "session not overwritten"; $res = $ua->get("http://127.0.0.1:$port/baz"); is $res->content, "hits: 3, last_hit: whatever"; } $ua->cookie_jar($jars[0]); my $res = $ua->get("http://127.0.0.1:$port/wibble"); is $res->content, "hits: 4, last_hit: baz", "session not overwritten"; $res = $ua->get("http://127.0.0.1:$port/clear"); is $res->content, "hits: 0, last_hit: ", "session destroyed"; }; }, server => sub { my $port = shift; use Dancer ':tests', ':syntax'; set port => $port; set appdir => $tempdir; set access_log => 0; # quiet startup banner set session_cookie_key => "John has a long mustache"; set session => "cookie"; set show_traces => 1; set warnings => 1; set show_errors => 1; set %{$config->{settings}} if %{$config->{settings}}; get "/clear" => sub { session "useless" => 1; # force write/flush session->destroy; redirect '/postclear'; }; get "/forward" => sub { session ignore_me => 1; forward '/whatever'; }; get "/*" => sub { my $hits = session("hit_counter") || 0; my $last = session("last_hit") || ''; session hit_counter => $hits + 1; session last_hit => (splat)[0]; return "hits: $hits, last_hit: $last"; }; dance; } ); } done_testing; Dancer-Session-Cookie-0.22/t/session-stealing.t000644 000765 000024 00000004115 12152266243 021636 0ustar00davidstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use Test::More 0.96 import => ["!pass"]; use File::Temp; use HTTP::Date qw/str2time/; plan skip_all => "Test::TCP required" unless eval { require Test::TCP; Test::TCP->import; 1; }; plan skip_all => "LWP required" unless eval { require LWP; require HTTP::Cookies; }; my $tempdir = File::Temp->newdir; test_tcp( client => sub { my $port = shift; # Two different browsers my ($one, $two) = (HTTP::Cookies->new, HTTP::Cookies->new); my ($ua_one, $ua_two) = (LWP::UserAgent->new, LWP::UserAgent->new); $ua_one->cookie_jar($one); $ua_two->cookie_jar($two); my $res; # Set foo to one and two respectively $ua_one->get("http://127.0.0.1:$port/?foo=one"); $ua_two->get("http://127.0.0.1:$port/?foo=two"); # Retrieve both stored $res = $ua_one->get("http://127.0.0.1:$port/"); is $res->content, 'one', 'One received for first cookie'; $res = $ua_two->get("http://127.0.0.1:$port/"); is $res->content, 'two', 'Two received for second cookie'; # Die against one and ensure we still get 'two' back for the second $ua_one->get("http://127.0.0.1:$port/die"); $res = $ua_two->get("http://127.0.0.1:$port/"); is $res->content, 'two', 'Two received after first died'; }, server => sub { my $port = shift; use Dancer ':tests', ':syntax'; set port => $port; set appdir => $tempdir; set access_log => 0; # quiet startup banner set session_cookie_key => "John has a long mustache"; set session => "cookie"; set show_traces => 1; set warnings => 1; set show_errors => 1; get '/die' => sub { die 'Bad route'; }; get '/' => sub { if (my $foo = param('foo')) { session(foo => $foo); } return session('foo'); }; dance; } ); done_testing; Dancer-Session-Cookie-0.22/t/data/config.yml000644 000765 000024 00000000035 12152266243 021060 0ustar00davidstaff000000 000000 session_cookie_key: "secret" Dancer-Session-Cookie-0.22/lib/Dancer/000755 000765 000024 00000000000 12152266243 017660 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/lib/Dancer/Session/000755 000765 000024 00000000000 12152266243 021303 5ustar00davidstaff000000 000000 Dancer-Session-Cookie-0.22/lib/Dancer/Session/Cookie.pm000644 000765 000024 00000020334 12152266243 023054 0ustar00davidstaff000000 000000 package Dancer::Session::Cookie; use strict; use warnings; # ABSTRACT: Encrypted cookie-based session backend for Dancer our $VERSION = '0.22'; # VERSION use base 'Dancer::Session::Abstract'; use Session::Storage::Secure 0.007; use Crypt::CBC; use String::CRC32; use Crypt::Rijndael; use Time::Duration::Parse; use Dancer 1.3113 ':syntax'; # 1.3113 for on_reset_state and fixed after hook use Dancer::Cookie (); use Dancer::Cookies (); use Storable (); use MIME::Base64 (); # crydec my $CIPHER = undef; my $STORE = undef; # cache session here instead of flushing/reading from cookie all the time my $SESSION = undef; sub is_lazy { 1 }; # avoid calling flush needlessly sub init { my ($self) = @_; $self->SUPER::init(); my $key = setting("session_cookie_key") # XXX default to smth with warning or die "The setting session_cookie_key must be defined"; my $duration = $self->_session_expires_as_duration; $CIPHER = Crypt::CBC->new( -key => $key, -cipher => 'Rijndael', ); $STORE = Session::Storage::Secure->new( secret_key => $key, ( $duration ? ( default_duration => $duration ) : () ), ); } # return our cached ID if we have it instead of looking in a cookie sub read_session_id { my ($self) = @_; return $SESSION->id if defined $SESSION; return $self->SUPER::read_session_id; } sub retrieve { my ( $class, $id ) = @_; # if we have a cached session, hand that back instead # of decrypting again return $SESSION if $SESSION && $SESSION->id eq $id; my $ses = eval { if ( my $hash = $STORE->decode($id) ) { # we recover a plain hash, so reconstruct into object bless $hash, $class; } else { _old_retrieve($id); } }; return $SESSION = $ses; } # support decoding old cookies sub _old_retrieve { my ($id) = @_; # 1. decrypt and deserialize $id my $plain_text = _old_decrypt($id); # 2. deserialize $plain_text && Storable::thaw($plain_text); } sub create { my $class = shift; # cache the newly created session return $SESSION = Dancer::Session::Cookie->new; } # we don't write session ID when told; we do it in the after hook sub write_session_id { } # we don't flush when we're told; we do it in the after hook sub flush { } sub destroy { my $self = shift; # gross hack; replace guts with new session guts %$self = %{ Dancer::Session::Cookie->new }; return 1; } # Copied from Dancer::Session::Abstract::write_session_id and # refactored for testing hook 'after' => sub { my $response = shift; if ($SESSION) { # UGH! Awful hack because Dancer instantiates responses # and headers too many times and locks out new cookies $response->{_built_cookies} = 0; my $c = Dancer::Cookie->new( $SESSION->_cookie_params ); Dancer::Cookies->set_cookie_object( $c->name => $c ); } }; # Make sure that the session is initially undefined for every request hook 'on_reset_state' => sub { my $is_forward = shift; undef $SESSION unless $is_forward; }; # modified from Dancer::Session::Abstract::write_session_id to add # support for session_cookie_path sub _cookie_params { my $self = shift; my $name = $self->session_name; my $duration = $self->_session_expires_as_duration; my %cookie = ( name => $name, value => $self->_cookie_value, path => setting('session_cookie_path') || '/', domain => setting('session_domain'), secure => setting('session_secure'), http_only => defined( setting("session_is_http_only") ) ? setting("session_is_http_only") : 1, ); if ( defined $duration ) { $cookie{expires} = time + $duration; } return %cookie; } # refactored for testing sub _cookie_value { my ($self) = @_; # copy self guts so we aren't serializing a blessed object. # we don't set expires, because default_duration will handle it return $STORE->encode( {%$self} ); } # session_expires could be natural language sub _session_expires_as_duration { my ($self) = @_; my $session_expires = setting('session_expires'); return unless defined $session_expires; my $duration = eval { parse_duration($session_expires) }; die "Could not parse session_expires: $session_expires" unless defined $duration; return $duration; } # legacy algorithm sub _old_decrypt { my $cookie = shift; $cookie =~ tr{_*-}{=+/}; $SIG{__WARN__} = sub { }; my ( $crc32, $plain_text ) = unpack "La*", $CIPHER->decrypt( MIME::Base64::decode($cookie) ); return $crc32 == String::CRC32::crc32($plain_text) ? $plain_text : undef; } 1; =pod =encoding utf-8 =head1 NAME Dancer::Session::Cookie - Encrypted cookie-based session backend for Dancer =head1 VERSION version 0.22 =head1 SYNOPSIS Your F: session: "cookie" session_cookie_key: "this random key IS NOT very random" =head1 DESCRIPTION This module implements a session engine for sessions stored entirely in cookies. Usually only B is stored in cookies and the session data itself is saved in some external storage, e.g. database. This module allows to avoid using external storage at all. Since server cannot trust any data returned by client in cookies, this module uses cryptography to ensure integrity and also secrecy. The data your application stores in sessions is completely protected from both tampering and analysis on the client-side. =head1 CONFIGURATION The setting B should be set to C in order to use this session engine in a Dancer application. See L. A mandatory setting is needed as well: B, which should contain a random string of at least 16 characters (shorter keys are not cryptographically strong using AES in CBC mode). Here is an example configuration to use in your F: session: "cookie" session_cookie_key: "kjsdf07234hjf0sdkflj12*&(@*jk" Compromising B will disclose session data to clients and proxies or eavesdroppers and will also allow tampering, for example session theft. So, your F should be kept at least as secure as your database passwords or even more. Also, changing B will have an effect of immediate invalidation of all sessions issued with the old value of key. B can be used to control the path of the session cookie. The default is /. The global B setting is honoured and a secure (https only) cookie will be used if set. =head1 DEPENDENCY This module depends on L. Legacy support is provided using L, L, L, L and L. =head1 SEE ALSO See L for details about session usage in route handlers. See L, L, L for alternative implementation of this mechanism. =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone git://github.com/dagolden/dancer-session-cookie.git =head1 AUTHORS =over 4 =item * Alex Kapranoff =item * Alex Sukria =item * David Golden =back =head1 CONTRIBUTORS =over 4 =item * Michael G. Schwern =item * Neil Kirsopp =item * Nick S. Knutov =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2013 by Alex Kapranoff. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ # vim: ts=4 sts=4 sw=4 et: