【问题标题】:Spring Boot: RequestRejectedException: The request was rejected because the URL contained a potentially malicious String ";"Spring Boot:RequestRejectedException:请求被拒绝,因为 URL 包含潜在的恶意字符串“;”
【发布时间】:2019-03-05 02:28:05
【问题描述】:

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

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

它发布到/dologin,然后重定向到/home,并在末尾附加jsessionid。它也确实设置了会话 cookie。我没有更改任何会话设置,application.properties 中也没有提到session

我试着设置

server.servlet.session.cookie.http-only=true
server.servlet.session.tracking-modes=cookie

正如https://stackoverflow.com/a/31792535/148844 中提到的,但它不起作用。

我加了

@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);
        }
    };
}

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

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

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

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

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

【问题讨论】:

  • @dur 没有SpringSecurityConfiguration。你的意思是OAuth2Configuration extends AuthorizationServerConfigurerAdapter? OAuth2 正在工作。
  • 好吧,你说得对,只是Spring Boot的配置问题,你的方法不重要。
  • 尝试将属性改为server.session.tracking-modes,见docs.spring.io/spring-boot/docs/1.5.1.RELEASE/reference/…

标签: spring google-chrome spring-boot spring-security


【解决方案1】:

确定将server.servlet.session.cookie.http-only=true 更改为server.session.tracking-modes=cookie 并将http://localhost:8080 更改为http://127.0.0.1:8080/ 有效。我找到了这个答案:

Chrome localhost cookie not being set

Chrome 似乎一直在从允许 localhost 转向不允许 localhost。它大约在一三个月前开始工作。 localhost 正在为 Rails 应用程序工作,Chrome 正在发送 cookie。

事实上,Chrome 也会将 localhost_mt_rails_session Rails cookie 发送到 Spring Boot 应用程序,但不会发送 JSESSIONID cookie。

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

【讨论】:

  • 谢谢!未弃用的形式现在是 server.servlet.session.tracking-modes=cookie
  • 谢谢!这在使用带有基本 http 身份验证的 wkhtmltopdf 时也很有用。
猜你喜欢
  • 2022-10-23
  • 2021-08-10
  • 2021-11-17
  • 2019-03-27
  • 2019-07-28
  • 1970-01-01
  • 2018-07-05
  • 2018-08-24
  • 2018-11-30
相关资源
最近更新 更多