javascript - Why shouldn't the server respond with a JSON Array?

后端 未结 2 617
醉话见心
醉话见心 2021-01-28 15:29

According to this Angular 2 guide:

Don\'t expect the decoded JSON to be the heroes array directly. This server always wraps JSON results in an object wit

2条回答
  •  长发绾君心
    2021-01-28 16:12

    This was rather bad advice that has since been removed from the angular tutorial.

    1. The linked OWASP Cheet Sheet lists three ways to defend against JSON Hijacking. The one the tutorial picked is the hardest to implement correctly, because one must educate every single developer, and audit every single REST resource, rather than writing a single HttpInterceptor to extend CSRF-defenses to GET requests.
    2. JSON hijacking can only occur due to browser bugs, which tend to be fixed quickly (this does not imply such attacks are impossible, but the easy exploits no longer work in modern browsers)

提交回复
热议问题