尝试 CSRF/XSRF 测试我们的网站 - 我可以使用 iframe POST 吗?
Trying to CSRF/XSRF test our website - can I use an iframe to POST?
我正在尝试测试我们网站中的特定 POST
端点是否受到 CSRF 攻击。
为此,我尝试使用 iFrame。当我 submit
整个页面重定向的形式。我的印象是 iFrame window 应该只提交表单,而不是 entire (root?) 文档?
示例代码...
<html>
<body>
<p>
<h3>CSRF Test.</h3>
<a href="#" onClick="crossDomainPost();">Click Me</a>
</p>
<form id="csrfForm" action="http://www.someWebsite/postTest" method="POST">
<snipped>
</form>
<iframe name="someiframe"></iframe>
<script type="text/javascript">
function crossDomainPost() {
var iframe = $('#someiframe');
var form = $('#csrfForm');
iframe.add(form);
// Submit the form in the iframe.
form.submit();
}
</script>
</body>
</html>
尝试将表单上的 target
设置为 iframe
<form id="csrfForm" action="url" method="POST" target="someiframe">
此外,如果您想使用 Javascript 来处理 post(因为表单可能 总是 想要定位 iFrame..
<-- No target attribute here -->
<form id="csrfForm" action="url" method="POST">
...
function crossDomainPost() {
var form = $('#csrfForm');
form[0].target = "someiframe";
form.submit();
}
(帽子提示:@charlietfl 和他在 OP 中的评论)。
我正在尝试测试我们网站中的特定 POST
端点是否受到 CSRF 攻击。
为此,我尝试使用 iFrame。当我 submit
整个页面重定向的形式。我的印象是 iFrame window 应该只提交表单,而不是 entire (root?) 文档?
示例代码...
<html>
<body>
<p>
<h3>CSRF Test.</h3>
<a href="#" onClick="crossDomainPost();">Click Me</a>
</p>
<form id="csrfForm" action="http://www.someWebsite/postTest" method="POST">
<snipped>
</form>
<iframe name="someiframe"></iframe>
<script type="text/javascript">
function crossDomainPost() {
var iframe = $('#someiframe');
var form = $('#csrfForm');
iframe.add(form);
// Submit the form in the iframe.
form.submit();
}
</script>
</body>
</html>
尝试将表单上的 target
设置为 iframe
<form id="csrfForm" action="url" method="POST" target="someiframe">
此外,如果您想使用 Javascript 来处理 post(因为表单可能 总是 想要定位 iFrame..
<-- No target attribute here -->
<form id="csrfForm" action="url" method="POST">
...
function crossDomainPost() {
var form = $('#csrfForm');
form[0].target = "someiframe";
form.submit();
}
(帽子提示:@charlietfl 和他在 OP 中的评论)。