1. 程式人生 > >Spring Security 4.x 啟用CSRF防禦後logout只能是POST請求

Spring Security 4.x 啟用CSRF防禦後logout只能是POST請求

學習Spring Security時碰到這個問題

官方原文:

18.5.3 Logging Out

Adding CSRF will update the LogoutFilter to only use HTTP POST. This ensures that log out requires a CSRF token and that a malicious user cannot forcibly log out your users.

譯:新增CSRF將更新LogoutFilter以僅使用HTTP POST。這樣可以確保log out 請求需要CSRF令牌並且惡意使用者無法偽造你的log out 請求。

One approach is to use a form for log out. If you really want a link, you can use JavaScript to have the link perform a POST (i.e. maybe on a hidden form). For browsers with JavaScript that is disabled, you can optionally have the link take the user to a log out confirmation page that will perform the POST.

一種方法是使用表單登出。 如果你真的想要一個連結,你可以使用JavaScript讓連結執行POST(也許在一個隱藏的表單)。對於禁用JavaScript的瀏覽器,您可以選擇包含使用者到登入確認頁面的連結,這將執行POST。

If you really want to use HTTP GET with logout you can do so, but remember this is generally not recommended. For example, the following Java Configuration will perform logout with the URL /logout is requested with any HTTP method:

如果你真的想使用HTTP GET與登出,你可以這樣做,但記住這是一般不推薦。 例如,以下Java配置將執行登出,使用任何HTTP方法請求URL /登出:

@EnableWebSecurity
public class WebSecurityConfig extends
WebSecurityConfigurerAdapter {

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http
			.logout()
				.logoutRequestMatcher(new AntPathRequestMatcher("/logout"
)); } }

相關推薦

Spring Security 4.x 啟用CSRF防禦logout只能POST請求

學習Spring Security時碰到這個問題 官方原文: 18.5.3 Logging Out Adding CSRF will update the LogoutFilter to only use HTTP POST. This ensures tha

upgrade to Spring-Security 4.X的登入問題

升級到4.2.3後,登入出現 HTTP Status 403 - Could not verify the provided CSRF token because your session was not found sec http裡面需要增加: <sec:hea

Spring Security 4.x -> 5.x 踩坑記錄

1. AuthenticationManager無法自動注入 在實現AbstractAuthenticationProcessingFilter重寫以使用者名稱、密碼認證時,需要顯示注入AuthenticationManager,不然會報如下錯誤: Caus

Spring Security 4.X xml配置重定向

<!-- 後臺許可權控制 @PreAuthorize --> <global-method-security pre-post-annotations="enabled" /> <form-login login-page="/login

Spring Security 4 退出再登入,頁面停留在登入頁,Url卻多了一個Logout引數

spring security 4 的logout問題 今天在整合spring-boot 和 spring-security的時候,出現瞭如下的怪象: 配置好了基本的登入和身份驗證(自定義了一個簡單的UserDetailsService),springboo

spring security 4.1.x入門

許可權控制在網頁開發中是很重要的一部分,最基本的就是用form進行賬號密碼的認證,更復雜的可能控制的粒度會更細一些,spring securty相關的資訊在網上可以搜到很多,入門的例程更是多不勝數,但是在我學習瞭解的過程中,卻發現沒有一個簡單易懂的,給學習之路帶

Spring Security 4.2.3 Filters 解析

其中 validate ali 配置 生命 擁有 path str support 一、 熟悉一個模塊的最快方法 1. 配置logback文件,打印相應的debug信息 2. 根據相應的信息,打斷點查看執行結果 二、spring 使用 DelegatingFilterP

spring security 5.x 入門及分析

Java Web專案的許可權管理框架,目前有兩個比較成熟且使用較多的框架,Shiro 和 Spring Security ,Shiro 比 Spring Security更加輕量級,但是需要手動配置的東西較多,Spring Security 和 Spring 整合更好,甚至直

spring security 5.x 使用及分析(二:自定義配置—初階)

二、自定義配置(初階): 自定義的配置,就要修改一些預設配置的資訊,從那開始入手呢? 1、第一步:建立Spring Security 的Java配置,改配置建立一個名為springSecurityFilterChain的servlet過濾器,它負責應用程式的安

Spring Security 4.2.2 一些注意事項

1.配置檔案中的http標籤變為security:http2.security:http上的屬性use-expressions="false",如果未這麼宣告,那麼在子節點中security:intercept-url的access中直接使用角色名,則會報錯Field or

Spring Security 4 (03)—— 資源資訊

序言 這一篇主要是講資源的載入和認證 1.記憶體載入 <security:http auto-config="false" use-expressions="false" &g

Spring Security 4 整合Hibernate 實現持久化登入驗證(帶原始碼)

【相關已翻譯的本系列其他文章,點選分類裡面的spring security 4】 本教程將使用Spring Security 4 和hibernate向你展示持久化登入驗證. 在持久化登入驗證中,應用通過session記住使用者特徵。 一般來說,在登入介面,當你

Spring Security 4 安全檢視片段 使用標籤(Spring Security 標籤)

下一篇文章: 【剩餘文章,將盡快翻譯完畢,敬請期待。 翻譯by 明明如月 QQ 605283073】 本教程向你展示怎樣建立安全檢視層,Spring MVC web 應用中,使用Spring Security 標籤,基於使用者角色顯示或者隱藏部分jsp或

Spring MVC 4.X ResponseBody 日期型別Json 處理

方法一:全域性處理 <mvc:annotation-driven>       <!-- 處理responseBody 裡面日期型別 -->           <mvc:message-converters>             

spring security 4.1兩個不錯功能介紹

一轉眼, spring security 已經發布4.1 了,檢視 了下新特性,有兩個比較值得關注: 1) 可以在pathvariable形式的URL中進行保護了   比如有個方法: [code="java"] public class WebSecurity {publi

Spring Security 4 整合Hibernate Bcrypt密碼加密(帶原始碼)

【相關已翻譯的本系列其他文章,點選分類裡面的spring security 4】 【 翻譯by 明明如月 QQ 605283073】 上一篇文章: Spring Security 4 Hibernate整合 註解和xml例子(帶原始碼) 本教程演示 使用 Spri

spring security 4.0 教程 步步深入 5

5. Java 配置 在Spring 3.1中向Spring框架添加了對Java配置的常規支援。 自Spring Security 3.2以來,一直有Spring Security Java配置支援,使使用者能夠輕鬆地配置Spring Security而不使用

Spring Security 4.0 CAS實現單點登入

1、各framework版本資訊       JDK 8       Tomcat 7       SpringMVC-4.2.0.RELEASE       Spring Security 4.2.0.RELEASE       CAS-Client 3.3.3       CAS-Serv

Spring Security 4.2.10 過濾器順序

aware ESS ember ssi sap war 協議 exce basic spring security 的版本為4.2.10。文檔章節13.3。文檔原文 無論是否使用這些過濾器,總的順序如下: 順序 名稱 功能 1 ChannelProcessi

基於註解配置的spring mvc 4 + spring security 4例項與解析

關於spring security 4(以下簡稱SS) ,我們不能不否認,學習的成本是挺高的。如果光光是複製配置程式碼而不去理解SS的各個元件的實現原理和功能,那當然還是相當簡單的一回事,因為配置的程式碼就那麼幾行 PS:本人不是大神,寫部落格只是為了增強記憶