├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── dependabot.yml └── workflows │ ├── ci.yaml │ ├── dependency_check.yaml │ └── snyk.yaml ├── .gitignore ├── 404.html ├── Gemfile ├── LICENSE ├── _config.yml ├── assets └── images │ ├── README.md │ ├── csrfguard.png │ ├── csrfguard_in_action.png │ ├── mature_projects.png │ ├── owasp_breakers_small.png │ ├── owasp_builders_small.png │ ├── owasp_tool_project.png │ ├── what_is_csrf_attacks_1.png │ ├── what_is_csrf_attacks_2.png │ ├── what_is_csrf_attacks_3.png │ ├── what_is_csrf_attacks_4.png │ ├── what_is_csrf_attacks_5.png │ ├── what_is_csrf_attacks_6.png │ └── what_is_csrf_attacks_7.png ├── csrfguard-extensions ├── csrfguard-extension-session │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── org │ │ └── owasp │ │ └── csrfguard │ │ ├── CsrfGuardHttpSessionListener.java │ │ ├── action │ │ └── SessionAttribute.java │ │ └── session │ │ ├── ContainerSession.java │ │ └── SessionTokenKeyExtractor.java ├── csrfguard-jsp-tags │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── owasp │ │ │ └── csrfguard │ │ │ └── tag │ │ │ ├── ATag.java │ │ │ ├── AbstractTag.java │ │ │ ├── AbstractUriTag.java │ │ │ ├── FormTag.java │ │ │ ├── TokenNameTag.java │ │ │ ├── TokenTag.java │ │ │ └── TokenValueTag.java │ │ └── resources │ │ └── META-INF │ │ └── csrfguard.tld └── pom.xml ├── csrfguard-test ├── csrfguard-test-jsp │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── owasp │ │ │ └── csrfguard │ │ │ └── test │ │ │ ├── CORSFilter.java │ │ │ └── CounterServlet.java │ │ ├── resources │ │ └── logback.xml │ │ └── webapp │ │ ├── WEB-INF │ │ ├── classes │ │ │ ├── Owasp.CsrfGuard.overlay.properties │ │ │ └── Owasp.CsrfGuard.properties │ │ └── web.xml │ │ ├── ajax.html │ │ ├── attack1.html │ │ ├── attack2.html │ │ ├── counter.html │ │ ├── error.html │ │ ├── favicon.ico │ │ ├── forward.jsp │ │ ├── index.html │ │ ├── javascript.html │ │ ├── legacySyncAjaxTest.html │ │ ├── owasp_logo.png │ │ ├── protect.html │ │ ├── redirect.jsp │ │ ├── regextest │ │ ├── protected.html │ │ ├── protected.txt │ │ ├── resources │ │ │ ├── protected.html │ │ │ ├── protected.txt │ │ │ └── unprotected.html │ │ └── unprotected.html │ │ ├── session.jsp │ │ ├── tag.jsp │ │ ├── upload.html │ │ └── wildcardtest │ │ ├── test.html │ │ └── test.txt └── pom.xml ├── csrfguard ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── owasp │ │ │ └── csrfguard │ │ │ ├── CsrfGuard.java │ │ │ ├── CsrfGuardException.java │ │ │ ├── CsrfGuardFilter.java │ │ │ ├── CsrfGuardServletContextListener.java │ │ │ ├── CsrfValidator.java │ │ │ ├── ProtectionResult.java │ │ │ ├── action │ │ │ ├── AbstractAction.java │ │ │ ├── Empty.java │ │ │ ├── Error.java │ │ │ ├── Forward.java │ │ │ ├── IAction.java │ │ │ ├── Invalidate.java │ │ │ ├── Log.java │ │ │ ├── Redirect.java │ │ │ ├── RequestAttribute.java │ │ │ └── Rotate.java │ │ │ ├── config │ │ │ ├── ConfigurationProvider.java │ │ │ ├── ConfigurationProviderFactory.java │ │ │ ├── NullConfigurationProvider.java │ │ │ ├── NullConfigurationProviderFactory.java │ │ │ ├── PropertiesConfigurationProvider.java │ │ │ ├── PropertiesConfigurationProviderFactory.java │ │ │ ├── overlay │ │ │ │ ├── ConfigPropertiesCascadeBase.java │ │ │ │ ├── ConfigPropertiesCascadeCommonUtils.java │ │ │ │ ├── ConfigPropertiesCascadeUtils.java │ │ │ │ ├── ConfigurationAutodetectProviderFactory.java │ │ │ │ ├── ConfigurationOverlayProvider.java │ │ │ │ ├── ConfigurationOverlayProviderFactory.java │ │ │ │ ├── ExpirableCache.java │ │ │ │ └── ExpirableValue.java │ │ │ └── properties │ │ │ │ ├── ConfigParameters.java │ │ │ │ ├── HttpMethod.java │ │ │ │ ├── PropertyUtils.java │ │ │ │ ├── SimpleBooleanConfigParameter.java │ │ │ │ ├── SimpleConfigParameter.java │ │ │ │ ├── SimpleDurationParameter.java │ │ │ │ ├── SimpleIntConfigParameter.java │ │ │ │ └── javascript │ │ │ │ ├── BooleanJsConfigParameter.java │ │ │ │ ├── JavaScriptConfigParameters.java │ │ │ │ ├── JsConfigParameter.java │ │ │ │ └── StringJsConfigParameter.java │ │ │ ├── exception │ │ │ └── CSRFGuardTokenException.java │ │ │ ├── http │ │ │ └── InterceptRedirectResponse.java │ │ │ ├── servlet │ │ │ └── JavaScriptServlet.java │ │ │ ├── session │ │ │ └── LogicalSession.java │ │ │ ├── token │ │ │ ├── TokenUtils.java │ │ │ ├── businessobject │ │ │ │ └── TokenBO.java │ │ │ ├── mapper │ │ │ │ └── TokenMapper.java │ │ │ ├── service │ │ │ │ └── TokenService.java │ │ │ ├── storage │ │ │ │ ├── LogicalSessionExtractor.java │ │ │ │ ├── Token.java │ │ │ │ ├── TokenHolder.java │ │ │ │ └── impl │ │ │ │ │ ├── InMemoryToken.java │ │ │ │ │ ├── InMemoryTokenHolder.java │ │ │ │ │ └── PageTokenValue.java │ │ │ └── transferobject │ │ │ │ └── TokenTO.java │ │ │ └── util │ │ │ ├── BrowserEncoder.java │ │ │ ├── ConvertUtil.java │ │ │ ├── CsrfGuardPropertiesToStringBuilder.java │ │ │ ├── CsrfGuardUtils.java │ │ │ ├── MessageConstants.java │ │ │ ├── RandomGenerator.java │ │ │ └── RegexValidationUtil.java │ └── resources │ │ ├── .babelrc │ │ ├── .gitignore │ │ ├── csrfguard.js │ │ ├── csrfguard.min.js │ │ ├── csrfguard.properties │ │ ├── license.txt │ │ ├── package-lock.json │ │ ├── package.json │ │ └── webpack.config.js │ └── test │ └── java │ └── org │ └── owasp │ └── csrfguard │ ├── CsrfValidatorTest.java │ ├── MandatoryProperties.java │ ├── config │ ├── PropertiesConfigurationProviderTest.java │ └── dummy │ │ ├── DummyAction.java │ │ └── DummyLogicalSessionExtractor.java │ ├── token │ └── transferobject │ │ └── TokenTOTest.java │ └── util │ └── RandomGeneratorTest.java ├── index.md ├── info.md ├── leaders.md ├── pom.xml ├── readme.md ├── tab_features.md ├── tab_screenshots.md └── tab_supporters.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | updates: 4 | - package-ecosystem: maven 5 | directory: / 6 | schedule: 7 | interval: daily -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | 15 | - name: Build with Maven 16 | run: mvn --batch-mode --update-snapshots verify 17 | 18 | - name: 'Upload Artifact' 19 | if: github.event_name == 'workflow_dispatch' 20 | uses: actions/upload-artifact@v4 21 | with: 22 | name: csrfguard-latest-test-application 23 | path: | 24 | csrfguard-test/csrfguard-test-jsp/csrfguard-test-jsp-*SNAPSHOT.war 25 | csrfguard-test/csrfguard-test-jsp/csrfguard-test-jsp-*SNAPSHOT-executable.jar 26 | retention-days: 3 -------------------------------------------------------------------------------- /.github/workflows/dependency_check.yaml: -------------------------------------------------------------------------------- 1 | name: OWASP Dependency Check 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | schedule: 7 | - cron: '0 10 * * 1' 8 | 9 | jobs: 10 | owasp-dependency-check: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v4 15 | 16 | - name: OWASP Dependency Check 17 | run: mvn clean --batch-mode --update-snapshots verify -Pdependency-check 18 | 19 | - name: Upload Test results 20 | uses: actions/upload-artifact@v4 21 | with: 22 | name: OWASP Dependency Check report 23 | path: target -------------------------------------------------------------------------------- /.github/workflows/snyk.yaml: -------------------------------------------------------------------------------- 1 | name: Snyk Dependency Analysis 2 | on: 3 | workflow_dispatch: 4 | schedule: 5 | - cron: '0 10 * * 1' 6 | 7 | jobs: 8 | snyk-dependency-analysis: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | 13 | - name: Run Snyk to check for vulnerabilities 14 | uses: snyk/actions/maven@master 15 | continue-on-error: true 16 | env: 17 | SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} 18 | with: 19 | command: test --package-manager=maven --file=pom.xml --severity-threshold=medium --maven-aggregate-project --sarif-file-output=snyk.sarif 20 | 21 | - name: Upload result to GitHub Code Scanning 22 | uses: github/codeql-action/upload-sarif@v3 23 | with: 24 | sarif_file: snyk.sarif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Directory-based project format: 2 | .idea/ 3 | !.idea/copyright 4 | !.idea/dataSources.xml 5 | 6 | ## File-based project format: 7 | *.ipr 8 | *.iws 9 | *.iml 10 | 11 | # Output directories 12 | target/ 13 | /build/ 14 | /dist/ 15 | bin/ 16 | *.class 17 | 18 | # Eclipse metadata 19 | .metadata 20 | .project 21 | .recommenders 22 | .settings 23 | .classpath 24 | .loadpath 25 | 26 | # NetBeans specific 27 | nbproject/private/ 28 | build/ 29 | nbbuild/ 30 | dist/ 31 | nbdist/ 32 | nbactions.xml 33 | nb-configuration.xml 34 | 35 | # SonarGraph metadata 36 | *.sonargraph 37 | 38 | # Overlays 39 | *overlays/ 40 | 41 | # MacOS files 42 | .DS_Store 43 | .DS_Store? 44 | ._* 45 | .Spotlight-V100 46 | .Trashes 47 | ehthumbs.db 48 | Thumbs.db 49 | _site/ 50 | -------------------------------------------------------------------------------- /404.html: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | title: 404 - Not Found 4 | layout: col-generic 5 | 6 | --- 7 | 8 |
Try the SEARCH function in the main navigation to find something. If you are looking for chapter information, please see Chapters for the correct chapter. For information about OWASP projects see Projects. For common attacks, vulnerabilities, or information about other community-led contributions see Contributed Content.
12 | 13 |If all else fails you can search our historical site.
15 |Get or increment the counter:
41 |If the counter can be externally incremented, it signals that there is a vulnerability in the solution.
42 | 43 | 44 | 48 |Mimic hosting the exploits on a different domain:
25 |Tokens should not be injected into links referencing different domains if the domainStrict property is set to true.
47 | 51 |11 | The current approach of the OWASP CSRFGuard relies on JavaScript logic for injecting CSRF tokens into HTML elements or XHR requests. 12 | Forcing synchronous loading of the AJAX requests has been disabled, since they were 13 | deprecated 14 | due to their negative impact on the user experience. For this reason, protecting resources that would load 15 | before or in parallel with the JavaScript logic (e.g. references IFrames or IMG tags) is not possible. 16 | In most cases this should not be a problem, because usually GET requests should not facilitate state-changing operations. 17 | If this last condition cannot be fulfilled (e.g. for legacy applications), backwards compatibility can be achieved by enabling the 18 | "forceSynchronousAjax" property within the configurations, until there is browser support for it. 19 |
20 |Aims to test token injection for referenced protected pages that are loaded before user interaction.
22 |
23 |
24 |
25 |
Aims to test token injection for referenced protected pages that are loaded before user interaction.
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/csrfguard-test/csrfguard-test-jsp/src/main/webapp/owasp_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OWASP/www-project-csrfguard/cb951a1ae5c162e0f62d046348906e995b793775/csrfguard-test/csrfguard-test-jsp/src/main/webapp/owasp_logo.png
--------------------------------------------------------------------------------
/csrfguard-test/csrfguard-test-jsp/src/main/webapp/protect.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
true
if the client does not yet know about the
46 | * session or if the client chooses not to join the session.
47 | *
48 | * @see javax.servlet.http.HttpSession#isNew()
49 | *
50 | * @return true
if the server has created a session, but the client has not yet joined
51 | */
52 | boolean isNew();
53 |
54 | /**
55 | * Invalidates this session then unbinds any objects bound to it.
56 | */
57 | void invalidate();
58 |
59 | /**
60 | * @return whether the objects were generated or not.
61 | */
62 | boolean areTokensGenerated();
63 |
64 | /**
65 | * Set whether the objects were generated or not.
66 | *
67 | * @param areTokensGenerated set true
if the tokens were generated, false
otherwise
68 | */
69 | void setTokensGenerated(boolean areTokensGenerated);
70 |
71 | /**
72 | * Saves an object to the current session
73 | *
74 | * @see HttpSession#setAttribute(java.lang.String, java.lang.Object)
75 | *
76 | * @param attribute the name to which the object is bound; cannot be null
77 | * @param value the object to be bound
78 | */
79 | void setAttribute(final String attribute, final Object value);
80 |
81 | /**
82 | * Retrieves an object from the session using its name
83 | *
84 | * @see HttpSession#getAttribute(String)
85 | *
86 | * @param attributeName - identifies a certain object on the session
87 | * @return the object associated to the attribute name
88 | */
89 | Object getAttribute(String attributeName);
90 | }
91 |
--------------------------------------------------------------------------------
/csrfguard/src/main/java/org/owasp/csrfguard/token/TokenUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The OWASP CSRFGuard Project, BSD License
3 | * Copyright (c) 2011, Eric Sheridan (eric@infraredsecurity.com)
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are met:
8 | *
9 | * 1. Redistributions of source code must retain the above copyright notice,
10 | * this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of OWASP nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific
16 | * prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 |
30 | package org.owasp.csrfguard.token;
31 |
32 | import org.owasp.csrfguard.CsrfGuard;
33 | import org.owasp.csrfguard.exception.CSRFGuardTokenException;
34 | import org.owasp.csrfguard.util.MessageConstants;
35 | import org.owasp.csrfguard.util.RandomGenerator;
36 |
37 | public final class TokenUtils {
38 |
39 | private TokenUtils() {}
40 |
41 | /**
42 | * Create a random token based on the configuration.
43 | *
44 | * @return a random token
45 | */
46 | public static String generateRandomToken() {
47 | try {
48 | final CsrfGuard csrfGuard = CsrfGuard.getInstance();
49 | return RandomGenerator.generateRandomId(csrfGuard.getPrng(), csrfGuard.getTokenLength());
50 | } catch (final Exception e) {
51 | final String errorLiteral = MessageConstants.RANDOM_TOKEN_FAILURE_MSG + " - " + "%s";
52 | throw new CSRFGuardTokenException(String.format(errorLiteral, e.getLocalizedMessage()), e);
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/csrfguard/src/main/java/org/owasp/csrfguard/token/mapper/TokenMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The OWASP CSRFGuard Project, BSD License
3 | * Copyright (c) 2011, Eric Sheridan (eric@infraredsecurity.com)
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are met:
8 | *
9 | * 1. Redistributions of source code must retain the above copyright notice,
10 | * this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of OWASP nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific
16 | * prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package org.owasp.csrfguard.token.mapper;
30 |
31 | import org.owasp.csrfguard.token.businessobject.TokenBO;
32 | import org.owasp.csrfguard.token.transferobject.TokenTO;
33 |
34 | public final class TokenMapper {
35 |
36 | private TokenMapper() {}
37 |
38 | public static TokenTO toTransferObject(final TokenBO tokenBO) {
39 | return new TokenTO(tokenBO.getUpdatedMasterToken(), tokenBO.getUpdatedPageTokens());
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/csrfguard/src/main/java/org/owasp/csrfguard/token/storage/LogicalSessionExtractor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The OWASP CSRFGuard Project, BSD License
3 | * Copyright (c) 2011, Eric Sheridan (eric@infraredsecurity.com)
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are met:
8 | *
9 | * 1. Redistributions of source code must retain the above copyright notice,
10 | * this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of OWASP nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific
16 | * prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package org.owasp.csrfguard.token.storage;
30 |
31 | import org.owasp.csrfguard.session.LogicalSession;
32 |
33 | import javax.servlet.http.HttpServletRequest;
34 |
35 | public interface LogicalSessionExtractor {
36 |
37 | /**
38 | * Returns a logical session implementation based on the information extracted from the current HTTP request or null if that was not possible
39 | *
40 | * @param httpServletRequest current request
41 | *
42 | * @return a logical session created based on the current request or null if that was not possible
43 | */
44 | LogicalSession extract(final HttpServletRequest httpServletRequest);
45 |
46 | /**
47 | * Returns a logical session implementation based on the information extracted from the current HTTP request or creates a new one
48 | *
49 | * @param httpServletRequest current request
50 | * @return logical session implementation based on the information extracted from the current HTTP request or creates a new one
51 | */
52 | LogicalSession extractOrCreate(HttpServletRequest httpServletRequest);
53 | }
54 |
--------------------------------------------------------------------------------
/csrfguard/src/main/java/org/owasp/csrfguard/token/storage/impl/PageTokenValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The OWASP CSRFGuard Project, BSD License
3 | * Copyright (c) 2011, Eric Sheridan (eric@infraredsecurity.com)
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are met:
8 | *
9 | * 1. Redistributions of source code must retain the above copyright notice,
10 | * this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of OWASP nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific
16 | * prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package org.owasp.csrfguard.token.storage.impl;
30 |
31 | import java.time.LocalDateTime;
32 |
33 | public final class PageTokenValue {
34 |
35 | private final String pageTokenValue;
36 | private final LocalDateTime localDateTime;
37 |
38 | private PageTokenValue(final String pageTokenValue) {
39 | this(pageTokenValue, LocalDateTime.now());
40 | }
41 |
42 | private PageTokenValue(final String pageTokenValue, final LocalDateTime localDateTime) {
43 | this.pageTokenValue = pageTokenValue;
44 | this.localDateTime = localDateTime;
45 | }
46 |
47 | public static PageTokenValue from(final String pageTokenValue) {
48 | return new PageTokenValue(pageTokenValue);
49 | }
50 |
51 | public static PageTokenValue from(final String pageTokenValue, final LocalDateTime localDateTime) {
52 | return new PageTokenValue(pageTokenValue, localDateTime);
53 | }
54 |
55 | public String getValue() {
56 | return this.pageTokenValue;
57 | }
58 |
59 | public LocalDateTime getCreationTime() {
60 | return this.localDateTime;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/csrfguard/src/main/java/org/owasp/csrfguard/token/transferobject/TokenTO.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The OWASP CSRFGuard Project, BSD License
3 | * Copyright (c) 2011, Eric Sheridan (eric@infraredsecurity.com)
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are met:
8 | *
9 | * 1. Redistributions of source code must retain the above copyright notice,
10 | * this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of OWASP nor the names of its contributors may be used
15 | * to endorse or promote products derived from this software without specific
16 | * prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | */
29 | package org.owasp.csrfguard.token.transferobject;
30 |
31 | import com.google.gson.Gson;
32 | import org.apache.commons.lang3.StringUtils;
33 |
34 | import java.util.Collections;
35 | import java.util.Map;
36 |
37 | public class TokenTO {
38 |
39 | private final String masterToken;
40 |
41 | private final Map