App-WebPerimeterScan

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

probes on when the target is a deployment of your own.

The findings are the point of the exercise.  example.com is a good smoke test
because it is not hardened: a run reporting missing CSP, HSTS and nosniff
shows the checks are wired up, and a run that reports nothing - or a critical
finding - means the scan is broken, not the site.

## Example

A run against a local application, with its source tree supplied so the
report can name the endpoints it never reached.  The output is trimmed in the
middle for length.

```
    $ echo localhost:3000 > scope.txt
    $ bin/webperimeter --scope scope.txt --authorized --allow-private --ports 3000 \
        --source ~/src/njh/Database-BI --no-path-probes --max-urls 6 --delay 0.2 --no-color

    webperimeter 0.001.0  2026-11-06T01:05:47Z
    Scope: scope.txt
    Requests: 8

README.md  view on Meta::CPAN



    LOW (1)
    -------
    [port-open-3000] Port 3000 accepts connections from outside the host
      Evidence: TCP connect succeeded, no banner


    INFO (1)
    --------
    [source-routes-unvisited] 71 endpoints defined in source were not scanned
      Evidence: ~/src/njh/Database-BI/lib/Database/BI.pm:2713 GET /login; ~/src/njh/Database-BI/lib/Database/BI.pm:2714 POST /login; ~/src/njh/Database-BI/lib/Database/BI.pm:2715 POST /logout; [...]
      Fix: Name them explicitly, raise --max-urls, or review them by hand.

    Summary: 0 critical, 0 high, 0 medium, 1 low, 1 info
```

That application sends `style-src 'self' 'unsafe-inline'` with a
nonce-based `script-src`.  Only the script sources are judged, so the
inline-style allowance is not reported as a cross-site scripting gap.

lib/App/WebPerimeterScan.pm  view on Meta::CPAN

probes on when the target is a deployment of your own.

The findings are the point of the exercise.  example.com is a good smoke test
because it is not hardened: a run reporting missing CSP, HSTS and nosniff
shows the checks are wired up, and a run that reports nothing - or a critical
finding - means the scan is broken, not the site.

=head1 EXAMPLE

A run against a local application, with its source tree supplied so the
report can name the endpoints it never reached.  The output is trimmed in the
middle for length.

	$ echo localhost:3000 > scope.txt
	$ bin/webperimeter --scope scope.txt --authorized --allow-private --ports 3000 \
	    --source ~/src/njh/Database-BI --no-path-probes --max-urls 6 --delay 0.2 --no-color

	webperimeter 0.001.0  2026-11-06T01:05:47Z
	Scope: scope.txt
	Requests: 8

lib/App/WebPerimeterScan.pm  view on Meta::CPAN



	LOW (1)
	-------
	[port-open-3000] Port 3000 accepts connections from outside the host
	  Evidence: TCP connect succeeded, no banner


	INFO (1)
	--------
	[source-routes-unvisited] 71 endpoints defined in source were not scanned
	  Evidence: ~/src/njh/Database-BI/lib/Database/BI.pm:2713 GET /login; ~/src/njh/Database-BI/lib/Database/BI.pm:2714 POST /login; ~/src/njh/Database-BI/lib/Database/BI.pm:2715 POST /logout; [...]
	  Fix: Name them explicitly, raise --max-urls, or review them by hand.

	Summary: 0 critical, 0 high, 0 medium, 1 low, 1 info

That application sends C<style-src 'self' 'unsafe-inline'> with a
nonce-based C<script-src>.  Only the script sources are judged, so the
inline-style allowance is not reported as a cross-site scripting gap.

C<--allow-private> is required for a loopback or private target; without it

lib/App/WebPerimeterScan.pm  view on Meta::CPAN

	$self->_report('reflected-input',
		host => $report->{host}, url => $uri->as_string, vars => { parameter => $sent },
	) if $reflected;

	return $self;
}

# _source_pass
# Purpose:     the source-aware pass.  A black-box scan can only say that a
#              URL answered; given a docroot and a source tree it can also
#              say which file is served and which line defines the endpoint.
# Entry:       the scan has finished.
# Exit:        $self.
# Side effects: annotates findings; may add source-file-in-docroot.
sub _source_pass :Private
{
	my ($self) = @_;

	my $source = $self->{source};
	return $self unless $source;

lib/App/WebPerimeterScan/I18N.pm  view on Meta::CPAN

	use App::WebPerimeterScan::I18N;

	my $i18n = 'App::WebPerimeterScan::I18N';
	print $i18n->i18n('scope.not_listed', {
		host   => 'evil.example',
		source => 'scope.txt',
	}), "\n";

Let the count choose between singular and plural:

	# "1 endpoint defined in source was not scanned"
	# "3 endpoints defined in source were not scanned"
	print $i18n->i18n('source-routes-unvisited.title', { count => 3 }), "\n";

Choose the language, whatever the environment says:

	$App::WebPerimeterScan::I18N::config{language} = 'de';
	print $i18n->language, "\n";	# 'de' if a German catalogue exists, else 'en'

Remove the "at FILE line N." that C<croak> adds, before you show an error
to a person:

lib/App/WebPerimeterScan/I18N.pm  view on Meta::CPAN

the key, because that is a programming error and the stack trace is what
finds it.

Usage: C<< $self->i18n('scope.empty', { file => $file }) >>

=head3 EXAMPLE

	my $text = App::WebPerimeterScan::I18N->i18n(
		'source-routes-unvisited.title', { count => 3 },
	);
	# "3 endpoints defined in source were not scanned"

=head3 API SPECIFICATION

=head4 INPUT

	{
		key  => { type => 'string', min => 1, position => 0 },
		args => { type => 'hashref', optional => 1, position => 1 },
	}

lib/App/WebPerimeterScan/Messages.pm  view on Meta::CPAN

	'cli.usage'          => <<'EOF',
Usage: webperimeter --scope FILE [options]

  -s, --scope FILE        Hosts you are authorised to test (required)
      --authorized        Confirm the scope hosts are yours (required to scan)
      --dry-run           Show what would be scanned, send nothing
  -f, --format FORMAT     text (default), json or html
  -o, --output FILE       Write the report to FILE instead of stdout
      --ports LIST        Comma separated ports to probe
      --docroot DIR       Docroot to resolve discovered paths against (repeatable)
      --source DIR        Source tree to map endpoints back to code (repeatable)
      --timeout SECONDS   HTTP response timeout (default 10)
      --connect-timeout N TCP connect timeout for port/TLS checks (default 3)
      --delay SECONDS     Minimum gap between requests to one host (default 0.5)
  -d, --depth N           Link-following depth from each root URL (default 1)
      --max-urls N        Page budget per host (default 40)
      --no-path-probes    Skip the well-known sensitive path checks
      --reflection-probe  Send one marker parameter to test output encoding
      --allow-private     Permit loopback and private targets (staging, tests)
      --fail-on LEVEL     Exit 1 at or above this severity (default high)
      --no-color          Disable ANSI colour in text output (or --no-colour)

lib/App/WebPerimeterScan/Messages.pm  view on Meta::CPAN

	'reflected-input.evidence' => 'Sent {parameter} and received it back unencoded',
	'reflected-input.fix'      => 'HTML-encode all output, and add a CSP that forbids inline script.',

	'source-file-in-docroot.title'  => 'Sensitive file is inside a document root: {file}',
	'source-file-in-docroot.detail' => 'The file is on disk under a docroot but was not served during this scan. Any change that starts serving dotfiles - a handler, a rewrite, a new vhost - exposes it at once.',
	'source-file-in-docroot.fix'    => 'Move it above the document root, or deny the path at the web server.',

	'source-routes-unvisited.title' => {
		plural => 'count',
		forms  => {
			one   => '{count} endpoint defined in source was not scanned',
			other => '{count} endpoints defined in source were not scanned',
		},
	},
	'source-routes-unvisited.detail' => 'These routes exist in the code but no crawled page linked to them, so none of the checks above saw how they behave. They are exactly the surface a link-following scan never reaches.',
	'source-routes-unvisited.fix'    => 'Name them explicitly, raise --max-urls, or review them by hand.',

	# ==================================================================
	# Response header checks
	# ==================================================================
	'hsts-missing.title'    => 'Strict-Transport-Security header is missing',
	'hsts-missing.detail'   => 'Without HSTS a user who types the bare hostname makes one plaintext request, which is enough for a network attacker to intercept the session.',

lib/App/WebPerimeterScan/Messages.pm  view on Meta::CPAN

		},
	},
	'cors-misconfiguration.fix'      => 'Echo back only origins on an explicit allowlist, never a wildcard, and only with credentials when necessary.',

	'trace-enabled.title'    => 'HTTP TRACE is enabled',
	'trace-enabled.detail'   => 'TRACE echoes the request back, which can be combined with other flaws to read cookies and headers.',
	'trace-enabled.evidence' => 'Allow: {allow}',
	'trace-enabled.fix'      => 'Disable TRACE (TraceEnable off in Apache).',

	'write-methods-enabled.title'    => 'Write methods advertised on a public URL',
	'write-methods-enabled.detail'   => 'PUT, DELETE or PATCH are allowed here. That may be intended for an API, but it is worth confirming the endpoint authenticates and authorises.',
	'write-methods-enabled.evidence' => 'Allow: {allow}',
	'write-methods-enabled.fix'      => 'Restrict methods per route at the web server or application layer.',

	# ==================================================================
	# TLS
	# ==================================================================
	'tls-unavailable.title'  => 'TLS handshake failed',
	'tls-unavailable.detail' => 'The host did not complete a TLS handshake on the scanned port, so either HTTPS is not served there or the TLS configuration is broken.',
	'tls-unavailable.fix'    => 'Confirm the port serves HTTPS and that the certificate chain is complete.',

lib/App/WebPerimeterScan/Messages.pm  view on Meta::CPAN


	'server-info-exposed.title'  => 'Apache server-info is public',
	'server-info-exposed.detail' => 'mod_info is reachable and publishes the full module configuration.',
	'server-info-exposed.fix'    => 'Restrict /server-info with Require ip on localhost, or disable mod_info.',

	'phpinfo-exposed.title'  => 'phpinfo() is public',
	'phpinfo-exposed.detail' => 'A phpinfo page leaks absolute paths, loaded extensions, environment variables and sometimes credentials.',
	'phpinfo-exposed.fix'    => 'Delete phpinfo scripts from production.',

	'spring-actuator-exposed.title'  => 'Spring Boot actuator environment is public',
	'spring-actuator-exposed.detail' => 'The actuator env endpoint is reachable and commonly exposes datasource credentials and API keys.',
	'spring-actuator-exposed.fix'    => 'Require authentication on /actuator/**, and only expose health and info.',

	'spring-health-exposed.title'  => 'Spring Boot actuator health is public',
	'spring-health-exposed.detail' => 'Health detail is public. This is minor on its own but confirms a Spring Boot management surface.',
	'spring-health-exposed.fix'    => 'Expose only the health endpoint, and set management.endpoint.health.show-details=never.',

	'composer-json-exposed.title'  => 'composer.json is public',
	'composer-json-exposed.detail' => 'Dependency pins are readable, which tells an attacker exactly which versions to try.',
	'composer-json-exposed.fix'    => 'Deny access to composer.json and composer.lock.',

	'package-json-exposed.title'  => 'package.json is public',
	'package-json-exposed.detail' => 'Dependency pins are readable, which tells an attacker exactly which versions to try.',
	'package-json-exposed.fix'    => 'Deny access to package.json and package-lock.json.',

	'crossdomain-xml.title'  => 'Permissive crossdomain.xml',

lib/App/WebPerimeterScan/Source.pm  view on Meta::CPAN


	use App::WebPerimeterScan::Source;

	my $source = App::WebPerimeterScan::Source->new(
		docroots => ['/srv/www/example'],
	);

	my $hit = $source->file_for('/.git/config');
	print "served from $hit->{path} ($hit->{size} bytes)\n" if $hit;

Find the line of code that defines an endpoint:

	my $app = App::WebPerimeterScan::Source->new(
		source_dirs => ['/home/me/src/example/lib'],
	);

	my $route = $app->route_for('/view/dogs?page=2');
	print "$route->{method} $route->{pattern} at $route->{file} line $route->{line}\n"
		if $route;

List every endpoint the source defines:

	for my $route (@{ $app->routes }) {
		print "$route->{pattern}\n";
	}

Look for secret files that exist on disk, even if the server did not serve
them:

	my $probes = App::WebPerimeterScan::Checks::sensitive_probes();
	for my $hit (@{ $source->sensitive_on_disk($probes) }) {

lib/App/WebPerimeterScan/Source.pm  view on Meta::CPAN

A scan from outside can only say "this URL answered".  This module adds
two facts that tell you what to change:

=over 4

=item * B<The file.>  Given a document root (the directory the web server
serves files from), it finds the file on disk that a URL path would be
served from.

=item * B<The route.>  Given your application's source code, it finds the
line that declares the endpoint, for example
C<< $r->get('/view/:name') >>.

=back

The module only reads files.  It never sends network traffic and never
changes a file.

A path is only accepted if it is inside the document root after every
symbolic link is followed.  So C<..> in the path, a symbolic link that
points out of the tree, and C<%2e%2e> (an encoded C<..>) cannot reach a

t/scan.t  view on Meta::CPAN

ok(!$by_id{'catch-all-200'}, 'a 404 for unknown paths is not a catch-all');

my ($on_disk) = grep { $_->{id} eq 'source-file-in-docroot' } @{ $findings->all };
ok($on_disk, 'the unserved .env on disk is reported');
like($on_disk->{title}, qr/\.env/, '... by name');
ok(!(grep { $_->{id} eq 'source-file-in-docroot' && $_->{title} =~ /\.git/ } @{ $findings->all }),
	'the served file is not reported twice');

my $unvisited = $by_id{'source-routes-unvisited'};
ok($unvisited, 'the route nothing links to is reported');
like($unvisited->{title}, qr/\A1 endpoint defined in source was not scanned\z/, 'singular title for one route');
like($unvisited->{evidence}, qr{/hidden/:id}, 'the unvisited route is named');
unlike($unvisited->{evidence}, qr{/about}, 'the crawled route is not');
is($by_id{'csp-missing'}{source}, '', 'a host-level finding has no source line');

cmp_ok($scanner->http->requests, '>', 20, 'the request counter covers probes as well as pages');

# The same scope without --allow-private: refused, and loudly.
my $refused = App::WebPerimeterScan->new(
	scope => App::WebPerimeterScan::Scope->new->load_file($scope_file),
	ports => [ $port ],



( run in 0.833 second using v1.01-cache-2.11-cpan-eb134014566 )