SecureEncoder contains many methods for manipulating untrusted data Strings
into RFC-Compliant Strings for a given context by encoding “bad” data into
the proper format.
Constructor Summary
This class does not have a constructor, so you cannot create it directly.
Encodes a given input for use in a general HTML context. E.g.
text content and text attributes. This method takes the UNION of allowed
characters between the two context, so may be more imprecise that the
more specific contexts. Generally, this method is preferred unless you
specifically understand the context in which untrusted data will be
output.
Encodes a given input for use in an HTML Attribute guarded by a double
quote. This method is preferred if you understand exactly how the output
of this will be used in the HTML document.
Encodes a given input for use in an HTML Attribute guarded by a single
quote. This method is preferred if you understand exactly how the output
of this will be used in the HTML document.
Encodes a given input for use in an HTML Attribute left unguarded.
This method is preferred if you understand exactly how the output
of this will be used in the HTML document.
Encodes a given input for use in JavaScript inside an HTML attribute.
This method is preferred if you understand exactly how the output
of the will be used in the page
Replace special JavaScript characters with their Hex Encoded equivalents prepended with \x for character codes under 128 and \u for character codes over 128
Parameters:
input - untrusted input to be encoded, if necessary
Encodes a given input for use in JavaScript inside an HTML block.
This method is preferred if you understand exactly how the output
of the will be used in the page
Example Usage:
1<script type="text/javascript">2 var data = "${SecureEncoder.forJavaScriptInBlock(unsafeData)}";3</script>
Flow:
Allow AlphaNumerics and some Special characters
Slash escape certain illegal characters
Replace special JavaScript characters with their Hex Encoded equivalents prepended with \x for character codes under 128 and \u for character codes over 128
Parameters:
input - untrusted input to be encoded, if necessary
Encodes a given input for use in JavaScript inside an HTML context.
This method takes the UNION of allowed characters among the other
contexts, so may be more imprecise that the more specific contexts.
Generally, this method is preferred unless you specifically understand
the context in which untrusted data will be output.
Example Usage:
1<script type="text/javascript">2 var data = "${SecureEncoder.forJavaScriptInHTML(unsafeData)}";3</script>45<button onclick="alert('${SecureEncoder.forJavaScriptInHTML(unsafeData)}');">
Flow:
Allow AlphaNumerics and some Special characters
Slash escape certain illegal characters
Replace special JavaScript characters with their Hex Encoded equivalents prepended with \x for character codes under 128 and \u for character codes over 128
Parameters:
input - untrusted input to be encoded, if necessary
Encodes a given input for use in JavaScript inside a JavaScript source
file. This method is preferred if you understand exactly how the output
of the will be used in the page
Example Usage:
1<...inside foobar.js...>2var data = "${SecureEncoder.forJavaScriptInSource(unsafeData)}";
Flow:
Allow AlphaNumerics and some Special characters
Slash escape certain illegal characters
Replace special JavaScript characters with their Hex Encoded equivalents prepended with \x for character codes under 128 and \u for character codes over 128
Parameters:
input - untrusted input to be encoded, if necessary
Encodes a given input for use in a general XML context. E.g.
text content and text attributes. This method takes the UNION of allowed
characters between the other contexts, so may be more imprecise that the
more specific contexts. Generally, this method is preferred unless you
specifically understand the context in which untrusted data will be
output.
Note: It is recommended that you use a real parser, as this method
can be misused, but is left here if a parser is unavailable to you
Encodes a given input for use in an XML attribute guarded by a double
quote. This method is preferred if you understand the context in which
untrusted data will be output.
Note: It is recommended that you use a real parser, as this method
can be misused, but is left here if a parser is unavailable to you
Encodes a given input for use in an XML attribute guarded by a single
quote. This method is preferred if you understand the context in which
untrusted data will be output.
Note: It is recommended that you use a real parser, as this method
can be misused, but is left here if a parser is unavailable to you