Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class CookieCsrfTokenRepository
- Object
- CookieCsrfTokenRepository
ImplementsCsrfTokenRepository
Keeps the token in a cookie, XSRF-TOKEN, for a page whose script reads the
cookie and sends its value back in the X-XSRF-TOKEN header – the
convention Angular and axios follow. The token is also kept in the session
so a sibling subdomain cannot inject a cookie and submit a matching value.
http.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()));A script can only read the cookie when it is not HttpOnly, which is what
withHttpOnlyFalse is for. Because the script has the token as the cookie
holds it, a chain with this repository accepts the token unmasked in the
header as well as masked. A cookie is trusted only when it matches the
token issued to the current session. Tokens copied from other sessions
are rejected.
Constructors
public CookieCsrfTokenRepository() |
Methods
Inherited methods
Constructor details
CookieCsrfTokenRepository
public CookieCsrfTokenRepository()Method details
withHttpOnlyFalse
public static CookieCsrfTokenRepository withHttpOnlyFalse()setCookieName
public void setCookieName(String cookieName)setHeaderName
public void setHeaderName(String headerName)setParameterName
public void setParameterName(String parameterName)setCookiePath
public void setCookiePath(String cookiePath)/ unless set.setCookieHttpOnly
public void setCookieHttpOnly(boolean cookieHttpOnly)generateToken
public CsrfToken generateToken(HttpServer.Request request)saveToken
public void saveToken(CsrfToken token, HttpServer.Request request)token for the client; null forgets the stored one.loadToken
public CsrfToken loadToken(HttpServer.Request request)