经过渗透测试,他们发现我需要将沙箱指令添加到内容安全策略中。 我有一个 4 框架的页面
<frameset rows="35,*,20" framespacing="0" border="0" frameborder="no">
<frame name="testata" scrolling="no" noresize src="top.asp" id="testata">
<frameset cols="260,*" id="framesetCentrale">
<frame name="funzioni" src="menu.asp" scrolling="auto" class="bordofrmdestra" id="funzioni">
<frame name="visualizza" src="visualizza.asp" scrolling="auto" id="visualizza">
</frameset>
<frame name="fondo" scrolling="no" noresize src="fondo.asp" id="fondo">
<noframes>
<body>
<p>La pagina corrente utilizza i frame. Questa caratteristica non è
supportata dal browser in uso. Aggiornate il vostro browser.</p>
</body>
</noframes>
</frameset>
如果我添加此指令,我无法单击框架 Visualizza 上的 td 来刷新框架 funzioni、Visualizza (本身)和 Fondo。
执行此操作的脚本位于框架可视化页面中:
$(document).on('click','#tabellaArchivi td', function() {
archivio = $(this).attr("id");
//parent.funzioni.location='menu.asp?sceltaarch=1&arc='+ archivio;
window.top.funzioni.location='menu.asp?sceltaarch=1&arc='+ archivio;
window.top.visualizza.location='visualizza.asp?arc='+ archivio;
window.top.fondo.location='fondo.asp?paginafunzioni=menu.asp?sceltaarch=1$arc='+ archivio +'&paginavisualizza=visualizza.asp?arc='+ archivio;
});
尝试了两种方法(parent.funzioni 或 window.top.funzioni)来刷新框架但不起作用。 当我点击 td 时,我收到了
visualizza.asp:26 Unsafe attempt to initiate navigation for frame with URL 'http://localhost/login/menu.asp' from frame with URL 'http://localhost/login/visualizza.asp'. The frame attempting navigation is sandboxed, and is therefore disallowed from navigating its ancestors.
(anonimo) @ visualizza.asp:26
dispatch @ jquery.js:2
v.handle @ jquery.js:2
visualizza.asp:26 Uncaught SecurityError: Failed to set the 'href' property on 'Location': The current window does not have permission to navigate the target frame to 'menu.asp?sceltaarch=1&arc=2-SILF Finanziamenti'.
at HTMLTableCellElement.<anonymous> (visualizza.asp:26:31)
at HTMLDocument.dispatch (jquery.js:2:40035)
at v.handle (jquery.js:2:38006)
我的实际 CSP,对于所有框架来说是:
frame-ancestors 'self'; default-src 'self'; script-src 'self' 'report-sample' 'nonce-****'; style-src 'self' 'report-sample' 'nonce-****'; object-src 'none'; frame-src 'self'; child-src 'self'; img-src 'self'; font-src 'self'; connect-src 'self'; manifest-src 'none'; base-uri 'self'; form-action 'self'; media-src 'self'; worker-src 'none'; upgrade-insecure-requests; report-uri https://xxx.report-uri.com/r/d/csp/reportOnly; report-to https://xxx.report-uri.com/r/d/csp/reportOnly; sandbox allow-scripts allow-popups allow-forms allow-modals allow-same-origin allow-top-navigation allow-top-navigation-by-user-activation allow-popups-to-escape-sandbox;
我尝试在没有成功的情况下添加沙箱的所有值,尝试在javascript代码中使用window.top.framename而不是parent.framename
我希望我可以刷新另一个框架。我的问题有解决办法吗?预先感谢
CSP 会阻止主页正确加载框架。因此,您需要通过将
iframe
的域添加到主页 CSP 的 frame-src
部分来编辑主页的 CSP。相反,您尝试编辑 iframe
的 CSP。
除此之外,您还需要编辑 iframe 页面的 CORS 标头,请参阅 https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS,特别是 Access-Control-Allow -起源,请参阅https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin