简体   繁体   English

jQuery Ajax安全问题

[英]Jquery Ajax security concerns

I have been using Jquery Ajax calls in several projects. 我在几个项目中一直在使用Jquery Ajax调用。 I'm wondering if these calls to the server are not secure? 我想知道对服务器的这些调用是否不安全? Consider something like following, 考虑下面的事情,

   $.ajax({
            method: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            url: "/CMSWebParts/vline/Serviceupdates/ServiceUpdate.aspx/EditPlannedDisruption",
            data: '{"id":"' + id + '"}',
            success: function (res) {
            $("#hdnOverrideId_PlannedDisruption").val(res.d.PlannedDisruptionId);

                $("#edTime2_PublishPlanned").val(res.d.pubtime2);
                if (res.d.Proposed) {
                    $("#chkProposed").prop("checked", true);
                }

                if (res.d.Active) {
                    $("#chkActive").prop("checked", true);
                }

                if (res.d.LinkedOverrideId || res.d.LinkedOverrideId != "null") {
                    $("#btnlinkedOverride").hide();
                    $("#linkedOverride").hide();
                }

            }

        })

If the user checks the browser source he can see this whole code including server method names and parameter names and it provides opportunities for the hackers. 如果用户检查了浏览器源,则他可以看到包括服务器方法名称和参数名称在内的整个代码,这为黑客提供了机会。

are there any security measures I am missing here? 我在这里缺少任何安全措施吗?

Well, the only thing you should worry about is encrypting the data you are sending to the server and the data that you receive from the server. 好吧,您唯一需要担心的就是对发送到服务器的数据以及从服务器接收的数据进行加密。 You can't do pretty much anything for code inspection on the browser. 您无法在浏览器上做任何检查代码的事情。

Let me explain a little. 让我解释一下。 When someone visits your web page, they already have everything you have designed to work in the browser. 当某人访问您的网页时,他们已经拥有了您可以在浏览器中使用的所有功能。 You can't do anything about this. 您对此无能为力。 You can try to make it a little bit more daunting to get around (minification) but accept that someone will have access to your client-side code. 您可以尝试使其变得更艰巨,以至于无法解决(最小化),但要接受有人可以访问您的客户端代码。

The real problem is the data that passes through the wire. 真正的问题是穿过电线的数据。 See, if a hacker inspected the code in his browser, he wouldn't get a lot of useful information (unless you make some obvious mistakes yourself). 看,如果黑客检查了浏览器中的代码,他将不会获得很多有用的信息(除非您自己犯了一些明显的错误)。 Sure, they can see where the requests go and what the parameters are to various endpoints. 当然,他们可以查看请求的去向以及各个端点的参数。 But a properly secured back-end will not even let them send requests to these endpoints without proper authentication and authorization. 但是,如果没有适当的身份验证和授权,则具有适当保护的后端甚至不会允许它们将请求发送到这些端点。

Hackers are also interested in capturing other people's details. 黑客也有兴趣在获取其他人的详细信息。 A very obvious case is usernames and passwords. 一个非常明显的例子是用户名和密码。 If you send this data over the wire without proper encryption, that is the real problem. 如果您在没有适当加密的情况下通过网络发送此数据, 那将是真正的问题。

In short, there's not a lot you can do to protect your source code that runs on the browser. 简而言之,您可以采取很多措施来保护运行在浏览器上的源代码。 The interested party has whatever they need already and JS does not lend itself to obfuscation. 感兴趣的一方已经拥有了他们所需的一切,并且JS不会使自己陷入混乱。 You should be much more interested in securing the data that passes over the wire. 您应该对确保通过网络传输的数据更感兴趣。

If the user checks the browser source he can see this whole code including server method names and parameter names and it provides opportunities for the hackers. 如果用户检查了浏览器源,则他可以看到包括服务器方法名称和参数名称在内的整个代码,这为黑客提供了机会。

So, yes any attacker can learn how your application works from an external perspective. 因此,是的,任何攻击者都可以从外部角度了解应用程序的工作方式。

This is why you should ensure your application is secure despite any user being able to work how your application server communicates with the browser. 这就是为什么即使任何用户都可以使用应用程序服务器与浏览器进行通信的方式,也应确保应用程序安全的原因。

You need to prevent: 您需要防止:

  • Attackers gaining access to your server, despite knowing which URLs, methods and parameters are passed. 攻击者尽管知道传递了哪些URL,方法和参数,但仍可以访问您的服务器。
  • Attackers targeting other users of your application through your application (eg stored XSS). 攻击者通过您的应用程序(例如存储的XSS)将您的应用程序的其他用户作为目标。
  • Attackers targeting other users of your application through their browser (eg reflected XSS, CSRF and other cross-origin attacks - see Same Origin Policy ). 攻击者通过他们的浏览器将您的应用程序的其他用户作为目标(例如,反射的XSS,CSRF和其他跨域攻击-参见Same Origin Policy )。
  • Attackers abusing the privileges granted to them on their account. 攻击者滥用在其帐户上授予他们的特权。
  • Countless other attack vectors from being leveraged. 利用了无数其他攻击媒介。

are there any security measures I am missing here? 我在这里缺少任何安全措施吗?

Check out the OWASP Top 10 for a starting point of vulnerabilities that you should be securing your application against. 请查看OWASP Top 10 ,以获取应该保护应用程序安全的漏洞的起点。

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

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