Is CORS a secure way to do cross-domain AJAX requests?

前端 未结 6 1617
天涯浪人
天涯浪人 2020-11-27 11:10

After reading about CORS (Cross-Origin Resource Sharing), I don\'t understand how it improves security. Cross-Domain AJAX communication is allowed if the correct ORIGIN head

6条回答
  •  情歌与酒
    2020-11-27 11:19

    I am late to answer but I don't think any post here really provides the sought answer. The biggest takeaway should be that the browser is the agent that is writing the origin header value. An evil script cannot write the origin header value. When the server responds back with a Access-Control-Allow-Origin header, the browser tries to ensure that this header contains the origin value sent earlier. If not, it triggers an error and does not return the value back to the requesting script. The other answers to this question present a good scenario to when you would like to deny an answer back to the evil script.

    @daniel f also provides a good answer to the question

提交回复
热议问题