| 1 | package Catalyst::ActionRole::RequireSSL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $Catalyst::ActionRole::RequireSSL::VERSION = '1.00'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | with 'Catalyst::ActionRole::RequireSSL::Role'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | Catalyst::ActionRole::RequireSSL - Force an action to be secure only. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | version 1.00 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | package MyApp::Controller::Foo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | use parent qw/Catalyst::Controller::ActionRole/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub bar : Local Does('RequireSSL') { ... } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | sub bar : Local Does('NoSSL') { ... } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | =head2 HIERARCHY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | You can chain the SSL Roles to allow for enforced combinations such as all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | secure apart from a certain action and vice versa. See the tests to see this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | in action. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | ▶ | around execute => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 9 | my ($controller, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | unless(defined $c->config->{require_ssl}->{disabled}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | $c->config->{require_ssl}->{disabled} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | $c->engine->isa("Catalyst::Engine::HTTP") ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | #use Data::Dumper;warn Dumper($c->action); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | ▶ | if (!$c->req->secure && $c->req->method eq "POST" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $c->req->secure and $c->req->method eq "POST" and not $c->config->{"require_ssl"}{"ignore_on_post"}
not $c->req->secure and $c->req->method eq "POST"
MC/DC66%2/3
not $c->req->secure and $c->req->method eq "POST" and not $c->config->{"require_ssl"}{"ignore_on_post"}
not $c->req->secure
$c->req->method eq "POST"
not $c->config->{"require_ssl"}{"ignore_on_post"}
Truth table75%3/4
not(A) and B and not(C)
A= not $c->req->secureB= $c->req->method eq "POST"C= not $c->config->{"require_ssl"}{"ignore_on_post"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | && !$c->config->{require_ssl}->{ignore_on_post}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | $c->error("Cannot secure request on POST") | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | unless( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$c->config->{"require_ssl"}{"disabled"} or $c->req->secure or $c->req->method eq "POST" or not $self->check_chain($c)
$c->config->{"require_ssl"}{"disabled"} or $c->req->secure or $c->req->method eq "POST"
$c->config->{"require_ssl"}{"disabled"} or $c->req->secure
MC/DC75%3/4
$c->config->{"require_ssl"}{"disabled"} or $c->req->secure or $c->req->method eq "POST" or not $self->check_chain($c)
$c->config->{"require_ssl"}{"disabled"}
$c->req->secure
$c->req->method eq "POST"
not $self->check_chain($c)
Truth table80%4/5
A or B or C or not(D)
A= $c->config->{"require_ssl"}{"disabled"}B= $c->req->secureC= $c->req->method eq "POST"D= not $self->check_chain($c)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $c->config->{require_ssl}->{disabled} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $c->req->secure || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $c->req->method eq "POST" || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | !$self->check_chain($c) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | my $uri = $c->req->uri->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 4 | $uri->scheme('https'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 4 | $c->res->redirect( $uri, 301 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | $c->detach(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $c->log->warn("Would've redirected to SSL") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | ▶ | if $c->config->{require_ssl}->{disabled} && $c->debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->config->{"require_ssl"}{"disabled"} and $c->debug
MC/DC0%0/2
$c->config->{"require_ssl"}{"disabled"} and $c->debug
$c->config->{"require_ssl"}{"disabled"}
$c->debug
Truth table33%1/3
A and B
A= $c->config->{"require_ssl"}{"disabled"}B= $c->debug
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | $self->$orig( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | Simon Elliott <cpan@papercreatures.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | =head1 THANKS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | Andy Grundman, <andy@hybridized.org> for the original RequireSSL Plugin | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | t0m (Tomas Doran), zamolxes (Bogdan Lucaciu), wreis (Wallace Reis) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Copyright 2009 by Simon Elliott | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||