我被卡住了,我花了幾乎整整一天的時間來解決這個問題。 我正在嘗試將csrf安全性集成到我們的網站,該網站使用了play framework 2.5.9和angularjs 1.x編寫的。我添加了csrf的東西,我試圖通過郵遞員測試。 雖然它的工作原理是將內容類型設置爲x-www-form-urlencoded,但在設置爲application/json時不起作用。它給了我不適用於json,但在Postman中使用urlencoding
Content-Length →0
Date →Tue, 14 Mar 2017 13:22:13 GMT
error →No CSRF token found for application/json body
和我的JSON是
{
"username": "admin",
"email": "admin",
"password": "123456",
"consumer": "consumer",
"csrfToken": "c29625a2c1c26bfbd4e74f6f6499d21f9a21aed-1489470934941-ae012aab7984ed13bfc697ea"
}
有什麼錯呢?我想念什麼? 任何幫助,感激。
編輯: 順便說一句, 當我加入以下行
X-Requested-With = "*"
Csrf-Token = "nocheck"
後方法適用於應用/ JSON內容類型在application.conf禁用CSRF檢查。
您是否嘗試過這樣做呢? https://playframework.com/documentation/2.5.x/SecurityHeaders你必須啓用過濾器才能使用它們 – pedroct92
其實這個鏈接真的是你需要的。 https://www.playframework.com/documentation/2.5.x/JavaCsrf#Adding-a-CSRF-token-to-the-session並檢查您的請求,如果您確實在請求的標頭上有令牌 – pedroct92
如上所述,我啓用了csrf和cors過濾器@ pedroct92 – FreeMan