【发布时间】:2015-07-22 05:55:10
【问题描述】:
我复制了一些在 compojure 1.1.18 和其他旧库中运行的旧代码,但使用最新版本我无法让它运行。
这是我从 the minimal example here 复制的 minimal example code,以证明使用最新的 ring 和 compojure 库时,即使设置了标头,我在发送 http POST 时也会出错。
lein ring server 启动它,然后执行
curl -X GET --cookie-jar cookies "http://localhost:3000/" 会产生这样的结果:
{"csrf-token":"7JnNbzx8BNG/kAeH4bz1jDdGc7zPC4TddDyiyPGX3jmpVilhyXJ7AOjfJgeQllGthFeVS/rgG4GpkUaF"}
但是当我这样做时
curl -X POST -v --cookie cookies -F "email=someone@gmail.com" --header "X-CSRF-Token: 7JnNbzx8BNG/kAeH4bz1jDdGc7zPC4TddDyiyPGX3jmpVilhyXJ7AOjfJgeQllGthFeVS/rgG4GpkUaF" http://localhost:3000/send
我收到<h1>Invalid anti-forgery token</h1>
我做错了吗?
【问题讨论】:
-
在黑暗中拍摄,但使用反斜杠转义正斜杠(在令牌中)有什么不同吗?
-
谢谢! James Reeves / weavejester,compojure 和 maintainer of ring anti-forgery told me that the new
wrap-defaultsandsite-defaultsin thering-defaultspackage 的作者,替换了已弃用的 compojurehandler命名空间自动需要用于 HTTPPOST等人的 CSRF 令牌。所以我的代码生成了两次令牌,我验证了错误的令牌。我正在修复...
标签: clojure ring compojure csrf-protection