| 1 | package Alien::Build::Plugin::Fetch::HostAllowList; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use 5.008004; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Alien::Build::Plugin 2.64; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # ABSTRACT: Require that Alien::Build based aliens only fetch from an allow list of hosts | ||||||||||||||||||||
| 10 | 1 | our $VERSION = '0.02'; # VERSION | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 0 | ▶ | has '+allow_hosts' => sub { [ | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
| |||||||||||||||||||||
| 14 | defined $ENV{ALIEN_BUILD_HOST_ALLOW} | ||||||||||||||||||||
| 15 | ? split /,/, $ENV{ALIEN_BUILD_HOST_ALLOW} | ||||||||||||||||||||
| 16 | : () | ||||||||||||||||||||
| 17 | 0 | ▶ | ] }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | sub init | ||||||||||||||||||||
| 20 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 21 | 1 | my($self, $meta) = @_; | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | my %allowed = map { $_ => 1 } @{ $self->allow_hosts }; | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 3 | ▶ | $meta->around_hook( fetch => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.3
| |||||||||||||||||||||
| 26 | 3 | my $orig = shift; | |||||||||||||||||||
| 27 | 3 | my $build = shift; | |||||||||||||||||||
| 28 | 3 | ▶ | my $url = $_[0] || $build->meta_prop->{start_url}; | ||||||||||||||||||
|
Condition66%2/3
$_[0] || $build->meta_prop->{'start_url'}
MC/DC0%0/2
$_[0] || $build->meta_prop->{'start_url'}
$_[0]
$build->meta_prop->{'start_url'}
Truth table66%2/3
A || B
A= $_[0]B= $build->meta_prop->{'start_url'}
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # If URL doesn't have a : then it doesn't have a scheme or | ||||||||||||||||||||
| 31 | # protocol and we assume that it is a file or directory. | ||||||||||||||||||||
| 32 | 3 | ▶ | if($url =~ /:/) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | { | ||||||||||||||||||||
| 34 | 3 | my $url = URI->new($url); | |||||||||||||||||||
| 35 | 3 | ▶ | if($url->scheme ne 'file') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | { | ||||||||||||||||||||
| 37 | 3 | my $host = eval { $url->host }; | |||||||||||||||||||
| 38 | 3 | ▶ | die "unable to determine host from $url: $@" if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 3 | ▶ | die "The host $host is not in the allow list" unless $allowed{$host}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 2 | $orig->($build, @_); | |||||||||||||||||||
| 44 | 1 | }); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | 1; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | __END__ | ||||||||||||||||||||