Why are audio files (MP3) blocked by CORS? What's the security risk?

大城市里の小女人 提交于 2020-05-15 21:58:50

问题


Why do I need to set Access-Control-Allow-Origin to * for an MP3 file so that it can be loaded by websites of other domains? What's the security risk with this?

Or is it just to prevent other's from display content that you didn't authorize them to (assuming browsers support CORS)?


回答1:


Most video players are initialized using JS in script tags, and video is fetch through a XMLHttpRequest.

According to the docs:

For security reasons, browsers restrict cross-origin HTTP requests initiated from within scripts. For example, XMLHttpRequest and the Fetch API follow the same-origin policy. This means that a web application using those APIs can only request HTTP resources from the same domain the application was loaded from unless CORS headers are used.

So for security and to prevent data breach, CORS headers are required.



来源:https://stackoverflow.com/questions/47950470/why-are-audio-files-mp3-blocked-by-cors-whats-the-security-risk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!