【发布时间】:2020-08-04 01:11:10
【问题描述】:
我对配置 CsrfGuard 有疑问。我使用来自 github 的配置(在这里 -> https://github.com/aramrami/OWASP-CSRFGuard/tree/d197506c122aefa09af807ac48e944d778bf624c/csrfguard-test)。
我尝试实现令牌同步器模式。
当我使用它时,我仍然有警告:潜在的跨站点请求伪造(CSRF)攻击受阻(用户:,ip:0:0:0:0:0:0:0:1,错误:缺少所需的令牌请求)。
我知道有什么问题,但我不知道如何将令牌添加到我的 2 个 html 文件中。
我不使用jsp,因为我的旧应用程序有很多html文件,我不能使用jsp。我在简单的登录项目上尝试这个
我不知道我做错了什么。
当我添加这个时:<script src="/JavaScriptServlet"></script>
我在控制台中得到了这个:Failed to load resource: the server responded with a status of 404 () JavaScriptServlet:1
当我将 js 文件复制到我的项目中时(路径:/WEB-INF/Owasp.CsrfGuard.js),我遇到了这样的变量问题:%DOMAIN_STRICT%。我知道该变量是从某个文件中检索的,但我不知道是哪一个。
我不知道我做错了什么?我应该用Java编写一些代码还是在html中不起作用?
这是我在 index.html 中的代码(整个 body 标签):
<form method="POST" action="login">
<label for="username">Username:</label>
<input type="text" name="username" id="username">
<label for="password">Password:</label>
<input type="text" name="password" id="password">
<button>Submit</button>
</form>
<script src="/JavaScriptServlet"></script>
这些都是属性(对我的代码稍作修改,可能是错误的):
org.owasp.csrfguard.Logger=org.owasp.csrfguard.log.JavaLogger
org.owasp.csrfguard.NewTokenLandingPage=
org.owasp.csrfguard.configuration.provider.factory = org.owasp.csrfguard.config.overlay.ConfigurationAutodetectProviderFactory
org.owasp.csrfguard.Enabled = true
org.owasp.csrfguard.ValidateWhenNoSessionExists = true
org.owasp.csrfguard.TokenPerPage=true
org.owasp.csrfguard.TokenPerPagePrecreate=true
org.owasp.csrfguard.Ajax=true
org.owasp.csrfguard.protected.Protected=/hello.html
org.owasp.csrfguard.unprotected.Index=%servletContext%/index.html
org.owasp.csrfguard.action.Log=org.owasp.csrfguard.action.Log
org.owasp.csrfguard.action.Log.Message=potential cross-site request forgery (CSRF) attack thwarted (user:%user%, ip:%remote_ip%, uri:%request_uri%, error:%exception_message%)
org.owasp.csrfguard.action.Redirect=org.owasp.csrfguard.action.Redirect
org.owasp.csrfguard.action.Redirect.Page=%servletContext%/error.html
org.owasp.csrfguard.action.Rotate=org.owasp.csrfguard.action.Rotate
org.owasp.csrfguard.TokenName=OWASP-CSRFTOKEN
org.owasp.csrfguard.PRNG=SHA1PRNG
org.owasp.csrfguard.PRNG.Provider=SUN
org.owasp.csrfguard.Config.Print = true
org.owasp.csrfguard.JavascriptServlet.sourceFile = /script/Owasp.CsrfGuard.js
org.owasp.csrfguard.JavascriptServlet.domainStrict = true
org.owasp.csrfguard.JavascriptServlet.cacheControl = private, maxage=28800
org.owasp.csrfguard.JavascriptServlet.refererPattern = .*
org.owasp.csrfguard.JavascriptServlet.refererMatchDomain = true
org.owasp.csrfguard.JavascriptServlet.injectIntoForms = true
org.owasp.csrfguard.JavascriptServlet.injectGetForms = false
org.owasp.csrfguard.JavascriptServlet.injectFormAttributes = true
org.owasp.csrfguard.JavascriptServlet.injectIntoAttributes = true
org.owasp.csrfguard.JavascriptServlet.xRequestedWith = OWASP CSRFGuard Project
org.owasp.csrfguard.configOverlay.hierarchy = classpath:Owasp.CsrfGuard.properties, classpath:Owasp.CsrfGuard.overlay.properties
org.owasp.csrfguard.configOverlay.secondsBetweenUpdateChecks = 60
【问题讨论】: