How do I restrict JSON access?

前端 未结 8 605
时光取名叫无心
时光取名叫无心 2020-11-30 23:24

I have a web application that pulls data from my newly created JSON API.

My static HTML pages dynamically calls the JSON API via JavaScript from the static HTML page

相关标签:
8条回答
  • 2020-12-01 00:27

    Sorry, there's no DRM on the web :-)

    You can not treat HTML as a trusted client. It's a plain text script interpreted on other people's computers as they see fit. Whatever you allow your "own" JavaScript code do you allow anyone. You can't even define how long it's "yours" with Greasemonkey and Firebug in the wild.

    You must duplicate all access control and business logic restrictions in the server as if none of it were present in your JavaScript client.

    Include the service in your SSO, restrict the URLs each user has access to, design the service keeping wget as the client in mind, not your well behaved JavaScript code.

    0 讨论(0)
  • 2020-12-01 00:30

    In my opinion, you can't restrict the access, only make it harder. It's a bit like access-restriction by obscurity. Referrers can be easily forged, and even with the short-lived key a script can get the responses by constantly refreshing the key.

    So, what can we do?

    Identify the weakness here:

    http://www.example.com/json/getUserInfo.php?id=443

    The attacker now can easily request all user info from 1 to 1.000.000 in a loop. The weak point of auto_increment IDs is their linearity and that they're easy to guess.

    Solution: use non-numeric unique identifiers for your data.

    http://www.example.com/json/getUserInfo.php?userid=XijjP4ow

    You can't loop over those. True, you can still parse the HTML pages for keys for all kinds of keys, but this type of attack is different (and more easily avoidable) problem.

    Downside: of course you can't use this method to restrict queries that aren't key-dependent, e.g. search.

    0 讨论(0)
提交回复
热议问题