【发布时间】: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