|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
The IValidator interface defines a set of methods for canonicalizing and validating untrusted input. Implementors should feel free to extend this interface to accomodate their own data formats. Rather than throw exceptions, this interface returns boolean results because not all validation problems are security issues. Boolean returns allow developers to handle both valid and invalid results more cleanly than exceptions.
Implementations must adopt a "whitelist" approach to validation where a specific pattern or character set is matched. "Blacklist" approaches that attempt to identify the invalid or disallowed characters are much more likely to allow a bypass with encoding or other tricks.
| Method Summary | |
void |
assertIsValidHTTPRequest()
Validates the current HTTP request by comparing parameters, headers, and cookies to a predefined whitelist of allowed characters. |
void |
assertIsValidHTTPRequestParameterSet(java.lang.String context,
java.util.Set required,
java.util.Set optional)
Validates that the parameters in the current request contain all required parameters and only optional ones in addition. |
void |
assertValidFileUpload(java.lang.String context,
java.lang.String filepath,
java.lang.String filename,
byte[] content,
int maxBytes,
boolean allowNull)
Validates the filepath, filename, and content of a file. |
java.lang.String |
getValidCreditCard(java.lang.String context,
java.lang.String input,
boolean allowNull)
Returns a canonicalized and validated credit card number as a String. |
java.util.Date |
getValidDate(java.lang.String context,
java.lang.String input,
java.text.DateFormat format,
boolean allowNull)
Returns a valid date as a Date. |
java.lang.String |
getValidDirectoryPath(java.lang.String context,
java.lang.String input,
boolean allowNull)
Returns a canonicalized and validated directory path as a String. |
java.lang.Double |
getValidDouble(java.lang.String context,
java.lang.String input,
double minValue,
double maxValue,
boolean allowNull)
Returns a validated real number as a double. |
byte[] |
getValidFileContent(java.lang.String context,
byte[] input,
int maxBytes,
boolean allowNull)
Returns validated file content as a byte array. |
java.lang.String |
getValidFileName(java.lang.String context,
java.lang.String input,
boolean allowNull)
Returns a canonicalized and validated file name as a String. |
java.lang.String |
getValidInput(java.lang.String context,
java.lang.String input,
java.lang.String type,
int maxLength,
boolean allowNull)
Returns canonicalized and validated input as a String. |
java.lang.Integer |
getValidInteger(java.lang.String context,
java.lang.String input,
int minValue,
int maxValue,
boolean allowNull)
Returns a validated integer as an int. |
java.lang.String |
getValidListItem(java.lang.String context,
java.lang.String input,
java.util.List list)
Returns the list item that exactly matches the canonicalized input. |
java.lang.Double |
getValidNumber(java.lang.String context,
java.lang.String input,
long minValue,
long maxValue,
boolean allowNull)
Returns a validated number as a double. |
byte[] |
getValidPrintable(java.lang.String context,
byte[] input,
int maxLength,
boolean allowNull)
Returns canonicalized and validated printable characters as a byte array. |
java.lang.String |
getValidPrintable(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
Returns canonicalized and validated printable characters as a String. |
java.lang.String |
getValidRedirectLocation(java.lang.String context,
java.lang.String input,
boolean allowNull)
Returns a canonicalized and validated redirect location as a String. |
java.lang.String |
getValidSafeHTML(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
Returns canonicalized and validated "safe" HTML. |
boolean |
isValidCreditCard(java.lang.String context,
java.lang.String input,
boolean allowNull)
Returns true if input is a valid credit card. |
boolean |
isValidDate(java.lang.String context,
java.lang.String input,
java.text.DateFormat format,
boolean allowNull)
Returns true if input is a valid date according to the specified date format. |
boolean |
isValidDirectoryPath(java.lang.String context,
java.lang.String input,
boolean allowNull)
Returns true if input is a valid directory path. |
boolean |
isValidDouble(java.lang.String context,
java.lang.String input,
double minValue,
double maxValue,
boolean allowNull)
Returns true if input is a valid double. |
boolean |
isValidFileContent(java.lang.String context,
byte[] input,
int maxBytes,
boolean allowNull)
Returns true if input is valid file content. |
boolean |
isValidFileName(java.lang.String context,
java.lang.String input,
boolean allowNull)
Returns true if input is a valid file name. |
boolean |
isValidFileUpload(java.lang.String context,
java.lang.String filepath,
java.lang.String filename,
byte[] content,
int maxBytes,
boolean allowNull)
Returns true if a file upload has a valid name, path, and content. |
boolean |
isValidHTTPRequest()
Validate the current HTTP request by comparing parameters, headers, and cookies to a predefined whitelist of allowed characters. |
boolean |
isValidHTTPRequestParameterSet(java.lang.String context,
java.util.Set required,
java.util.Set optional)
Returns true if the parameters in the current request contain all required parameters and only optional ones in addition. |
boolean |
isValidInput(java.lang.String context,
java.lang.String input,
java.lang.String type,
int maxLength,
boolean allowNull)
Returns true if input is valid according to the specified type. |
boolean |
isValidInteger(java.lang.String context,
java.lang.String input,
int minValue,
int maxValue,
boolean allowNull)
Returns true if input is a valid integer. |
boolean |
isValidListItem(java.lang.String context,
java.lang.String input,
java.util.List list)
Returns true if input is a valid list item. |
boolean |
isValidNumber(java.lang.String context,
java.lang.String input,
long minValue,
long maxValue,
boolean allowNull)
Returns true if input is a valid number. |
boolean |
isValidPrintable(java.lang.String context,
byte[] input,
int maxLength,
boolean allowNull)
Returns true if input is valid printable ASCII characters. |
boolean |
isValidPrintable(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
Returns true if input is valid printable ASCII characters (32-126). |
boolean |
isValidRedirectLocation(java.lang.String context,
java.lang.String input,
boolean allowNull)
Returns true if input is a valid redirect location. |
boolean |
isValidSafeHTML(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
Returns true if input is "safe" HTML. |
java.lang.String |
safeReadLine(java.io.InputStream inputStream,
int maxLength)
Reads from an input stream until end-of-line or a maximum number of characters. |
| Method Detail |
public boolean isValidInput(java.lang.String context,
java.lang.String input,
java.lang.String type,
int maxLength,
boolean allowNull)
throws IntrusionException
context - A descriptive name for the field to validate. This is used for error facing validation messages and element identification.input - The actual user input data to validate.type - The regular expression name while maps to the actual regular expression from "ESAPI.properties".maxLength - The maximum post-canonicalized String length allowed.allowNull - If allowNull is true then a input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.
IntrusionException
public java.lang.String getValidInput(java.lang.String context,
java.lang.String input,
java.lang.String type,
int maxLength,
boolean allowNull)
throws ValidationException,
IntrusionException
context - A descriptive name for the field to validate. This is used for error facing validation messages and element identification.input - The actual user input data to validate.type - The regular expression name while maps to the actual regular expression from "ESAPI.properties".maxLength - The maximum post-canonicalized String length allowed.allowNull - If allowNull is true then a input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.
ValidationException
IntrusionException
public boolean isValidDate(java.lang.String context,
java.lang.String input,
java.text.DateFormat format,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.util.Date getValidDate(java.lang.String context,
java.lang.String input,
java.text.DateFormat format,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidSafeHTML(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.String getValidSafeHTML(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
throws ValidationException
ValidationException
public boolean isValidCreditCard(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.String getValidCreditCard(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidDirectoryPath(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.String getValidDirectoryPath(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidFileName(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.String getValidFileName(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidNumber(java.lang.String context,
java.lang.String input,
long minValue,
long maxValue,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.Double getValidNumber(java.lang.String context,
java.lang.String input,
long minValue,
long maxValue,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidInteger(java.lang.String context,
java.lang.String input,
int minValue,
int maxValue,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.Integer getValidInteger(java.lang.String context,
java.lang.String input,
int minValue,
int maxValue,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidDouble(java.lang.String context,
java.lang.String input,
double minValue,
double maxValue,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.Double getValidDouble(java.lang.String context,
java.lang.String input,
double minValue,
double maxValue,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidFileContent(java.lang.String context,
byte[] input,
int maxBytes,
boolean allowNull)
throws IntrusionException
IntrusionException
public byte[] getValidFileContent(java.lang.String context,
byte[] input,
int maxBytes,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidFileUpload(java.lang.String context,
java.lang.String filepath,
java.lang.String filename,
byte[] content,
int maxBytes,
boolean allowNull)
throws IntrusionException
IntrusionException
public void assertValidFileUpload(java.lang.String context,
java.lang.String filepath,
java.lang.String filename,
byte[] content,
int maxBytes,
boolean allowNull)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidHTTPRequest()
throws IntrusionException
IntrusionException
public void assertIsValidHTTPRequest()
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidListItem(java.lang.String context,
java.lang.String input,
java.util.List list)
throws IntrusionException
IntrusionException
public java.lang.String getValidListItem(java.lang.String context,
java.lang.String input,
java.util.List list)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidHTTPRequestParameterSet(java.lang.String context,
java.util.Set required,
java.util.Set optional)
throws IntrusionException
IntrusionException
public void assertIsValidHTTPRequestParameterSet(java.lang.String context,
java.util.Set required,
java.util.Set optional)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidPrintable(java.lang.String context,
byte[] input,
int maxLength,
boolean allowNull)
throws IntrusionException
IntrusionException
public byte[] getValidPrintable(java.lang.String context,
byte[] input,
int maxLength,
boolean allowNull)
throws ValidationException
ValidationException
public boolean isValidPrintable(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.String getValidPrintable(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
throws ValidationException
ValidationException
public boolean isValidRedirectLocation(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws IntrusionException
IntrusionException
public java.lang.String getValidRedirectLocation(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws ValidationException
ValidationException
public java.lang.String safeReadLine(java.io.InputStream inputStream,
int maxLength)
throws ValidationException
ValidationException
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||