java.lang.Object
org.klomp.snark.web.RedirectQuery
Validation for the numeric query strings used by the post/redirect/get pattern in the web UI.
A redirect query string is later handed to response.sendRedirect(); it must therefore only ever contain the known numeric parameters with integer values. Crafted input containing a scheme, host, or embedded HTML entity must be rejected so the redirect target can never be an external URL.
Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionstatic booleanValidate a redirect query string.static booleanisValidNumeric(String str) Test whether the given string is exactly a signed 32-bit integer, without throwing.
Constructor Details
RedirectQuery
private RedirectQuery()Static class, no instances.
Method Details
isSafeRedirectQuery
Validate a redirect query string. It must be null/empty, or start with '?' and contain only thep,sort,standsearchparameters with integer values separated by '&'. Anything else - a scheme, a host, a different parameter, or an embedded entity like "&" - is rejected.- Parameters:
qs- the query string, may be null or empty- Returns:
- true if the query string is safe to redirect to
isValidNumeric
Test whether the given string is exactly a signed 32-bit integer, without throwing. Unlike a naivematches()+parseInt()combination, an extremely long digit string cannot escape as an uncaughtNumberFormatException.- Parameters:
str- the string to test, may be null- Returns:
- true if the string parses cleanly to an int