简体   繁体   English

通过 ajax 加载 HTML 和 js 是否安全?

[英]Is it safe to load HTML and js via ajax?

I'm using the Jquery load function $('#result').load('test.php');我正在使用 Jquery 加载 function $('#result').load('test.php'); to load a page into another page by clicking a tab.通过单击选项卡将页面加载到另一个页面。 The page I'm loading contains javascript, php, and contains a form.我正在加载的页面包含 javascript、php,并包含一个表单。 Using the firebug console I saw that there is a GET for all my script sources in the page I'm loading as well.使用萤火虫控制台,我看到我正在加载的页面中的所有脚本源都有一个GET Not sure if that should be a concern..不知道这是否应该是一个问题..

Can data be hacked via the jquery load?可以通过 jquery 负载入侵数据吗? Are there any issues to consider?有什么问题需要考虑吗?

note: I'm aware that old browsers don't work with javascript but is there anything else to consider?注意:我知道旧浏览器不能与 javascript 一起使用,但还有什么需要考虑的吗?

Loading content using AJAX does not introduce any additional security issues.使用 AJAX 加载内容不会引入任何额外的安全问题。

An attacker can hijack the connection and inject his own Javascript (unless you're using HTTPS), but he can also do that to the page itself.攻击者可以劫持连接并注入他自己的 Javascript(除非您使用 HTTPS),但他也可以对页面本身执行此操作。

An attacker can exploit an XSS hole in your backend to run his own Javascript, but he can also do that to the page itself.攻击者可以利用您后端的 XSS 漏洞来运行他自己的 Javascript,但他也可以对页面本身执行此操作。

So long as your site isn't compromised, a XHR to your own data is inherently no more dangerous than any other request.只要您的网站没有受到损害,您自己的数据的 XHR 本质上并不比任何其他请求更危险。

It really depends on how well you trust the source of the scripts.这实际上取决于您对脚本来源的信任程度。 If you control them then there's no (additional) issue.如果你控制它们,那么就没有(额外的)问题。 If you're getting them from somewhere else (like jQuery from Google's CDN, for example) you're trusting that source.如果您从其他地方获取它们(例如,来自 Google 的 CDN 的 jQuery),那么您就是信任该来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM