Skip to content

Commit

Permalink
s/forbidden/allowed/ whitelisting easier than blacklisting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ted Guild committed Jun 23, 2015
1 parent 8505ad9 commit bdf0e3d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
22 changes: 6 additions & 16 deletions bin/checklink
Expand Up @@ -82,7 +82,7 @@ sub new

$self->allow_private_ips(1);

$self->protocols_forbidden([qw(mailto javascript)]);
$self->protocols_allowed([qw(http https ftp)]);

return $self;
}
Expand Down Expand Up @@ -206,16 +206,6 @@ sub ip_disallowed
$resp->header('Client-Warning', 'Internal response');
}

my $scheme = undef;
$scheme = $uri->scheme();
#whitelist regex if short enough
if ($scheme !~ m/^(http|https|ftp|urn)$/ ) {
$resp = HTTP::Response->new(403,
'Checking certain protocols disallowed by link checker configuration'
);
$resp->header('Client-Warning', 'Internal response');
}

return $resp;
}

Expand Down Expand Up @@ -500,11 +490,11 @@ $@
EOF
}

# Add configured forbidden protocols
if ($Cfg{Forbidden_Protocols}) {
my $forbidden = $ua->protocols_forbidden();
push(@$forbidden, split(/[,\s]+/, lc($Cfg{Forbidden_Protocols})));
$ua->protocols_forbidden($forbidden);
# Add configured allowed protocols
if ($Cfg{Allowed_Protocols}) {
my $allowed = $ua->protocols_allowed();
push(@$allowed, split(/[,\s]+/, lc($Cfg{Allowed_Protocols})));
$ua->protocols_allowed($allowed);
}

if ($Opts{Command_Line}) {
Expand Down
11 changes: 6 additions & 5 deletions etc/checklink.conf
Expand Up @@ -54,13 +54,14 @@


#
# Forbidden_Protocols is a comma separated list of additional protocols/URI
# schemes that the link checker is not allowed to use. The javascript and
# mailto schemes are always forbidden, and so is the file scheme when running
# as a CGI script.
# Allowed_Protocols is a comma separated list of additional protocols/URI
# schemes that the link checker is allowed to use besides http, https and ftp.
#
# The javascript and mailto schemes for example are forbidden, and so is
# the file scheme when running as a CGI script.
#
# Default:
# Forbidden_Protocols = javascript,mailto
# Allowed_Protocols = http,https,ftp


#
Expand Down

0 comments on commit bdf0e3d

Please sign in to comment.