Security
Linz comes with a number of security features out of the box including:
- CSRF Protection
CSRF Protection#
CSRF protection helps prevent unauthorized commands that are transmitted from a user that the web application trusts.
You can read more about CSRF on OWASP.
Customising CSRF#
Linz uses the csurf module to provide CSRF protection.
To customise the options you can supply Linz with the option 'csrf options: {}'. It accepts an object with the same properties as the csurf module:
Custom error handler#
CSRF errors throw an error with the code err.code === 'EBADCSRFTOKEN'. You can use this in your error handlers to display a custom message.
For example, here is a snippet from the linz error middleware:
Adding CSRF protection to a custom form#
The csurf module exposes the csrf token via req.csrfToken().
When implementing a custom page with a form, make sure to pass the following hidden input:
This is handled automatically for you when using linz.api.model.generateFormString(). Just make sure to add the csrfToken option: