| 1 | package Articulate::Validation::NoScript; | ||
| 2 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Articulate::Validation::NoScript | ||
| 10 | |||
| 11 | =head1 DESCRIPTION | ||
| 12 | |||
| 13 | An example validator to do a rudimentary check to see if the content has the text "<script" in it, to prevent users from injecting scripts directly into your application. | ||
| 14 | |||
| 15 | It doesn't thoroughly prevent Javascript injection, an onload attribute might do just as well. | ||
| 16 | |||
| 17 | =head1 METHODS | ||
| 18 | |||
| 19 | =head3 validate | ||
| 20 | |||
| 21 | Returns true if the content contains qr/<script/i; false otherwise. | ||
| 22 | |||
| 23 | It does not look at the meta to determine content type so might behave unexpectedly, e.g. if called on plain text. | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | sub validate { | ||
| 28 | 0 | ▶ | my $self = shift; |
|
Subroutine
validate: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 29 | 0 | my $item = shift; | |
| 30 | 0 | return ( $item->content !~ /<script/i ); | |
| 31 | } | ||
| 32 | |||
| 33 | 1 | 1; | |