Positive scenario:
Client Server
| |
| GET Fetch Request \| JSESSIONID
|---------------------------------| X-CSRF-Token
| /| pair generation
|/Response to Fetch Request |
|---------------------------------|
JSESSIONID |\ |
X-CSRF-Token | |
pair cached | POST Request with valid nonce \| JSESSIONID
|---------------------------------| X-CSRF-Token
| /| pair validation
|/ Response to POST Request |
|---------------------------------|
|\ |
Negative scenario:
Client Server
| |
| POST Request without nonce \| JSESSIONID
|---------------------------------| X-CSRF-Token
| /| pair validation
|/Request is rejected |
|---------------------------------|
|\ |
Client Server
| |
| POST Request with invalid nonce\| JSESSIONID
|---------------------------------| X-CSRF-Token
| /| pair validation
|/Request is rejected |
|---------------------------------|
|\ |
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private static enum | |
| private static interface | |
| private static interface | |
| private static interface | |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private static final Pattern | |
| private static final Predicate | |
| private Set | |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | doFilter(ServletRequest
The request to process request, ServletResponse The response associated with the request response, FilterChain Provides access to the next filter in the chain for this filter to pass the request and response
to for further processing chain)Implements jakarta. The |
| public Set | |
| public void | init(FilterConfig
The configuration information associated with the filter instance being initialised filterConfig)Overrides org. Overrides default jakarta. Iterates over the configuration parameters and either logs a warning, or throws an exception for any parameter that does not have a matching setter in this filter. |
| public void | setPathsAcceptingParams(String
Comma separated list of URLs to be configured as paths accepting request parameters with nonce
information. pathsList)A comma separated list of URLs that can accept nonces via request parameter 'X-CSRF-Token'. |
| NON_MODIFYING_METHODS_PATTERN | back to summary |
|---|---|
| private static final Pattern NON_MODIFYING_METHODS_PATTERN | |
| nonModifyingMethods | back to summary |
|---|---|
| private static final Predicate<String> nonModifyingMethods | |
| pathsAcceptingParams | back to summary |
|---|---|
| private Set<String> pathsAcceptingParams | |
| pathsDelimiter | back to summary |
|---|---|
| private String pathsDelimiter | |
| RestCsrfPreventionFilter | back to summary |
|---|---|
| public RestCsrfPreventionFilter() | |
| doFilter | back to summary |
|---|---|
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException Implements jakarta. Doc from jakarta. The
A typical implementation of this method would follow the following pattern:-
| |
| getPathsAcceptingParams | back to summary |
|---|---|
| public Set | |
| init | back to summary |
|---|---|
| public void init(FilterConfig filterConfig) throws ServletException Overrides org. Overrides default jakarta. Doc from org. Iterates over the configuration parameters and either logs a warning, or throws an exception for any parameter that does not have a matching setter in this filter.
| |
| setPathsAcceptingParams | back to summary |
|---|---|
| public void setPathsAcceptingParams(String pathsList) A comma separated list of URLs that can accept nonces via request parameter 'X-CSRF-Token'. For use cases when a nonce information cannot be provided via header, one can provide it via request parameters. If there is a X-CSRF-Token header, it will be taken with preference over any parameter with the same name in the request. Request parameters cannot be used to fetch new nonce, only header.
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | apply(HttpServletRequest request, HttpServletResponse response)
Implements org.
|
| fetchRequest | back to summary |
|---|---|
| private final Predicate<String> fetchRequest | |
| FetchRequest | back to summary |
|---|---|
| private FetchRequest() | |
| apply | back to summary |
|---|---|
| public boolean apply(HttpServletRequest request, HttpServletResponse response) Implements org.
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| public static final RestCsrfPreventionFilter. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static RestCsrfPreventionFilter. | |
| public static RestCsrfPreventionFilter. |
| MODIFYING_METHOD | back to summary |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| NON_MODIFYING_METHOD | back to summary |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| MethodType | back to summary |
|---|---|
| private MethodType() | |
| valueOf | back to summary |
|---|---|
| public static RestCsrfPreventionFilter. | |
| values | back to summary |
|---|---|
| public static RestCsrfPreventionFilter. | |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| setNonce | back to summary |
|---|---|
| public void setNonce(T consumer, String key, String value) | |
| getNonce | back to summary |
|---|---|
| public R getNonce(T supplier, String key) | |
| Modifier and Type | Field and Description |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| public static final RestCsrfPreventionFilter. | |
| public static final RestCsrfPreventionFilter. | |
| public static final RestCsrfPreventionFilter. | |
| public static final RestCsrfPreventionFilter. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean |
| nonceFromRequestHeader | back to summary |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| nonceFromRequestParams | back to summary |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| nonceFromSession | back to summary |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| nonceToResponse | back to summary |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| nonceToSession | back to summary |
|---|---|
| public static final RestCsrfPreventionFilter. | |
| apply | back to summary |
|---|---|
| public boolean apply(HttpServletRequest request, HttpServletResponse response) throws IOException | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | apply(HttpServletRequest request, HttpServletResponse response)
Implements org.
|
| private String | |
| private String | |
| private boolean |
| StateChangingRequest | back to summary |
|---|---|
| private StateChangingRequest() | |
| apply | back to summary |
|---|---|
| public boolean apply(HttpServletRequest request, HttpServletResponse response) throws IOException Implements org.
| |
| extractNonceFromRequest | back to summary |
|---|---|
| private String extractNonceFromRequest(HttpServletRequest request) | |
| extractNonceFromRequestParams | back to summary |
|---|---|
| private String extractNonceFromRequestParams(HttpServletRequest request) | |
| isValidStateChangingRequest | back to summary |
|---|---|
| private boolean isValidStateChangingRequest(String reqNonce, String sessionNonce) | |