|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.owasp.esapi.reference.DefaultValidator
Reference implementation of the IValidator interface. This implementation relies on the ESAPI Encoder, Java Pattern (regex), Date, and several other classes to provide basic validation functions. This library has a heavy emphasis on whitelist validation and canonicalization. All double-encoded characters, even in multiple encoding schemes, such as
<or
%26lt;or even%25%26lt;are disallowed.
Validator| Constructor Summary | |
DefaultValidator()
|
|
| Method Summary | |
void |
assertIsValidHTTPRequest()
Validates the current HTTP request by comparing parameters, headers, and cookies to a predefined whitelist of allowed characters. |
void |
assertIsValidHTTPRequest(javax.servlet.http.HttpServletRequest request)
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 directorypath,
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 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)
Validates data received from the browser and returns a safe version. |
java.lang.Integer |
getValidInteger(java.lang.String context,
java.lang.String input,
int minValue,
int maxValue,
boolean allowNull)
Returns a validated number as a double. |
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 the directory path (not including a filename) is valid. |
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 directorypath,
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()
Validates the current HTTP request by comparing parameters, headers, and cookies to a predefined whitelist of allowed characters. |
boolean |
isValidHTTPRequest(javax.servlet.http.HttpServletRequest request)
Validates 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 requiredNames,
java.util.Set optionalNames)
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 data received from browser is valid. |
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)
Checks that all bytes are valid ASCII characters (between 33 and 126 inclusive). |
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 in,
int max)
This implementation reads until a newline or the specified number of characters. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public DefaultValidator()
| Method Detail |
public boolean isValidInput(java.lang.String context,
java.lang.String input,
java.lang.String type,
int maxLength,
boolean allowNull)
throws IntrusionException
isValidInput in interface Validatorcontext - 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
getValidInput in interface Validatorcontext - 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
isValidDate in interface ValidatorIntrusionException
public java.util.Date getValidDate(java.lang.String context,
java.lang.String input,
java.text.DateFormat format,
boolean allowNull)
throws ValidationException,
IntrusionException
Validator
getValidDate in interface ValidatorValidationException
IntrusionException
public boolean isValidSafeHTML(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
throws IntrusionException
Validator
isValidSafeHTML in interface ValidatorIntrusionException
public java.lang.String getValidSafeHTML(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
throws ValidationException,
IntrusionException
Validator
getValidSafeHTML in interface ValidatorValidationException
IntrusionException
public boolean isValidCreditCard(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws IntrusionException
Validator
isValidCreditCard in interface ValidatorIntrusionException
public java.lang.String getValidCreditCard(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidCreditCard in interface ValidatorValidationException
IntrusionException
public boolean isValidDirectoryPath(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws IntrusionException
isValidDirectoryPath in interface ValidatorIntrusionExceptionorg.owasp.esapi.Validator#isValidDirectoryPath(java.lang.String)
public java.lang.String getValidDirectoryPath(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidDirectoryPath in interface ValidatorValidationException
IntrusionException
public boolean isValidFileName(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws IntrusionException
isValidFileName in interface ValidatorIntrusionException
public java.lang.String getValidFileName(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidFileName in interface ValidatorValidationException
IntrusionException
public boolean isValidNumber(java.lang.String context,
java.lang.String input,
long minValue,
long maxValue,
boolean allowNull)
throws IntrusionException
Validator
isValidNumber in interface ValidatorIntrusionException
public java.lang.Double getValidNumber(java.lang.String context,
java.lang.String input,
long minValue,
long maxValue,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidNumber in interface ValidatorValidationException
IntrusionException
public boolean isValidDouble(java.lang.String context,
java.lang.String input,
double minValue,
double maxValue,
boolean allowNull)
throws IntrusionException
Validator
isValidDouble in interface ValidatorIntrusionException
public java.lang.Double getValidDouble(java.lang.String context,
java.lang.String input,
double minValue,
double maxValue,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidDouble in interface ValidatorValidationException
IntrusionException
public boolean isValidInteger(java.lang.String context,
java.lang.String input,
int minValue,
int maxValue,
boolean allowNull)
throws IntrusionException
Validator
isValidInteger in interface ValidatorIntrusionException
public java.lang.Integer getValidInteger(java.lang.String context,
java.lang.String input,
int minValue,
int maxValue,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidInteger in interface ValidatorValidationException
IntrusionException
public boolean isValidFileContent(java.lang.String context,
byte[] input,
int maxBytes,
boolean allowNull)
throws IntrusionException
isValidFileContent in interface ValidatorIntrusionException
public byte[] getValidFileContent(java.lang.String context,
byte[] input,
int maxBytes,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidFileContent in interface ValidatorValidationException
IntrusionException
public boolean isValidFileUpload(java.lang.String context,
java.lang.String directorypath,
java.lang.String filename,
byte[] content,
int maxBytes,
boolean allowNull)
throws IntrusionException
isValidFileUpload in interface ValidatorIntrusionException
public void assertValidFileUpload(java.lang.String context,
java.lang.String directorypath,
java.lang.String filename,
byte[] content,
int maxBytes,
boolean allowNull)
throws ValidationException,
IntrusionException
assertValidFileUpload in interface ValidatorValidationException
IntrusionException
public boolean isValidHTTPRequest()
throws IntrusionException
isValidHTTPRequest in interface ValidatorIntrusionException
public boolean isValidHTTPRequest(javax.servlet.http.HttpServletRequest request)
throws IntrusionException
IntrusionException
public void assertIsValidHTTPRequest()
throws ValidationException,
IntrusionException
assertIsValidHTTPRequest in interface ValidatorValidationException
IntrusionException
public void assertIsValidHTTPRequest(javax.servlet.http.HttpServletRequest request)
throws ValidationException,
IntrusionException
ValidationException
IntrusionException
public boolean isValidListItem(java.lang.String context,
java.lang.String input,
java.util.List list)
Validator
isValidListItem in interface Validator
public java.lang.String getValidListItem(java.lang.String context,
java.lang.String input,
java.util.List list)
throws ValidationException,
IntrusionException
getValidListItem in interface ValidatorValidationException
IntrusionException
public boolean isValidHTTPRequestParameterSet(java.lang.String context,
java.util.Set requiredNames,
java.util.Set optionalNames)
Validator
isValidHTTPRequestParameterSet in interface Validator
public void assertIsValidHTTPRequestParameterSet(java.lang.String context,
java.util.Set required,
java.util.Set optional)
throws ValidationException,
IntrusionException
assertIsValidHTTPRequestParameterSet in interface ValidatorValidationException
IntrusionException
public boolean isValidPrintable(java.lang.String context,
byte[] input,
int maxLength,
boolean allowNull)
throws IntrusionException
isValidPrintable in interface ValidatorIntrusionExceptionorg.owasp.esapi.Validator#isValidASCIIFileContent(byte[])
public byte[] getValidPrintable(java.lang.String context,
byte[] input,
int maxLength,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidPrintable in interface ValidatorValidationException
IntrusionException
public boolean isValidPrintable(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
throws IntrusionException
Validator
isValidPrintable in interface ValidatorIntrusionException
public java.lang.String getValidPrintable(java.lang.String context,
java.lang.String input,
int maxLength,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidPrintable in interface ValidatorValidationException
IntrusionException
public boolean isValidRedirectLocation(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws IntrusionException
isValidRedirectLocation in interface ValidatorIntrusionException
public java.lang.String getValidRedirectLocation(java.lang.String context,
java.lang.String input,
boolean allowNull)
throws ValidationException,
IntrusionException
getValidRedirectLocation in interface ValidatorValidationException
IntrusionException
public java.lang.String safeReadLine(java.io.InputStream in,
int max)
throws ValidationException
safeReadLine in interface Validatorin - the inmax - the max
ValidationException - the validation exceptionValidator.safeReadLine(java.io.InputStream,
int)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||