Koha-QA
view release on metacpan or search on metacpan
lib/Koha/QA/Security/Nonce.pm view on Meta::CPAN
package Koha::QA::Security::Nonce;
use Modern::Perl;
use base 'Koha::QA::Base';
=head1 NAME
Koha::QA::Security::Nonce - Check for missing nonce attributes in script/link tags
=head1 SYNOPSIS
use Koha::QA::Security::Nonce;
# With a file
my $checker = Koha::QA::Security::Nonce->new({file => $file_path});
# Or with content directly
my $checker = Koha::QA::Security::Nonce->new({content => $template_content});
my $is_valid = $checker->check;
my @errors = $checker->errors;
=head1 DESCRIPTION
This module checks Template Toolkit files for script and link tags that are missing
nonce attributes.
=head1 METHODS
=head2 new
my $checker = Koha::QA::Security::Nonce->new({file => $file_path});
Creates a new Nonce checker instance.
=head2 check
my $is_valid = $checker->check;
Checks the file for missing nonce attributes.
=head2 errors
my @errors = $checker->errors;
Returns array of error hashrefs, each containing:
- file: the file path
- line: the line number
- script: the script/link tag content
- error: the error type (missing_nonce_attribute)
=cut
sub check {
my ($self) = @_;
my $content = $self->content;
my @errors;
my @lines = split /\n/, $content;
return 1 unless grep { $_ =~ m[<(script|style)] } @lines;
my $line_number = 0;
for my $line (@lines) {
$line_number++;
( run in 1.021 second using v1.01-cache-2.11-cpan-eb134014566 )