Spring Boot:RequestRejectedException:请求被拒绝,因为 URL 包含潜在的恶意字符串“;”

Chl*_*loe 6 spring google-chrome spring-security spring-boot

当我发布 Spring Boot 应用程序的登录凭据时,出现以下异常。

org.springframework.security.web.firewall.RequestRejectedException:请求被拒绝,因为 URL 包含潜在的恶意字符串“;”

它被张贴到/dologin,然后重定向到/homejsessionid追加到末尾。它也设置会话cookie。我没有更改任何会话设置,也没有提到sessionin application.properties.

我试图设置

server.servlet.session.cookie.http-only=true
server.servlet.session.tracking-modes=cookie
Run Code Online (Sandbox Code Playgroud)

/sf/answers/2225477481/ 中所述,但它没有用。

我加了

@Bean
public ServletContextInitializer servletContextInitializer() {
    return new ServletContextInitializer() {
        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
           servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
           SessionCookieConfig sessionCookieConfig=servletContext.getSessionCookieConfig();
           sessionCookieConfig.setHttpOnly(true);
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

但现在它只是 POST,设置 cookie,然后重定向回登录屏幕。就好像它无法访问会话一样。

我设置了server.session.tracking-modes=cookie(而不是server.servlet...)并且它现在只使用 cookie,但是 Chrome 浏览器在登录后没有将 cookie 发送回服务器!/home如果user会话中的属性为空,则操作只会重新显示登录页面。

POST /dologin HTTP/1.1
Host: localhost:8080
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
Referer: http://localhost:8080/home

HTTP/1.1 302
Set-Cookie: JSESSIONID=3B82AAA40CE94FF490FBF7B4DBD837DD; Path=/; HttpOnly
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Location: http://localhost:8080/home

GET /home HTTP/1.1
Host: localhost:8080
Upgrade-Insecure-Requests: 1
Referer: http://localhost:8080/home

HTTP/1.1 200
Set-Cookie: JSESSIONID=B60BF649068F7E85346691FD2F5D119B; Path=/; HttpOnly
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: text/html;charset=UTF-8
Content-Language: en-US
Content-Length: 2742
Date: Sat, 29 Sep 2018 17:41:55 GMT
Run Code Online (Sandbox Code Playgroud)

注意到 cookie 不同,Chrome 没有将 cookie 发送回服务器吗?为什么?

Spring Boot 1.5.13,Chrome 版本 69.0.3497.100(官方版本)(64 位)

Chl*_*loe 8

OK改变server.servlet.session.cookie.http-only=trueserver.session.tracking-modes=cookie和不断变化的http://localhost:8080,以http://127.0.0.1:8080/工作。我找到了这个答案:

未设置 Chrome 本地主机 cookie

似乎 Chrome 不断从允许localhost变为不允许localhost. 大约一三个月前它正在工作。localhost正在为 Rails 应用程序工作,而 Chrome 正在发送 cookie。

事实上,Chrome 也将_mt_rails_sessionRails cookie发送localhost到 Spring Boot 应用程序,但从未发送过JSESSIONIDcookie。

我怀疑,但尚未确认,这可能是由于在端口 8080 上为不相关的第三个 Spring Boot 应用程序设置了 HTTPS,并且 Chrome 内部可能缓存了一些 HSTS 设置。这可能是 Chrome 中的一个错误。

  • 谢谢你!不推荐使用的形式现在是 `server.servlet.session.tracking-modes=cookie` (2认同)