CSRF
Native Cross Request Site Forgery protection for BoxLang
Last updated
Was this helpful?
Native Cross Request Site Forgery protection for BoxLang
Last updated
Was this helpful?
The CSRF module provides the functionality to generate and verify tokens for Boxlang Web Runtimes.
This module contributes the following native functions to the boxlang runtime:
CSRFGenerateToken( [string key='default'], [boolean forceNew=false] )
- this function generates the CSRF token. The optional key
argument can be provided to create and scope a specific token.
CSRFVerifyToken( required string token, [ string key ] )
- this function verifies the token created by the above method. The key
argument must be passed if the token was generated with the that argument.
CSRFRotate()
- this function will rotate all tokens in the cache by removing them. This will force the next request to generate a new token.
CSRFHiddenField( [string key='default'], [boolean forceNew=false] )
- Generates a hidden field with a csrf in it as the value. The name of the field is csrf
The module may be configured using the following settings in your boxlang.json
file. The settings noted below are the defaults:
By default, the module is configured to rotate all user csrf tokens every 30 minutes. This setting may be changed to another duration of minutes using the rotationInterval
module setting. If you do NOT want the tokens to EVER expire, then use the value of 0 zero. Note that using in-memory caches will result in token expiration on runtime shutdown.
The module may be enabled to perform auto-verification of CSRF inbound headers. If enabled, a check will be performed at the beginning of the request for the presence of the configured CSRF headerName
setting and, if verification fails, an error will be thrown. Note that any tokens created for use in auto-verification must omit the key
argument, as only the default token may be verified.
A scheduler is enabled with the module, which will perform a check and remove all expired tokens from the cache at a frequency of minutes ( default 1
). If you wish to adjust this, you can change the reapFrequency
setting to your desired interval.
Tokens may be stored in any named within the Boxlang runtime. By default, the user bxSessions
cache is used for storage.