| 1 | package Mojolicious::Plugin::SecureOnly; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 0 | ▶ | has 'conf' => sub { {} }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | 3 | my ($self, $app, $conf) = @_; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | $self->conf({%$conf, %{$app->config('SecureOnly')||{}}}); | ||||||||||||||||||||||||||
|
Condition50%1/2
$app->config('SecureOnly') || {}
MC/DC0%0/1
$app->config('SecureOnly') || {}
$app->config('SecureOnly')
Truth table50%1/2
A
A= $app->config('SecureOnly')
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 8 | ▶ | $app->hook(before_dispatch => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||
| 14 | 8 | my $c = shift; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 8 | ▶ | if ( $self->conf->{not_modes} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | return if grep { $_ eq $app->mode } @{$self->conf->{not_modes}||[]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->conf->{'not_modes'} || []
MC/DC0%0/1
$self->conf->{'not_modes'} || []
$self->conf->{'not_modes'}
Truth table50%1/2
A
A= $self->conf->{'not_modes'}
| |||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | 7 | ▶ | if ( $self->conf->{modes} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | return unless grep { $_ eq $app->mode } @{$self->conf->{modes}||[]}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->conf->{'modes'} || []
MC/DC0%0/1
$self->conf->{'modes'} || []
$self->conf->{'modes'}
Truth table50%1/2
A
A= $self->conf->{'modes'}
| |||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | ▶ | return if $c->req->is_secure; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 6 | ▶ | return $app->log->warn('SecureOnly disabled; Reverse Proxy support not enabled in Mojolicious, see http://mojolicious.org/perldoc/Mojo/Server#reverse_proxy') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $c->tx->req->reverse_proxy and detect_proxy($c)
MC/DC100%2/2
not $c->tx->req->reverse_proxy and detect_proxy($c)
not $c->tx->req->reverse_proxy
detect_proxy($c)
Truth table100%3/3
not(A) and B
A= not $c->tx->req->reverse_proxyB= detect_proxy($c)
| |||||||||||||||||||||||||||||
| 25 | if !$c->tx->req->reverse_proxy && detect_proxy($c); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 5 | my $url = $c->req->url->to_abs; | |||||||||||||||||||||||||||
| 28 | 5 | $url->scheme('https'); | |||||||||||||||||||||||||||
| 29 | 5 | ▶ | $url->port($self->conf->{secureport}) if $self->conf->{secureport}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 5 | $c->app->log->debug("SecureOnly enabled; Request for insecure resource, redirecting to $url"); | |||||||||||||||||||||||||||
| 31 | 5 | $c->redirect_to($url); | |||||||||||||||||||||||||||
| 32 | 3 | }); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | sub detect_proxy { | ||||||||||||||||||||||||||
|
Subroutine
detect_proxy: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 2 | my $c = shift; | |||||||||||||||||||||||||||
| 37 | 2 | ▶ | return $c->tx->req->headers->header('X-Forwarded-For') || $c->tx->req->headers->header('X-Forwarded-Proto') | ||||||||||||||||||||||||||
|
Condition66%2/3
$c->tx->req->headers->header('X-Forwarded-For') || $c->tx->req->headers->header('X-Forwarded-Proto')
MC/DC50%1/2
$c->tx->req->headers->header('X-Forwarded-For') || $c->tx->req->headers->header('X-Forwarded-Proto')
$c->tx->req->headers->header('X-Forwarded-For')
$c->tx->req->headers->header('X-Forwarded-Proto')
Truth table66%2/3
A || B
A= $c->tx->req->headers->header('X-Forwarded-For')B= $c->tx->req->headers->header('X-Forwarded-Proto')
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | 1; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | __END__ | ||||||||||||||||||||||||||||