The OWASP Encoder Plugin creates a Velocity viewtool with a number of useful input-sanitization functions. Strategic use of such procedures in Velocity templates can help prevent XSS-based attacks.
Installation
Please refer to the General Instructions under Plugin Examples.
Usage
Once the plugin is installed, your Velocity context will include a new viewtool accessed by calling $owasp. Its capabilities can be seen in the table below; each method accepts a string as its input argument.
All for... methods perform encoding operations that escape or enclose terminating sequences or similar dangers, and return the modified input. More detailed documentation of these can be found in the Encoder class's Javadoc.
| Method | Description |
|---|---|
$owasp.validateUrl() | Returns true if input is a valid URL, false otherwise. |
$owasp.urlHasXSS() | Returns true if input contains a substring that may execute a script. |
$owasp.cleanUrl() | If input is a valid URL, returns a version sanitized with the forHtmlAttribute() method; returns null otherwise. |
$owasp.forCDATA() | Encodes data for an XML CDATA section. Replaces ]]> with ]]>]]<