Class DefaultValidator
- java.lang.Object
-
- org.owasp.esapi.reference.DefaultValidator
-
- All Implemented Interfaces:
Validator
public class DefaultValidator extends java.lang.Object implements Validator
Reference implementation of the Validator 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.- Since:
- June 1, 2007
- Author:
- Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security, Jim Manico (jim@manico.net) Manico.net, Matt Seil (mseil .at. acm.org)
- See Also:
Validator
-
-
Constructor Summary
Constructors Constructor Description DefaultValidator()Default constructor uses the ESAPI standard encoder for canonicalization.DefaultValidator(Encoder encoder)Construct a new DefaultValidator that will use the specified Encoder for canonicalization.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRule(ValidationRule rule)Add a validation rule to the registry using the "type name" of the rule as the key.voidassertValidFileUpload(java.lang.String context, java.lang.String directorypath, java.lang.String filename, java.io.File parent, byte[] content, int maxBytes, java.util.List<java.lang.String> allowedExtensions, boolean allowNull)Validates the filepath, filename, and content of a file.voidassertValidFileUpload(java.lang.String context, java.lang.String filepath, java.lang.String filename, java.io.File parent, byte[] content, int maxBytes, java.util.List<java.lang.String> allowedExtensions, boolean allowNull, ValidationErrorList errors)Calls getValidFileUpload with the supplied errorList to capture ValidationExceptionsvoidassertValidHTTPRequestParameterSet(java.lang.String context, javax.servlet.http.HttpServletRequest request, java.util.Set<java.lang.String> required, java.util.Set<java.lang.String> optional)Validates that the parameters in the current request contain all required parameters and only optional ones in addition.voidassertValidHTTPRequestParameterSet(java.lang.String context, javax.servlet.http.HttpServletRequest request, java.util.Set<java.lang.String> required, java.util.Set<java.lang.String> optional, ValidationErrorList errors)ValidationErrorList variant of assertIsValidHTTPRequestParameterSet Uses current HTTPRequest saved in ESAPI Authenticatorstatic ValidatorgetInstance()java.net.URIgetRfcCompliantURI(java.lang.String input)Will return aURIobject that will represent a fully parsed and legal URI as specified in RFC-3986.ValidationRulegetRule(java.lang.String name)Get a validation rule from the registry with the "type name" of the rule as the key.java.lang.StringgetValidCreditCard(java.lang.String context, java.lang.String input, boolean allowNull)Returns a canonicalized and validated credit card number as a String.java.lang.StringgetValidCreditCard(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors)Calls getValidCreditCard with the supplied errorList to capture ValidationExceptionsjava.util.DategetValidDate(java.lang.String context, java.lang.String input, java.text.DateFormat format, boolean allowNull)Returns a valid date as a Date.java.util.DategetValidDate(java.lang.String context, java.lang.String input, java.text.DateFormat format, boolean allowNull, ValidationErrorList errors)Calls getValidDate with the supplied errorList to capture ValidationExceptionsjava.lang.StringgetValidDirectoryPath(java.lang.String context, java.lang.String input, java.io.File parent, boolean allowNull)Returns a canonicalized and validated directory path as a String, provided that the input maps to an existing directory that is an existing subdirectory (at any level) of the specified parent.java.lang.StringgetValidDirectoryPath(java.lang.String context, java.lang.String input, java.io.File parent, boolean allowNull, ValidationErrorList errors)Calls getValidDirectoryPath with the supplied errorList to capture ValidationExceptionsjava.lang.DoublegetValidDouble(java.lang.String context, java.lang.String input, double minValue, double maxValue, boolean allowNull)Returns a validated real number as a double.java.lang.DoublegetValidDouble(java.lang.String context, java.lang.String input, double minValue, double maxValue, boolean allowNull, ValidationErrorList errors)Calls getValidDouble with the supplied errorList to capture ValidationExceptionsbyte[]getValidFileContent(java.lang.String context, byte[] input, int maxBytes, boolean allowNull)Returns validated file content as a byte array.byte[]getValidFileContent(java.lang.String context, byte[] input, int maxBytes, boolean allowNull, ValidationErrorList errors)Calls getValidFileContent with the supplied errorList to capture ValidationExceptionsjava.lang.StringgetValidFileName(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> allowedExtensions, boolean allowNull)Returns a canonicalized and validated file name as a String.java.lang.StringgetValidFileName(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> allowedParameters, boolean allowNull, ValidationErrorList errors)Calls getValidFileName with the supplied errorList to capture ValidationExceptionsjava.lang.StringgetValidInput(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.StringgetValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, boolean canonicalize)Validates data received from the browser and returns a safe version.java.lang.StringgetValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, boolean canonicalize, ValidationErrorList errors)Validates data received from the browser and returns a safe version.java.lang.StringgetValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, ValidationErrorList errors)Validates data received from the browser and returns a safe version.java.lang.IntegergetValidInteger(java.lang.String context, java.lang.String input, int minValue, int maxValue, boolean allowNull)Returns a validated integer.java.lang.IntegergetValidInteger(java.lang.String context, java.lang.String input, int minValue, int maxValue, boolean allowNull, ValidationErrorList errors)Calls getValidInteger with the supplied errorList to capture ValidationExceptionsjava.lang.StringgetValidListItem(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> list)Returns the list item that exactly matches the canonicalized input.java.lang.StringgetValidListItem(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> list, ValidationErrorList errors)ValidationErrorList variant of getValidListItemjava.lang.DoublegetValidNumber(java.lang.String context, java.lang.String input, long minValue, long maxValue, boolean allowNull)Returns a validated number as a double within the range of minValue to maxValue.java.lang.DoublegetValidNumber(java.lang.String context, java.lang.String input, long minValue, long maxValue, boolean allowNull, ValidationErrorList errors)Calls getValidSafeHTML with the supplied errorList to capture ValidationExceptionschar[]getValidPrintable(java.lang.String context, char[] input, int maxLength, boolean allowNull)Returns canonicalized and validated printable characters as a byte array.char[]getValidPrintable(java.lang.String context, char[] input, int maxLength, boolean allowNull, ValidationErrorList errors)ValidationErrorList variant of getValidPrintablejava.lang.StringgetValidPrintable(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull)Returns canonicalized and validated printable characters as a String.java.lang.StringgetValidPrintable(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull, ValidationErrorList errors)ValidationErrorList variant of getValidPrintablejava.lang.StringgetValidRedirectLocation(java.lang.String context, java.lang.String input, boolean allowNull)Returns a canonicalized and validated redirect location as a String.java.lang.StringgetValidRedirectLocation(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors)ValidationErrorList variant of getValidRedirectLocationjava.lang.StringgetValidSafeHTML(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull)Returns canonicalized and validated "safe" HTML that does not contain unwanted scripts in the body, attributes, CSS, URLs, or anywhere else.java.lang.StringgetValidSafeHTML(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull, ValidationErrorList errors)Calls getValidSafeHTML with the supplied errorList to capture ValidationExceptionsbooleanisValidCreditCard(java.lang.String context, java.lang.String input, boolean allowNull)Calls getValidCreditCard and returns true if no exceptions are thrown.booleanisValidCreditCard(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors)Calls getValidCreditCard and returns true if no exceptions are thrown.booleanisValidDate(java.lang.String context, java.lang.String input, java.text.DateFormat format, boolean allowNull)Calls isValidDate and returns true if no exceptions are thrown.booleanisValidDate(java.lang.String context, java.lang.String input, java.text.DateFormat format, boolean allowNull, ValidationErrorList errors)Calls isValidDate and returns true if no exceptions are thrown.booleanisValidDirectoryPath(java.lang.String context, java.lang.String input, java.io.File parent, boolean allowNull)Calls getValidDirectoryPath and returns true if no exceptions are thrown.booleanisValidDirectoryPath(java.lang.String context, java.lang.String input, java.io.File parent, boolean allowNull, ValidationErrorList errors)Calls getValidDirectoryPath and returns true if no exceptions are thrown.booleanisValidDouble(java.lang.String context, java.lang.String input, double minValue, double maxValue, boolean allowNull)Calls getValidDouble and returns true if no exceptions are thrown.booleanisValidDouble(java.lang.String context, java.lang.String input, double minValue, double maxValue, boolean allowNull, ValidationErrorList errors)Calls getValidDouble and returns true if no exceptions are thrown.booleanisValidFileContent(java.lang.String context, byte[] input, int maxBytes, boolean allowNull)Calls getValidFileContent and returns true if no exceptions are thrown.booleanisValidFileContent(java.lang.String context, byte[] input, int maxBytes, boolean allowNull, ValidationErrorList errors)Calls getValidFileContent and returns true if no exceptions are thrown.booleanisValidFileName(java.lang.String context, java.lang.String input, boolean allowNull)Calls getValidFileName with the default list of allowedExtensionsbooleanisValidFileName(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors)Calls getValidFileName with the default list of allowedExtensionsbooleanisValidFileName(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> allowedExtensions, boolean allowNull)Calls getValidFileName and returns true if no exceptions are thrown.booleanisValidFileName(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> allowedExtensions, boolean allowNull, ValidationErrorList errors)Calls getValidFileName and returns true if no exceptions are thrown.booleanisValidFileUpload(java.lang.String context, java.lang.String directorypath, java.lang.String filename, java.io.File parent, byte[] content, int maxBytes, boolean allowNull)Calls getValidFileUpload and returns true if no exceptions are thrown.booleanisValidFileUpload(java.lang.String context, java.lang.String directorypath, java.lang.String filename, java.io.File parent, byte[] content, int maxBytes, boolean allowNull, ValidationErrorList errors)Calls getValidFileUpload and returns true if no exceptions are thrown.booleanisValidHTTPRequestParameterSet(java.lang.String context, javax.servlet.http.HttpServletRequest request, java.util.Set<java.lang.String> requiredNames, java.util.Set<java.lang.String> optionalNames)Calls assertValidHTTPRequestParameterSet and returns true if no exceptions are thrown.booleanisValidHTTPRequestParameterSet(java.lang.String context, javax.servlet.http.HttpServletRequest request, java.util.Set<java.lang.String> requiredNames, java.util.Set<java.lang.String> optionalNames, ValidationErrorList errors)Calls assertValidHTTPRequestParameterSet and returns true if no exceptions are thrown.booleanisValidInput(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.booleanisValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, boolean canonicalize)Calls isValidInput and returns true if no exceptions are thrown.booleanisValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, boolean canonicalize, ValidationErrorList errors)Calls isValidInput and returns true if no exceptions are thrown.booleanisValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, ValidationErrorList errors)Calls isValidInput and returns true if no exceptions are thrown.booleanisValidInteger(java.lang.String context, java.lang.String input, int minValue, int maxValue, boolean allowNull)Calls getValidInteger and returns true if no exceptions are thrown.booleanisValidInteger(java.lang.String context, java.lang.String input, int minValue, int maxValue, boolean allowNull, ValidationErrorList errors)Calls getValidInteger and returns true if no exceptions are thrown.booleanisValidListItem(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> list)Calls getValidListItem and returns true if no exceptions are thrown.booleanisValidListItem(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> list, ValidationErrorList errors)Calls getValidListItem and returns true if no exceptions are thrown.booleanisValidNumber(java.lang.String context, java.lang.String input, long minValue, long maxValue, boolean allowNull)Calls getValidNumber and returns true if no exceptions are thrown.booleanisValidNumber(java.lang.String context, java.lang.String input, long minValue, long maxValue, boolean allowNull, ValidationErrorList errors)Calls getValidNumber and returns true if no exceptions are thrown.booleanisValidPrintable(java.lang.String context, char[] input, int maxLength, boolean allowNull)Calls getValidPrintable and returns true if no exceptions are thrown.booleanisValidPrintable(java.lang.String context, char[] input, int maxLength, boolean allowNull, ValidationErrorList errors)Calls getValidPrintable and returns true if no exceptions are thrown.booleanisValidPrintable(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull)Calls getValidPrintable and returns true if no exceptions are thrown.booleanisValidPrintable(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull, ValidationErrorList errors)Calls getValidPrintable and returns true if no exceptions are thrown.booleanisValidRedirectLocation(java.lang.String context, java.lang.String input, boolean allowNull)Returns true if input is a valid redirect location.booleanisValidRedirectLocation(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors)Returns true if input is a valid redirect location.booleanisValidSafeHTML(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull)Calls getValidSafeHTML and returns true if no exceptions are thrown.booleanisValidSafeHTML(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull, ValidationErrorList errors)Calls getValidSafeHTML and returns true if no exceptions are thrown.booleanisValidURI(java.lang.String context, java.lang.String input, boolean allowNull)Parses and ensures that the URI in question is a valid RFC-3986 URI.java.lang.StringsafeReadLine(java.io.InputStream in, int max)Reads from an input stream until end-of-line or a maximum number of characters.
-
-
-
Constructor Detail
-
DefaultValidator
public DefaultValidator()
Default constructor uses the ESAPI standard encoder for canonicalization.
-
DefaultValidator
public DefaultValidator(Encoder encoder)
Construct a new DefaultValidator that will use the specified Encoder for canonicalization.- Parameters:
encoder-
-
-
Method Detail
-
getInstance
public static Validator getInstance()
-
addRule
public void addRule(ValidationRule rule)
Add a validation rule to the registry using the "type name" of the rule as the key.
-
getRule
public ValidationRule getRule(java.lang.String name)
Get a validation rule from the registry with the "type name" of the rule as the key.
-
isValidInput
public boolean isValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull) throws IntrusionExceptionReturns true if data received from browser is valid. Double encoding is treated as an attack. The default encoder supports html encoding, URL encoding, and javascript escaping. Input is canonicalized by default before validation.- Specified by:
isValidInputin interfaceValidator- Parameters:
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.- Returns:
- The canonicalized user input.
- Throws:
IntrusionException
-
isValidInput
public boolean isValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionDescription copied from interface:ValidatorCalls isValidInput and returns true if no exceptions are thrown.- Specified by:
isValidInputin interfaceValidator- Throws:
IntrusionException
-
isValidInput
public boolean isValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, boolean canonicalize) throws IntrusionExceptionDescription copied from interface:ValidatorCalls isValidInput and returns true if no exceptions are thrown.- Specified by:
isValidInputin interfaceValidator- Throws:
IntrusionException
-
isValidInput
public boolean isValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, boolean canonicalize, ValidationErrorList errors) throws IntrusionExceptionDescription copied from interface:ValidatorCalls isValidInput and returns true if no exceptions are thrown.- Specified by:
isValidInputin interfaceValidator- Throws:
IntrusionException
-
getValidInput
public java.lang.String getValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull) throws ValidationExceptionValidates data received from the browser and returns a safe version. Double encoding is treated as an attack. The default encoder supports html encoding, URL encoding, and javascript escaping. Input is canonicalized by default before validation.- Specified by:
getValidInputin interfaceValidator- Parameters:
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 which 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.- Returns:
- The canonicalized user input.
- Throws:
ValidationExceptionIntrusionException
-
getValidInput
public java.lang.String getValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, boolean canonicalize) throws ValidationExceptionValidates data received from the browser and returns a safe version. Only URL encoding is supported. Double encoding is treated as an attack.- Specified by:
getValidInputin interfaceValidator- Parameters:
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 which maps to the actual regular expression in the ESAPI validation configuration filemaxLength- The maximum String length allowed. If input is canonicalized per the canonicalize argument, then maxLength must be verified after canonicalizationallowNull- 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.canonicalize- If canonicalize is true then input will be canonicalized before validation- Returns:
- The user input, may be canonicalized if canonicalize argument is true
- Throws:
ValidationExceptionIntrusionException
-
getValidInput
public java.lang.String getValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionValidates data received from the browser and returns a safe version. Only URL encoding is supported. Double encoding is treated as an attack. Input is canonicalized by default before validation.- Specified by:
getValidInputin interfaceValidator- Parameters:
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 String length allowed. If input is canonicalized per the canonicalize argument, then maxLength must be verified after canonicalizationallowNull- 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.errors- If ValidationException is thrown, then add to error list instead of throwing out to caller- Returns:
- The canonicalized user input.
- Throws:
IntrusionException
-
getValidInput
public java.lang.String getValidInput(java.lang.String context, java.lang.String input, java.lang.String type, int maxLength, boolean allowNull, boolean canonicalize, ValidationErrorList errors) throws IntrusionExceptionValidates data received from the browser and returns a safe version. Only URL encoding is supported. Double encoding is treated as an attack.- Specified by:
getValidInputin interfaceValidator- Parameters:
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 allowedallowNull- 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.canonicalize- If canonicalize is true then input will be canonicalized before validationerrors- If ValidationException is thrown, then add to error list instead of throwing out to caller- Returns:
- The user input, may be canonicalized if canonicalize argument is true
- Throws:
IntrusionException
-
isValidDate
public boolean isValidDate(java.lang.String context, java.lang.String input, java.text.DateFormat format, boolean allowNull) throws IntrusionExceptionCalls isValidDate and returns true if no exceptions are thrown.- Specified by:
isValidDatein interfaceValidator- Throws:
IntrusionException
-
isValidDate
public boolean isValidDate(java.lang.String context, java.lang.String input, java.text.DateFormat format, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls isValidDate and returns true if no exceptions are thrown.- Specified by:
isValidDatein interfaceValidator- Throws:
IntrusionException
-
getValidDate
public java.util.Date getValidDate(java.lang.String context, java.lang.String input, java.text.DateFormat format, boolean allowNull) throws ValidationException, IntrusionExceptionReturns a valid date as a Date. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidDatein interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual user input data to validate.format- Required formatting of date inputted.allowNull- If allowNull is true then an 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.- Returns:
- A valid date as a Date
- Throws:
ValidationExceptionIntrusionException
-
getValidDate
public java.util.Date getValidDate(java.lang.String context, java.lang.String input, java.text.DateFormat format, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidDate with the supplied errorList to capture ValidationExceptions- Specified by:
getValidDatein interfaceValidator- Throws:
IntrusionException
-
isValidSafeHTML
public boolean isValidSafeHTML(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull) throws IntrusionExceptionCalls getValidSafeHTML and returns true if no exceptions are thrown.- Specified by:
isValidSafeHTMLin interfaceValidator- Throws:
IntrusionException
-
isValidSafeHTML
public boolean isValidSafeHTML(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidSafeHTML and returns true if no exceptions are thrown.- Specified by:
isValidSafeHTMLin interfaceValidator- Throws:
IntrusionException
-
getValidSafeHTML
public java.lang.String getValidSafeHTML(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull) throws ValidationException, IntrusionExceptionReturns canonicalized and validated "safe" HTML that does not contain unwanted scripts in the body, attributes, CSS, URLs, or anywhere else. Implementors should reference the OWASP AntiSamy project for ideas on how to do HTML validation in a whitelist way, as this is an extremely difficult problem. This implementation relies on the OWASP AntiSamy project.- Specified by:
getValidSafeHTMLin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual user input data to validate.maxLength- The maximum String length allowed.allowNull- If allowNull is true then an 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.- Returns:
- Valid safe HTML
- Throws:
ValidationExceptionIntrusionException
-
getValidSafeHTML
public java.lang.String getValidSafeHTML(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidSafeHTML with the supplied errorList to capture ValidationExceptions- Specified by:
getValidSafeHTMLin interfaceValidator- Throws:
IntrusionException
-
isValidCreditCard
public boolean isValidCreditCard(java.lang.String context, java.lang.String input, boolean allowNull) throws IntrusionExceptionCalls getValidCreditCard and returns true if no exceptions are thrown.- Specified by:
isValidCreditCardin interfaceValidator- Throws:
IntrusionException
-
isValidCreditCard
public boolean isValidCreditCard(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidCreditCard and returns true if no exceptions are thrown.- Specified by:
isValidCreditCardin interfaceValidator- Throws:
IntrusionException
-
getValidCreditCard
public java.lang.String getValidCreditCard(java.lang.String context, java.lang.String input, boolean allowNull) throws ValidationException, IntrusionExceptionReturns a canonicalized and validated credit card number as a String. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidCreditCardin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual user input data to validate.allowNull- If allowNull is true then an 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.- Returns:
- A valid credit card number
- Throws:
ValidationExceptionIntrusionException
-
getValidCreditCard
public java.lang.String getValidCreditCard(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidCreditCard with the supplied errorList to capture ValidationExceptions- Specified by:
getValidCreditCardin interfaceValidator- Throws:
IntrusionException
-
isValidDirectoryPath
public boolean isValidDirectoryPath(java.lang.String context, java.lang.String input, java.io.File parent, boolean allowNull) throws IntrusionExceptionCalls getValidDirectoryPath and returns true if no exceptions are thrown.Note: On platforms that support symlinks, this function will fail canonicalization if directorypath is a symlink. For example, on MacOS X, /etc is actually /private/etc. If you mean to use /etc, use its real path (/private/etc), not the symlink (/etc).
- Specified by:
isValidDirectoryPathin interfaceValidator- Throws:
IntrusionException
-
isValidDirectoryPath
public boolean isValidDirectoryPath(java.lang.String context, java.lang.String input, java.io.File parent, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidDirectoryPath and returns true if no exceptions are thrown.Note: On platforms that support symlinks, this function will fail canonicalization if directorypath is a symlink. For example, on MacOS X, /etc is actually /private/etc. If you mean to use /etc, use its real path (/private/etc), not the symlink (/etc).
- Specified by:
isValidDirectoryPathin interfaceValidator- Throws:
IntrusionException
-
getValidDirectoryPath
public java.lang.String getValidDirectoryPath(java.lang.String context, java.lang.String input, java.io.File parent, boolean allowNull) throws ValidationException, IntrusionExceptionReturns a canonicalized and validated directory path as a String, provided that the input maps to an existing directory that is an existing subdirectory (at any level) of the specified parent. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException. Instead of throwing a ValidationException on error, this variant will store the exception inside of the ValidationErrorList.- Specified by:
getValidDirectoryPathin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual input data to validate.allowNull- If allowNull is true then an 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.- Returns:
- A valid directory path
- Throws:
ValidationExceptionIntrusionException
-
getValidDirectoryPath
public java.lang.String getValidDirectoryPath(java.lang.String context, java.lang.String input, java.io.File parent, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidDirectoryPath with the supplied errorList to capture ValidationExceptions- Specified by:
getValidDirectoryPathin interfaceValidator- Throws:
IntrusionException
-
isValidFileName
public boolean isValidFileName(java.lang.String context, java.lang.String input, boolean allowNull) throws IntrusionExceptionCalls getValidFileName with the default list of allowedExtensions- Specified by:
isValidFileNamein interfaceValidator- Throws:
IntrusionException
-
isValidFileName
public boolean isValidFileName(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidFileName with the default list of allowedExtensions- Specified by:
isValidFileNamein interfaceValidator- Throws:
IntrusionException
-
isValidFileName
public boolean isValidFileName(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> allowedExtensions, boolean allowNull) throws IntrusionExceptionCalls getValidFileName and returns true if no exceptions are thrown.- Specified by:
isValidFileNamein interfaceValidator- Throws:
IntrusionException
-
isValidFileName
public boolean isValidFileName(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> allowedExtensions, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidFileName and returns true if no exceptions are thrown.- Specified by:
isValidFileNamein interfaceValidator- Throws:
IntrusionException
-
getValidFileName
public java.lang.String getValidFileName(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> allowedExtensions, boolean allowNull) throws ValidationException, IntrusionExceptionReturns a canonicalized and validated file name as a String. Implementors should check for allowed file extensions here, as well as allowed file name characters, as declared in "ESAPI.properties". Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidFileNamein interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual input data to validate.allowNull- If allowNull is true then an 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.- Returns:
- A valid file name
- Throws:
ValidationExceptionIntrusionException
-
getValidFileName
public java.lang.String getValidFileName(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> allowedParameters, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidFileName with the supplied errorList to capture ValidationExceptions- Specified by:
getValidFileNamein interfaceValidator- Throws:
IntrusionException
-
isValidNumber
public boolean isValidNumber(java.lang.String context, java.lang.String input, long minValue, long maxValue, boolean allowNull) throws IntrusionExceptionCalls getValidNumber and returns true if no exceptions are thrown.- Specified by:
isValidNumberin interfaceValidator- Throws:
IntrusionException
-
isValidNumber
public boolean isValidNumber(java.lang.String context, java.lang.String input, long minValue, long maxValue, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidNumber and returns true if no exceptions are thrown.- Specified by:
isValidNumberin interfaceValidator- Throws:
IntrusionException
-
getValidNumber
public java.lang.Double getValidNumber(java.lang.String context, java.lang.String input, long minValue, long maxValue, boolean allowNull) throws ValidationException, IntrusionExceptionReturns a validated number as a double within the range of minValue to maxValue. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidNumberin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual input data to validate.minValue- Lowest legal value for input.maxValue- Highest legal value for input.allowNull- If allowNull is true then an 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.- Returns:
- A validated number as a double.
- Throws:
ValidationExceptionIntrusionException
-
getValidNumber
public java.lang.Double getValidNumber(java.lang.String context, java.lang.String input, long minValue, long maxValue, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidSafeHTML with the supplied errorList to capture ValidationExceptions- Specified by:
getValidNumberin interfaceValidator- Throws:
IntrusionException
-
isValidDouble
public boolean isValidDouble(java.lang.String context, java.lang.String input, double minValue, double maxValue, boolean allowNull) throws IntrusionExceptionCalls getValidDouble and returns true if no exceptions are thrown.- Specified by:
isValidDoublein interfaceValidator- Throws:
IntrusionException
-
isValidDouble
public boolean isValidDouble(java.lang.String context, java.lang.String input, double minValue, double maxValue, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidDouble and returns true if no exceptions are thrown.- Specified by:
isValidDoublein interfaceValidator- Throws:
IntrusionException
-
getValidDouble
public java.lang.Double getValidDouble(java.lang.String context, java.lang.String input, double minValue, double maxValue, boolean allowNull) throws ValidationException, IntrusionExceptionReturns a validated real number as a double. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidDoublein interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual input data to validate.minValue- Lowest legal value for input.maxValue- Highest legal value for input.allowNull- If allowNull is true then an 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.- Returns:
- A validated real number as a double.
- Throws:
ValidationExceptionIntrusionException
-
getValidDouble
public java.lang.Double getValidDouble(java.lang.String context, java.lang.String input, double minValue, double maxValue, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidDouble with the supplied errorList to capture ValidationExceptions- Specified by:
getValidDoublein interfaceValidator- Throws:
IntrusionException
-
isValidInteger
public boolean isValidInteger(java.lang.String context, java.lang.String input, int minValue, int maxValue, boolean allowNull) throws IntrusionExceptionCalls getValidInteger and returns true if no exceptions are thrown.- Specified by:
isValidIntegerin interfaceValidator- Throws:
IntrusionException
-
isValidInteger
public boolean isValidInteger(java.lang.String context, java.lang.String input, int minValue, int maxValue, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidInteger and returns true if no exceptions are thrown.- Specified by:
isValidIntegerin interfaceValidator- Throws:
IntrusionException
-
getValidInteger
public java.lang.Integer getValidInteger(java.lang.String context, java.lang.String input, int minValue, int maxValue, boolean allowNull) throws ValidationException, IntrusionExceptionReturns a validated integer. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidIntegerin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual input data to validate.minValue- Lowest legal value for input.maxValue- Highest legal value for input.allowNull- If allowNull is true then an 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.- Returns:
- A validated number as an integer.
- Throws:
ValidationExceptionIntrusionException
-
getValidInteger
public java.lang.Integer getValidInteger(java.lang.String context, java.lang.String input, int minValue, int maxValue, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidInteger with the supplied errorList to capture ValidationExceptions- Specified by:
getValidIntegerin interfaceValidator- Throws:
IntrusionException
-
isValidFileContent
public boolean isValidFileContent(java.lang.String context, byte[] input, int maxBytes, boolean allowNull) throws IntrusionExceptionCalls getValidFileContent and returns true if no exceptions are thrown.- Specified by:
isValidFileContentin interfaceValidator- Throws:
IntrusionException
-
isValidFileContent
public boolean isValidFileContent(java.lang.String context, byte[] input, int maxBytes, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidFileContent and returns true if no exceptions are thrown.- Specified by:
isValidFileContentin interfaceValidator- Throws:
IntrusionException
-
getValidFileContent
public byte[] getValidFileContent(java.lang.String context, byte[] input, int maxBytes, boolean allowNull) throws ValidationException, IntrusionExceptionReturns validated file content as a byte array. This is a good place to check for max file size, allowed character sets, and do virus scans. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidFileContentin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The actual input data to validate.maxBytes- The maximum number of bytes allowed in a legal file.allowNull- If allowNull is true then an 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.- Returns:
- A byte array containing valid file content.
- Throws:
ValidationExceptionIntrusionException
-
getValidFileContent
public byte[] getValidFileContent(java.lang.String context, byte[] input, int maxBytes, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidFileContent with the supplied errorList to capture ValidationExceptions- Specified by:
getValidFileContentin interfaceValidator- Throws:
IntrusionException
-
isValidFileUpload
public boolean isValidFileUpload(java.lang.String context, java.lang.String directorypath, java.lang.String filename, java.io.File parent, byte[] content, int maxBytes, boolean allowNull) throws IntrusionExceptionCalls getValidFileUpload and returns true if no exceptions are thrown.Note: On platforms that support symlinks, this function will fail canonicalization if directorypath is a symlink. For example, on MacOS X, /etc is actually /private/etc. If you mean to use /etc, use its real path (/private/etc), not the symlink (/etc).
- Specified by:
isValidFileUploadin interfaceValidator- Throws:
IntrusionException
-
isValidFileUpload
public boolean isValidFileUpload(java.lang.String context, java.lang.String directorypath, java.lang.String filename, java.io.File parent, byte[] content, int maxBytes, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidFileUpload and returns true if no exceptions are thrown.Note: On platforms that support symlinks, this function will fail canonicalization if directorypath is a symlink. For example, on MacOS X, /etc is actually /private/etc. If you mean to use /etc, use its real path (/private/etc), not the symlink (/etc).
- Specified by:
isValidFileUploadin interfaceValidator- Throws:
IntrusionException
-
assertValidFileUpload
public void assertValidFileUpload(java.lang.String context, java.lang.String directorypath, java.lang.String filename, java.io.File parent, byte[] content, int maxBytes, java.util.List<java.lang.String> allowedExtensions, boolean allowNull) throws ValidationException, IntrusionExceptionValidates the filepath, filename, and content of a file. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
assertValidFileUploadin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.directorypath- The file path of the uploaded file.filename- The filename of the uploaded filecontent- A byte array containing the content of the uploaded file.maxBytes- The max number of bytes allowed for a legal file upload.allowNull- If allowNull is true then an 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.- Throws:
ValidationExceptionIntrusionException
-
assertValidFileUpload
public void assertValidFileUpload(java.lang.String context, java.lang.String filepath, java.lang.String filename, java.io.File parent, byte[] content, int maxBytes, java.util.List<java.lang.String> allowedExtensions, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidFileUpload with the supplied errorList to capture ValidationExceptions- Specified by:
assertValidFileUploadin interfaceValidator- Throws:
IntrusionException
-
isValidListItem
public boolean isValidListItem(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> list)Calls getValidListItem and returns true if no exceptions are thrown. Returns true if input is a valid list item.- Specified by:
isValidListItemin interfaceValidator
-
isValidListItem
public boolean isValidListItem(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> list, ValidationErrorList errors)Calls getValidListItem and returns true if no exceptions are thrown. Returns true if input is a valid list item.- Specified by:
isValidListItemin interfaceValidator
-
getValidListItem
public java.lang.String getValidListItem(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> list) throws ValidationException, IntrusionExceptionReturns the list item that exactly matches the canonicalized input. Invalid or non-matching input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidListItemin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- The value to search 'list' for.list- The list to search for 'input'.- Returns:
- The list item that exactly matches the canonicalized input.
- Throws:
ValidationExceptionIntrusionException
-
getValidListItem
public java.lang.String getValidListItem(java.lang.String context, java.lang.String input, java.util.List<java.lang.String> list, ValidationErrorList errors) throws IntrusionExceptionValidationErrorList variant of getValidListItem- Specified by:
getValidListItemin interfaceValidator- Parameters:
errors-- Throws:
IntrusionException
-
isValidHTTPRequestParameterSet
public boolean isValidHTTPRequestParameterSet(java.lang.String context, javax.servlet.http.HttpServletRequest request, java.util.Set<java.lang.String> requiredNames, java.util.Set<java.lang.String> optionalNames)Calls assertValidHTTPRequestParameterSet and returns true if no exceptions are thrown.- Specified by:
isValidHTTPRequestParameterSetin interfaceValidator
-
isValidHTTPRequestParameterSet
public boolean isValidHTTPRequestParameterSet(java.lang.String context, javax.servlet.http.HttpServletRequest request, java.util.Set<java.lang.String> requiredNames, java.util.Set<java.lang.String> optionalNames, ValidationErrorList errors)Calls assertValidHTTPRequestParameterSet and returns true if no exceptions are thrown.- Specified by:
isValidHTTPRequestParameterSetin interfaceValidator
-
assertValidHTTPRequestParameterSet
public void assertValidHTTPRequestParameterSet(java.lang.String context, javax.servlet.http.HttpServletRequest request, java.util.Set<java.lang.String> required, java.util.Set<java.lang.String> optional) throws ValidationException, IntrusionExceptionValidates that the parameters in the current request contain all required parameters and only optional ones in addition. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException. Uses current HTTPRequest- Specified by:
assertValidHTTPRequestParameterSetin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.required- parameters that are required to be in HTTP requestoptional- additional parameters that may be in HTTP request- Throws:
ValidationExceptionIntrusionException
-
assertValidHTTPRequestParameterSet
public void assertValidHTTPRequestParameterSet(java.lang.String context, javax.servlet.http.HttpServletRequest request, java.util.Set<java.lang.String> required, java.util.Set<java.lang.String> optional, ValidationErrorList errors) throws IntrusionExceptionValidationErrorList variant of assertIsValidHTTPRequestParameterSet Uses current HTTPRequest saved in ESAPI Authenticator- Specified by:
assertValidHTTPRequestParameterSetin interfaceValidator- Parameters:
errors-- Throws:
IntrusionException
-
isValidPrintable
public boolean isValidPrintable(java.lang.String context, char[] input, int maxLength, boolean allowNull) throws IntrusionExceptionCalls getValidPrintable and returns true if no exceptions are thrown. Checks that all bytes are valid ASCII characters (between 33 and 126 inclusive). This implementation does no decoding. http://en.wikipedia.org/wiki/ASCII.- Specified by:
isValidPrintablein interfaceValidator- Throws:
IntrusionException
-
isValidPrintable
public boolean isValidPrintable(java.lang.String context, char[] input, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidPrintable and returns true if no exceptions are thrown. Checks that all bytes are valid ASCII characters (between 33 and 126 inclusive). This implementation does no decoding. http://en.wikipedia.org/wiki/ASCII.- Specified by:
isValidPrintablein interfaceValidator- Throws:
IntrusionException
-
getValidPrintable
public char[] getValidPrintable(java.lang.String context, char[] input, int maxLength, boolean allowNull) throws ValidationException, IntrusionExceptionReturns canonicalized and validated printable characters as a byte array. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidPrintablein interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- data to be returned as valid and printablemaxLength- Maximum number of bytes stored in 'input'allowNull- If allowNull is true then an 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.- Returns:
- a byte array containing only printable characters, made up of data from 'input'
- Throws:
IntrusionExceptionValidationException
-
getValidPrintable
public char[] getValidPrintable(java.lang.String context, char[] input, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionValidationErrorList variant of getValidPrintable- Specified by:
getValidPrintablein interfaceValidator- Parameters:
errors-- Throws:
IntrusionException
-
isValidPrintable
public boolean isValidPrintable(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull) throws IntrusionExceptionCalls getValidPrintable and returns true if no exceptions are thrown. Returns true if input is valid printable ASCII characters (32-126).- Specified by:
isValidPrintablein interfaceValidator- Throws:
IntrusionException
-
isValidPrintable
public boolean isValidPrintable(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionCalls getValidPrintable and returns true if no exceptions are thrown. Returns true if input is valid printable ASCII characters (32-126).- Specified by:
isValidPrintablein interfaceValidator- Throws:
IntrusionException
-
getValidPrintable
public java.lang.String getValidPrintable(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull) throws ValidationException, IntrusionExceptionReturns canonicalized and validated printable characters as a String. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidPrintablein interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- data to be returned as valid and printablemaxLength- Maximum number of bytes stored in 'input' after canonicalizationallowNull- If allowNull is true then an 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.- Returns:
- a String containing only printable characters, made up of data from 'input'
- Throws:
IntrusionExceptionValidationException
-
getValidPrintable
public java.lang.String getValidPrintable(java.lang.String context, java.lang.String input, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionValidationErrorList variant of getValidPrintable- Specified by:
getValidPrintablein interfaceValidator- Parameters:
errors-- Throws:
IntrusionException
-
isValidRedirectLocation
public boolean isValidRedirectLocation(java.lang.String context, java.lang.String input, boolean allowNull) throws IntrusionExceptionReturns true if input is a valid redirect location.- Specified by:
isValidRedirectLocationin interfaceValidator- Throws:
IntrusionException
-
isValidRedirectLocation
public boolean isValidRedirectLocation(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionReturns true if input is a valid redirect location.- Specified by:
isValidRedirectLocationin interfaceValidator- Throws:
IntrusionException
-
getValidRedirectLocation
public java.lang.String getValidRedirectLocation(java.lang.String context, java.lang.String input, boolean allowNull) throws ValidationException, IntrusionExceptionReturns a canonicalized and validated redirect location as a String. Invalid input will generate a descriptive ValidationException, and input that is clearly an attack will generate a descriptive IntrusionException.- Specified by:
getValidRedirectLocationin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- redirect location to be returned as valid, according to encoding rules set in "ESAPI.properties"allowNull- If allowNull is true then an 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.- Returns:
- A canonicalized and validated redirect location, as defined in "ESAPI.properties"
- Throws:
ValidationExceptionIntrusionException
-
getValidRedirectLocation
public java.lang.String getValidRedirectLocation(java.lang.String context, java.lang.String input, boolean allowNull, ValidationErrorList errors) throws IntrusionExceptionValidationErrorList variant of getValidRedirectLocation- Specified by:
getValidRedirectLocationin interfaceValidator- Parameters:
errors-- Throws:
IntrusionException
-
safeReadLine
public java.lang.String safeReadLine(java.io.InputStream in, int max) throws ValidationExceptionReads from an input stream until end-of-line or a maximum number of characters. This method protects against the inherent denial of service attack in reading until the end of a line. If an attacker doesn't ever send a newline character, then a normal input stream reader will read until all memory is exhausted and the platform throws an OutOfMemoryError and probably terminates. This implementation reads until a newline or the specified number of characters.- Specified by:
safeReadLinein interfaceValidator- Parameters:
in-max-- Returns:
- a String containing the current line of inputStream
- Throws:
ValidationException
-
isValidURI
public boolean isValidURI(java.lang.String context, java.lang.String input, boolean allowNull)Parses and ensures that the URI in question is a valid RFC-3986 URI. This simplifies the kind of regex required for subsequent validation to mitigate regex-based DoS attacks.- Specified by:
isValidURIin interfaceValidator- Parameters:
context- A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the value passed in.input- redirect location to be returned as valid, according to encoding rules set in "ESAPI.properties"allowNull- If allowNull is true then an 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.- Returns:
- True if the URI is valid
- See Also:
- RFC-3986.
-
getRfcCompliantURI
public java.net.URI getRfcCompliantURI(java.lang.String input)
Will return aURIobject that will represent a fully parsed and legal URI as specified in RFC-3986.- Specified by:
getRfcCompliantURIin interfaceValidator- Parameters:
input- String- Returns:
- URI object representing a parsed URI, or
nullif the URI was non-compliant in some way.
-
-