gpt4 book ai didi

javascript - 使用 <script src=.... 的跨框架脚本来查找站点的状态代码 - 安全问题?

转载 作者:行者123 更新时间:2023-11-30 18:31:24 25 4
gpt4 key购买 nike

我们有一个站点,其中 Iframe 指向动态 Urls(通过用户输入)。如果出现 404/500 或任何其他错误,我们希望将 Iframe 源替换为不同的用户友好的其他 URL。为此,我们可以使用 onerror 事件来识别动态网站何时出现问题。 (然后,如果出现问题,请替换 iframe 网址)这也适用于跨域 url,但是在某些情况下,动态 url 可能是恶意的,并且当恶意代码将在我们网站的同一框架、同一域中执行时,就会出现此类安全问题。

这个假设是否正确?有什么解决办法吗?还有其他建议吗?

谢谢,塔尔

最佳答案

we have a site with Iframes pointing to dynamic Urls (by user input). In case of a 404/500 or any other error, we want to replace the Iframe source with a different user friendly other URL.

所以听起来您正在制作一种“网页中的浏览器”。

For this we can use with the onerror event to identify when the dynamic websites have problems. (then, in case of problem replace the iframe url)

是的,除了没有多少东西 onerror 事件。我假设您从对其他答案的评论中了解到这一点。如果我理解正确的话,你是在谈论使用虚拟 script 元素首先加载 URL(作为脚本,即使它不是真正的脚本),并确定 URL 是否有效使用对 script 元素使用 onload/onerror 处理程序(onerror 不会在脚本错误时触发,只有网络错误)。

This works also for cross domain urls, however there might be a case where the dynamic url might be malicious and such security issue rises where the malicious code will execute in the same frame ,same domain of our website.

Is this assumption correct?

你的假设是正确的。如果 URL 实际上确实包含脚本,它将在与您的网站位于同一域的用户浏览器中执行。

Is there any solution for this?

一个简单的解决方法可能是做一些像 jsfiddle.net 所做的事情......有一个单独的子域作为第三方内容和您的真实域之间的“防火墙”。

Any other suggestions?

脚本预加载 hack 实际上就是一个 hack。它盗用脚本标签并提出不必要的请求。我可能会考虑使用 XHR 来触发 HEAD 请求,或者做一些轻型服务器端代理。

关于javascript - 使用 &lt;script src=.... 的跨框架脚本来查找站点的状态代码 - 安全问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9518661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com