javascript - 内容安全策略不允许提交表单

标签 javascript jquery forms google-chrome content-security-policy

我在这里需要帮助。 我有一个表单要提交到另一个 url,但是当我尝试提交它时,它拒绝提交,我正在检查我的控制台。

在 Chrome 上,我看到以下错误

resources2.aspx?HCCID=75694719&culture=en-US&mlcv=3006&template=5:7 Refused to load the image 'https://s4.mylivechat.com/livechat2/images/sprite.png' because it violates the following Content Security Policy directive: "img-src 'self' data:".

Refused to send form data to 'https://cipg.stanbicibtcbank.com/MerchantServices/MakePayment.aspx' because it violates the following Content Security Policy directive: "form-action 'self'".

在 Mozilla Firefox 上,我看到以下内容:

Content Security Policy: The page’s settings blocked the loading of a resource at https://s4.mylivechat.com/livechat2/images/sprite.png (“img-src http://smehelp.themarketplace.ng data:”)

Content Security Policy: The page’s settings blocked the loading of a resource at http://smehelp.themarketplace.ng/purchase/summary (“form-action 'self'”).

在网上寻找解决方案,我已将以下内容添加到我的页眉

        <meta http-equiv="Content-Security-Policy" content="form-action 'self'">

但问题依然存在。

这导致我无法提交表格。早些时候,表单曾经被提交过,但我今天刚试了一下,发现了这个错误。

我在 MAC 操作系统上运行 Google Chrome 版本 55.0.2883.95(64 位)。

对于尽快解决此问题的任何建议,我将不胜感激。

谢谢

最佳答案

如果你看这里是因为你想发送一个表单到相同的 URL(这应该可以通过 form-action 'self')或你的 form-action 中列出的另一个 URL 规则,但之后重定向,以下可能是原因 https://github.com/w3c/webappsec-csp/issues/8 (包括长时间的讨论)。原因之一是:https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html

重定向的目标 url 在 CSP 报告中不可见的原因(这确实令人困惑)是一个安全问题,请参阅 https://w3c.github.io/webappsec-csp/#create-violation-for-request , 否则就可以分析表单端点的行为。

tl:dr; 除非目标 URL 列在表单操作 CSP 规则中,否则 Chrome 和 Safari 不允许在提交表单后进行重定向,即使它是不包含原始表单数据的 GET 重定向也是如此。

关于javascript - 内容安全策略不允许提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41942834/

相关文章:

Javascript 重新加载以加载新实例而不重新加载页面

javascript - 如何获得 AABB 顶点的三 Angular 形?

javascript - HTML/JS : Delete a form?

jquery - html/jquery组合输入类型: text within radio

javascript - 将类更改为可编辑的表格单元格

javascript - While 循环在 JavaScript 中永远运行

jquery - 什么是好的 jQuery timePicker?

javascript - window.onbeforeunload - 仅在未提交表单时显示警告

javascript - jQuery 未找到使用 AJAX 加载的元素

javascript - 在javascript中接收只有一个元素的表单数组时出现问题