Package filter
Class InputSanitizationFilter
java.lang.Object
filter.InputSanitizationFilter
- All Implemented Interfaces:
javax.servlet.Filter
Filter that validates and sanitizes user input to prevent XSS and injection attacks.
Blocks requests containing dangerous patterns or invalid data.
- Author:
- TAMIL MUGHILAN
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
containsDangerousSequences
(String value) void
destroy()
Cleans up resources when filter is destroyed.void
doFilter
(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) Processes requests to validate all input parameters.void
init
(javax.servlet.FilterConfig filterConfig) Initializes the filter when application starts.private boolean
Validates if a parameter value is safe to process.private boolean
isStaticResource
(String path) Checks if the requested path is a static resource.private boolean
validateAmount
(String amount) private boolean
validateContent
(String value) private boolean
validateCSRFToken
(String token) private boolean
validateEmail
(String email) private boolean
validateGeneral
(String value) private boolean
validateId
(String id) private boolean
validateName
(String name) private boolean
validatePassword
(String password) private boolean
validatePhone
(String phone)
-
Field Details
-
DANGEROUS_PATTERNS
-
-
Constructor Details
-
InputSanitizationFilter
public InputSanitizationFilter()
-
-
Method Details
-
init
public void init(javax.servlet.FilterConfig filterConfig) Initializes the filter when application starts.- Specified by:
init
in interfacejavax.servlet.Filter
- Parameters:
filterConfig
- the filter configuration
-
destroy
public void destroy()Cleans up resources when filter is destroyed.- Specified by:
destroy
in interfacejavax.servlet.Filter
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException Processes requests to validate all input parameters. Blocks requests containing dangerous or invalid input.- Specified by:
doFilter
in interfacejavax.servlet.Filter
- Parameters:
request
- the servlet requestresponse
- the servlet responsechain
- the filter chain- Throws:
IOException
- if an I/O error occursjavax.servlet.ServletException
- if a servlet error occurs
-
isStaticResource
Checks if the requested path is a static resource.- Parameters:
path
- the request path to check- Returns:
- true if it's a static resource, false otherwise
-
isSafe
Validates if a parameter value is safe to process.- Parameters:
paramName
- the parameter namevalue
- the parameter value- Returns:
- true if safe, false if dangerous
-
validateContent
-
validateEmail
-
validatePhone
-
validateAmount
-
validateName
-
validateId
-
validateCSRFToken
-
validatePassword
-
validateGeneral
-
containsDangerousSequences
-