简体   繁体   English

保护JSON服务

[英]Securing JSON services

I have a website that heavily uses JSON calls from jQuery to web services hosted in the same web domain. 我有一个网站,该网站大量使用从jQuery到同一Web域中托管的Web服务的JSON调用。 Many calls are made from the public pages that don't require visitors to login. 许多呼叫都是从公共页面发出的,不需要访问者登录。

It appears that I can replay these JSON calls using Fiddler, which is a big problem, since now a malicious user can capture a Fiddler trace just by opening my site and then, all bets are off, who knows what he/she can do. 看来我可以使用Fiddler重播这些JSON调用,这是一个大问题,因为现在恶意用户可以通过打开我的网站来捕获Fiddler跟踪,然后所有赌注都消失了,谁知道他/她可以做什么。

Is there a way to secure a web service, so only those JSON calls that are made from the site's pages are allowed on the server? 有没有一种方法可以保护Web服务,因此服务器上仅允许从站点页面进行的JSON调用? I am using ASP.NET MVC on the backend. 我在后端使用ASP.NET MVC。

Thank you. 谢谢。


Thank you all for contributing to this topic. 谢谢大家对这个话题的贡献。 I have a follow up question: 我有一个后续问题:

What about SSL? SSL呢? If I placed all my services in a folder secured with SSL, would that be a catch-all solution (at the expense of performance)? 如果我将所有服务放在使用SSL保护的文件夹中,那将是一个万能的解决方案(以性能为代价)吗? Thanks. 谢谢。

The answer is No. The user can always simulate HTTP Requests made by the browser. 答案是否定的。用户始终可以模拟浏览器发出的HTTP请求。 So have to code your back end in such a way that it should be able to handle all the exceptions and malicious attempts. 因此,必须以某种方式对后端进行编码,使其应该能够处理所有异常和恶意尝试。

  1. Use nonce for all your requests. 使用nonce满足您的所有请求。 This might be tricky to implement but is the one of the most important thing that could come in my mind. 这可能很难实现,但这是我想到的最重要的事情之一。

  2. Track User Agent and negate all requests that come from non standard browsers. 跟踪用户代理并否定来自非标准浏览器的所有请求。

  3. Check Referrer and make sure it is coming for the expected page or atleast from the same domain 检查引荐来源网址,并确保它来自同一域的预期页面或其他页面

  4. Include a tracking session/cookie variable to keep a track 包含跟踪会话/ cookie变量以保持跟踪

However, all of these things can be evaded so the best bet is to make your back end system more secure to handle any user input. 但是,可以避免所有这些事情,因此最好的选择是使您的后端系统更安全地处理任何用户输入。

I would suggest to authenticate each JSON service request. 我建议对每个JSON服务请求进行身份验证。 Ex- Passing a access_token 传递access_token

Each service request must be verified against the user accessing. 每个服务请求都必须针对用户访问进行验证。 Does he have the right to access this service/data? 他是否有权访问此服务/数据?

Same thing should be done for guest users. 对来宾用户应该执行相同的操作。 Only limited services/data should be exposed to guest user. 只有有限的服务/数据应向来宾用户公开。

Take inspiration from facebook API. 从facebook API中汲取灵感。

There are multiple ways to check the validness of a JSON call and each gives you multiple level of security: 检查JSON调用的有效性的方法有多种,每种方法都为您提供了多个安全级别:

  • Check that the Referer HTTP-header contains the URL of your site. 检查Referer HTTP标头是否包含您网站的URL。 That gives you basic security so your calls won't be accessible for regular users through Fiddle, for example 这样可以为您提供基本的安全性,例如,普通用户将无法通过Fiddle来访问您的电话
  • If the content of the JSON was generated server side, then you can sign the json content so only those calls will be accepted that you have previously generated at server side. 如果JSON的内容是在服务器端生成的,那么您可以对JSON内容进行签名,以便仅接受以前在服务器端生成的那些调用。 Check out JSON Web Token (JWT) for example. 例如,请查看JSON Web令牌(JWT)。
  • If the JSON content was not generated at server side, you can still issue one time "tickets" that has to be present along each JSON call. 如果JSON内容不是在服务器端生成的,您仍然可以发出每次在JSON调用中必须出现的一次性“票证”。 You have to check the validness of the ticket at server side, and that the ticket was used only once. 您必须在服务器端检查票证的有效性,并且该票证仅使用了一次。

Regarding the follow-up question: 关于后续问题:

SSL only secures the connection between the browser and your server, ie nobody can inspect the communication between the two. SSL仅保护浏览器和服务器之间的连接,即没有人可以检查两者之间的通信。 (A man in a middle for example who might change the content of the call along the way.) It doesn't prevent an attacker to make his own JSON calls. (例如,中间的一个人可能会在此过程中更改调用的内容。)这并不阻止攻击者进行自己的JSON调用。 The difference will be that his calls are encrypted and cannot be inspected by anyone else but your server. 不同之处在于,他的呼叫已加密,除您的服务器外,其他任何人都无法检查。

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

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