Finds the meta tag in the current document by the given name and returns it's content.
Description
Description
Get the CSRF token key. This can be used if you want to send CSRF tokens as header. If you want to send it using a form parameter, use the method #getParamName instead.
In order for this method to produce reliable output, your base HTML
page should contain a <meta>
-tag in the <head>
with name
_csrf_header
. The content
attribute is best filled from Spring by
using this variable: ${_csrf.headerName}
.
Get the name of the parameter to send when you want to pass CSRF tokens via a form. Alternatively you can use #getKey to get the name of the header to send for CSRF-protection.
In order for this method to produce reliable output, your base HTML
page should contain a <meta>
-tag in the <head>
with name
_csrf_parameter_name
. The content
attribute is best filled from
Spring by using this variable: ${_csrf.parameterName}
.
The name of the parameter to send when sending CSRF tokens via forms, e.g. "_csrf" or the empty string if the meta tag cannot be found.
Get the CSRF token value.
In order for this method to produce reliable output, your base HTML
page should contain a <meta>
-tag in the <head>
with name
_csrf
. The content
attribute is best filled from Spring by
using this variable: ${_csrf.token}
.
Get the CSRF token value from the XSRF-TOKEN
cookie. Alternative to
the getCsrfValue
method.
When using Spring Security, a CookieCsrfTokenRepository
has to be
configured to persist the CSRF token.
XSRF_TOKEN
cookie cannot be found.Get the full CSRF token header object. Can directly be used in fetch, e.g. in the following way:
let csrfHeader = CsrfUtil.getHeader();
fetch(targetUrl, { method: 'POST', headers: csrfHeader })
header - the header containing the CSRF key and value or an empty object if any of the required meta fields cannot be found.
Returns a simple object containing CSRF header name as key and CSRF value as field value
Simple object containing the CSRF key and value or an empty object if any of the required meta fields cannot be found.
Generated using TypeDoc
CSRF Utility methods.
Some methods to access the csrf-token information served by spring security.
The methods herein assume a certain HTML structure, which is easiest achieved by including a markup like the following in your base HTML file: