|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.owasp.esapi.Encoder
Reference implementation of the IEncoder interface. This implementation takes a whitelist approach, encoding everything not specifically identified in a list of "immune" characters. Several methods follow the approach in the Microsoft AntiXSS Library.
The canonicalization algorithm is complex, as it has to be able to recognize encoded characters that might affect downstream interpreters without being told what encodings are possible. The stream is read one character at a time. If an encoded character is encountered, it is canonicalized and pushed back onto the stream. If the next character is encoded, then a intrusion exception is thrown for the double-encoding which is assumed to be an attack. This assumption is a bit aggressive as some double-encoded characters may be sent by ordinary users through cut-and-paste.
If an encoded character is recognized, but does not parse properly, the response is to eat the character, stripping it from the input.
Currently the implementation supports:
IEncoder| Field Summary | |
static char[] |
CHAR_ALPHANUMERICS
The Constant CHAR_ALPHANUMERICS. |
static char[] |
CHAR_DIGITS
The Constant CHAR_DIGITS. |
static char[] |
CHAR_LETTERS
The Constant CHAR_LETTERS. |
static char[] |
CHAR_LOWERS
The Constant CHAR_LOWERS. |
static char[] |
CHAR_PASSWORD_LETTERS
|
static char[] |
CHAR_SPECIALS
The Constant CHAR_SPECIALS. |
static char[] |
CHAR_UPPERS
The Constant CHAR_UPPERS. |
static int |
ENTITY_ENCODING
|
static int |
NO_ENCODING
Encoding types |
static int |
PERCENT_ENCODING
|
static int |
URL_ENCODING
|
| Constructor Summary | |
Encoder()
|
|
| Method Summary | |
java.lang.String |
canonicalize(java.lang.String input)
Simplifies percent-encoded and entity-encoded characters to their simplest form so that they can be properly validated. |
byte[] |
decodeFromBase64(java.lang.String input)
Decode data encoded with BASE-64 encoding. |
java.lang.String |
decodeFromURL(java.lang.String input)
Decode from URL. |
java.lang.String |
encodeForBase64(byte[] input,
boolean wrap)
Encode for base64. |
java.lang.String |
encodeForDN(java.lang.String input)
Encode data for use in an LDAP distinguished name. |
java.lang.String |
encodeForHTML(java.lang.String input)
Encode data for use in HTML content. |
java.lang.String |
encodeForHTMLAttribute(java.lang.String input)
Encode data for use in HTML attributes. |
java.lang.String |
encodeForJavascript(java.lang.String input)
Encode for javascript. |
java.lang.String |
encodeForLDAP(java.lang.String input)
Encode data for use in LDAP queries. |
java.lang.String |
encodeForSQL(java.lang.String input)
This method is not recommended. |
java.lang.String |
encodeForURL(java.lang.String input)
Encode for use in a URL. |
java.lang.String |
encodeForVBScript(java.lang.String input)
Encode data for use in visual basic script. |
java.lang.String |
encodeForXML(java.lang.String input)
Encode data for use in an XML element. |
java.lang.String |
encodeForXMLAttribute(java.lang.String input)
Encode data for use in an XML attribute. |
java.lang.String |
encodeForXPath(java.lang.String input)
This implementation encodes almost everything and may overencode. |
static void |
main(java.lang.String[] args)
|
java.lang.String |
normalize(java.lang.String input)
Normalizes special characters down to ASCII using the Normalizer built into Java. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int NO_ENCODING
public static final int URL_ENCODING
public static final int PERCENT_ENCODING
public static final int ENTITY_ENCODING
public static final char[] CHAR_LOWERS
public static final char[] CHAR_UPPERS
public static final char[] CHAR_DIGITS
public static final char[] CHAR_SPECIALS
public static final char[] CHAR_LETTERS
public static final char[] CHAR_ALPHANUMERICS
public static final char[] CHAR_PASSWORD_LETTERS
| Constructor Detail |
public Encoder()
| Method Detail |
public java.lang.String canonicalize(java.lang.String input)
<or
%26lt;or
<. This implementation disallows ALL double-encoded characters and throws an IntrusionException when they are detected. Also, named entities that are not known are simply removed. Note that most data from the browser is likely to be encoded with URL encoding (FIXME: RFC). The web server will decode the URL and form data once, so most encoded data received in the application must have been double-encoded by the attacker. However, some HTTP inputs are not decoded by the browser, so this routine allows a single level of decoding.
canonicalize in interface IEncoderinput - unvalidated input from an HTTP request
IntrusionExceptionorg.owasp.esapi.interfaces.IValidator#canonicalize(java.lang.String)public java.lang.String normalize(java.lang.String input)
normalize in interface IEncoderinput -
org.owasp.esapi.interfaces.IValidator#normalize(java.lang.String)public java.lang.String encodeForHTML(java.lang.String input)
IEncoder
encodeForHTML in interface IEncoderinput - the input
public java.lang.String encodeForHTMLAttribute(java.lang.String input)
IEncoder
encodeForHTMLAttribute in interface IEncoderinput - the input
public java.lang.String encodeForJavascript(java.lang.String input)
IEncoder
encodeForJavascript in interface IEncoderinput - the input
public java.lang.String encodeForVBScript(java.lang.String input)
IEncoder
encodeForVBScript in interface IEncoderinput - the input
public java.lang.String encodeForSQL(java.lang.String input)
encodeForSQL in interface IEncoderinput - the input
IEncoder.encodeForSQL(java.lang.String)public java.lang.String encodeForLDAP(java.lang.String input)
IEncoder
encodeForLDAP in interface IEncoderinput - the input
public java.lang.String encodeForDN(java.lang.String input)
IEncoder
encodeForDN in interface IEncoderinput - the input
public java.lang.String encodeForXPath(java.lang.String input)
encodeForXPath in interface IEncoderinput - the input
IEncoder.encodeForXPath(java.lang.String)public java.lang.String encodeForXML(java.lang.String input)
IEncoderThe use of a real XML parser is strongly encouraged. However, in the hopefully rare case that you need to make sure that data is safe for inclusion in an XML document and cannot use a parse, this method provides a safe mechanism to do so.
encodeForXML in interface IEncoderinput - the input
public java.lang.String encodeForXMLAttribute(java.lang.String input)
IEncoderThe use of a real XML parser is highly encouraged. However, in the hopefully rare case that you need to make sure that data is safe for inclusion in an XML document and cannot use a parse, this method provides a safe mechanism to do so.
encodeForXMLAttribute in interface IEncoderinput - the input
public java.lang.String encodeForURL(java.lang.String input)
throws EncodingException
IEncoder
encodeForURL in interface IEncoderinput - the input
EncodingException
public java.lang.String decodeFromURL(java.lang.String input)
throws EncodingException
IEncoder
decodeFromURL in interface IEncoderinput - the input
EncodingException
public java.lang.String encodeForBase64(byte[] input,
boolean wrap)
IEncoderBeware double-encoding, as this will corrupt the results and could possibly cause a downstream security mechansim to make a mistake.
encodeForBase64 in interface IEncoderinput - the input
public byte[] decodeFromBase64(java.lang.String input)
throws java.io.IOException
IEncoderBeware double-encoded data, as the results of this method could still contain encoded characters as part of attacks.
decodeFromBase64 in interface IEncoderinput - the input
java.io.IOException - Signals that an I/O exception has occurred.public static void main(java.lang.String[] args)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||