https://owasp.org/www-project-csrfguard/
BSD License, All rights reserved.
Welcome to the home of the OWASP CSRFGuard Project! OWASP CSRFGuard is a library that implements a variant of the synchronizer token pattern to mitigate the risk of Cross-Site Request Forgery (CSRF) attacks. The OWASP CSRFGuard library is integrated through the use of a JavaEE Filter and exposes various automated and manual ways to integrate per-session or pseudo-per-request tokens into HTML. When a user interacts with this HTML, CSRF prevention tokens (i.e. cryptographically random synchronizer tokens) are submitted with the corresponding HTTP request. It is the responsibility of OWASP CSRFGuard to ensure the token is present and is valid for the current HTTP request. Any attempt to submit a request to a protected resource without the correct corresponding token is viewed as a CSRF attack in progress and is discarded. Prior to discarding the request, CSRFGuard can be configured to take one or more actions such as logging aspects of the request and redirecting the user to a landing page. The latest release enhances this strategy to support the optional verification of HTTP requests submitted using Ajax as well as the optional verification of referrer headers.
The CSRFGuard project is run by Azzeddine RAMRAMI and Istvan ALBERT-TOTH.
OWASP CSRFGuard 4.x is offered under the BSD license.
Add the following dependencies to your Maven POM file to use the library:
Note: for the Jakarta releases use the -jakarta
suffix in the version
.
<dependency>
<groupId>org.owasp</groupId>
<artifactId>csrfguard</artifactId>
<version>4.4.0</version>
</dependency>
<!-- Stateful web application support -->
<dependency>
<groupId>org.owasp</groupId>
<artifactId>csrfguard-extension-session</artifactId>
<version>4.4.0</version>
</dependency>
<!-- JSP TAG support -->
<dependency>
<groupId>org.owasp</groupId>
<artifactId>csrfguard-jsp-tags</artifactId>
<version>4.4.0</version>
</dependency>
- Make sure you have Apache Maven 3.6.3+ and JDK 11+ installed
- Clone this repository locally
- Build the project by running
mvn clean install
in the project root directory - Build and run the test JSP web application by running
mvn pre-integration-test -Pdeploy-jsp-webapp -pl csrfguard-test/csrfguard-test-jsp
ormvn -Pdeploy-jsp-webapp -pl csrfguard-test/csrfguard-test-jsp tomcat7:run
- Optional: you can use
mvnDebug
to enable remote debugging, then connect your IDE to it (default port is 8000) - Use a web browser to access
http://localhost:8080
to open the home page of the test project
- Follow the Sonatype Open-Source Project Maven Repository Usage Guide to create a Sonatype user account;
- Next, open a support request to get your newly created username added to the Maven groupId
org.owasp
; - Once the support request has been completed, follow the instructions in the Sonatype Maven repository usage guide mentioned above to upload new versions to the Maven Central repository.
You can download pre-compiled versions from:
If you have questions, would like to share or discuss ideas, please use the official discussions page (preferred). You can also sign up for the OWASP CSRFGuard email list here.
- Support for stateless web applications
- Apply "TokenPerPage" approach to AJAX
- Reduced code duplication
- Proper multi-module maven project structure
- The test JSP web application now relies on the latest development JavaScript code
- Improved code quality
- Addressing synchronous XMLHttpRequest deprecation
- Approach changed for master and page token retrieval
- Improved test coverage
- Better solution for looking up page tokens in the JS
- The javascript template is now parsable and minifiable
- Short-circuit the solution logic if CSRFGuard is disabled
- Do not generate page tokens for pages that are not protected
- Page tokens generated on first use are not sent back to the client
- Issue with the token-per-page support for REST endpoint containing path parameters
- Possible race condition on first access of endpoints when token-per-page and AJAX request options are enabled
- Tokens are not injected into dynamically created DOM elements
- Make the configuration more resilient to errors
- Tokens should not be injected into external links if the domainStrict property is set to true
- Tokens not injected in dynamic content returned from Ajax
- Heavily refactored, improved and more optimized code-base
- Documentation update and typo fixes.
- Copyright update and unification.