18 Jun 2012 14:02:27 UTC
- Distribution: Dancer-Plugin-EscapeHTML
- Module version: 0.22
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (892 / 3 / 0)
- KwaliteeBus factor: 1
- 89.04% Coverage
- License: perl_5
- Activity24 month
- Download (5.26KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- Automatic HTML encoding
- SEE ALSO
- LICENSE AND COPYRIGHT
Dancer::Plugin::EscapeHTML - Escape HTML entities to avoid XSS vulnerabilities
This plugin provides convenience keywords
unescape_htmlwhich are simply quick shortcuts to
use Dancer::Plugin::EscapeHTML; my $encoded = escape_html($some_html);
It also provides optional automatic escaping of all HTML (see below.)
This plugin is intended to provide a quick and simple way to ensure that HTML passed in the tokens hashref to the template is safely escaped (encoded), thereby helping to avoid XSS/cross-site scripting vulnerabilities.
You can encode specific bits of data yourself using the
unescape_htmlkeywords, or you can enable automatic escaping of all values passed to the template.
When the plugin is loaded, the following keywords are exported to your app:
Encodes HTML entities; shortcut to
Decodes HTML entities; shortcut to
If desired, you can also enable automatic HTML encoding of all params passed to templates.
If you're using Template Toolkit, you may wish to look instead at Template::Stash::EscapeHTML which takes care of this reliably at the template engine level, and is more widely-used and tested than this module.
To arrange for this plugin to automatically encode HTML entities, enable the automatic_encoding option in your app's config - for instance, add the following to your
plugins: EscapeHTML: automatic_escaping: 1
Now, all values passed to the template will be automatically encoded, so you should be protected from potential XSS vulnerabilities.
Of course, this has the drawback that you cannot provide pre-prepared HTML in template params to be used "as is". You can get round this by using the
exclude_patternoption to provide a pattern to match token names which should be exempted from automatic escaping - for example:
plugins: EscapeHTML: automatic_escaping: 1 exclude_pattern: '_html$'
The above would exclude token names ending in
_htmlfrom being escaped.
By default, blessed objects being passed to the template will be left unmolested, as digging around in the internals of the object is probably not wise or desirable. However, if you do want this to be done, set the
traverse_objectssetting to a true value, and objects will be treated just like any other hashref/arrayref.
<davidp at preshweb.co.uk>
<tom.rathborne at gmail.com>
Copyright 2011 David Precious.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
Module Install Instructions
To install Dancer::Plugin::EscapeHTML, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Dancer::Plugin::EscapeHTML
For more information on module installation, please visit the detailed CPAN module installation guide.