| 1 |
Overriding HTML::StripScripts to add tags |
| 2 |
----------------------------------------- |
| 3 |
|
| 4 |
The allowed tags and attributes in HTML::StripScripts is not complete. Unsafe |
| 5 |
tags have been specifically left out (eg <script>). |
| 6 |
|
| 7 |
If, however, you would like to add certain tags or attributes into the allowed |
| 8 |
list, then you will need to override HTML::StripScripts (or |
| 9 |
HTML::StripScripts::Parser). |
| 10 |
|
| 11 |
In this example, I add the <meta> and <link> tags into tags allowed under |
| 12 |
the <head> tag. |
| 13 |
|
| 14 |
WARNING: Both of these tags are potentially DANGEROUS. So think very carefully |
| 15 |
before you allow them. Imagine, for example: |
| 16 |
|
| 17 |
<meta http-equiv="refresh" content="0;url=http://hackme.com" /> |
| 18 |
|
| 19 |
After enabling these tags, you will be able to filter them with Rules, for |
| 20 |
instance: |
| 21 |
|
| 22 |
$f = MyStripScripts->new({ |
| 23 |
Rules => { meta => \&check_meta_tags }, |
| 24 |
}); |
| 25 |
|
| 26 |
-------------------------------------------------------------------------------- |
| 27 |
In this example, I override the tag definitions in MyStripScripts. |
| 28 |
|
| 29 |
To run the example: |
| 30 |
|
| 31 |
- change to the examples/tags directory: |
| 32 |
|
| 33 |
cd examples/tags |
| 34 |
|
| 35 |
- then type: |
| 36 |
|
| 37 |
perl tags.pl |
| 38 |
|
| 39 |
The example parses the same HTML, first with HTML::StripScripts::Parser, then |
| 40 |
with MyStripScripts (a subclass of HTML::StripScripts::Parser) and prints out |
| 41 |
the two versions. |
| 42 |
|
| 43 |
No checking of the values is done. |
| 44 |
|
| 45 |
The example script requires HTML::StripScripts::Parser to work. |