该方案是用户选择某个产品,然后单击进行付款。在这里,我将他/她重定向到IPG(银行的互联网支付网关),并在付款完成后通过我的返回网址并最终确定采购订单。在我添加弹簧安全性之前,每件事情都可以正常工作。
但是如果在某个内部视图中发布此网址,那么每件事情都会再次正常工作。
这是正常工作(弹簧安全启用,一切都工作正常)
<form:form method="post" name="saleform" id="saleform"
action="http://localhost:8080/Click2Pay/salecomplete">
<input class="btn btn-primary" type="submit" value=" SaleComplete "
id="btnsalecomplete" name="btnsalecomplete" />
</form:form>
@RequestMapping(value = "/salecomplete", method = RequestMethod.POST)
public String salecomplete(HttpServletRequest request,
HttpServletResponse response, Model m)
throws
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/admin/**" access="hasRole('admin')" />
<access-denied-handler error-page="/403" />
<form-login login-page="/login" default-target-url="/admin/admin"
authentication-failure-url="/login?error" username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" />
<!-- enable csrf protection -->
<csrf />
</http>
<authentication-manager>
<authentication-provider user-service-ref="UserAuthenService">
<password-encoder hash="sha" />
</authentication-provider>
</authentication-manager>
在浏览器中查看银行IPG来源(https://pna.shaparak.ir/CardServices/paymentSuccess.html)
<form action="http://localhost:8080/Click2Pay/salecomplete"
method="post" autocomplete="off">
<div class="commandBar">
<input type="hidden" name="redirectURL" id="redirectURL"
value="http://localhost:8080/Click2Pay/salecomplete" />
<input type="hidden" name="MID" id="MID" value="01134254" />
<input type="hidden" name="ResNum" id="ResNum" value="162" />
<input type="hidden" name="RefNum" id="RefNum"
value="00000000021278797788" /> <input type="hidden"
name="CustomerRefNum" id="CustomerRefNum" value="421320082083" />
<input type="hidden" name="State" id="State" value="OK" /> <input
type="hidden" name="language" id="language" value="fa" /> <input
type="hidden" name="CardPanHash" id="CardPanHash"
value="417bf6657c3830d051b4e9bab45203508c386787d4c083244c4dbac82bd559b8" />
<input type="submit" value="تکمیل خرید"
class="button btn btn-success btn-lg" name="Submit" />
<input type="button" value="لغو خرید"
class="button btn btn-default btn-lg" name="cancelButton"
id="cancelButton" onclick="document.forms['returnForm'].submit();" />
</div>
</form>
问题是什么?
答案 0 :(得分:1)
如果银行网站回复到您的应用程序,那么这就是跨站点请求,银行需要银行表格中不存在的csrf令牌。尝试临时禁用csrf保护以进行验证。
解决方案将是:
通过为csrf protected urls提供自定义请求匹配器来禁用该特定请求的CSRF保护:
<csrf request-matcher-ref="someRequestMatcher" />
完全关闭CSRF保护(这会使其工作但会使应用程序容易受到CSRF攻击)