admin管理员组文章数量:1323547
API keys issued by your server have a CORS origin associated with them. When the server receives an API request, it retrieves the CORS origin from the API key sent in the custom header and performs CORS judgment. CORS judgment cannot be performed because a custom header (API key) is not sent during a preflight request.
As a solution, we are considering allowing any origin without performing CORS judgment when preflight request, and judgments based on the CORS origin associated with the API key during subsequent GET and POST requests. Are there any security issues?
API keys issued by your server have a CORS origin associated with them. When the server receives an API request, it retrieves the CORS origin from the API key sent in the custom header and performs CORS judgment. CORS judgment cannot be performed because a custom header (API key) is not sent during a preflight request.
As a solution, we are considering allowing any origin without performing CORS judgment when preflight request, and judgments based on the CORS origin associated with the API key during subsequent GET and POST requests. Are there any security issues?
Share Improve this question asked Jan 12 at 4:36 LAS JPLAS JP 31 bronze badge 1- Why do you need an API key in a browser? it can easily be stolen. If you want to prevent where your API is used, isn't checking the origin alone enough? – Evert Commented Jan 12 at 4:41
1 Answer
Reset to default 0Preflight requests exist to prevent pre-CORS web applications from becoming vulnerable due to the emergence of CORS.
Even without preflight requests, modern applications can block unauthorized requests on the application side by checking the Origin header in HTTP requests.
However, pre-CORS applications do not have such security features implemented.
The main attack vector enabled by dangerous requests is Cross-Site Request Fery (CSRF). While CSRF via POST requests should have been mitigated even before CORS, endpoints using methods like PUT or DELETE had no known attack vector before CORS. Therefore, there is a possibility that CSRF countermeasures are not implemented for endpoints using PUT or DELETE.
Simple requests, which are closely related to preflight requests, correspond to requests that can be sent via HTML forms. Other requests cannot be sent without CORS. Therefore, preflight requests exist to cover situations where developers might assume "This endpoint requires the PUT method. PUT method cannot be sent with HTML forms. Therefore, this endpoint does not require CSRF protection."
Therefore, for newly developed API endpoints, protection by preflight requests is not essential, and countermeasures can be implemented on the GET and POST endpoint bodies themselves.
However, is it really necessary to allow preflight requests for all origins?
本文标签: securityIssue with CORS origin linked to API keyStack Overflow
版权声明:本文标题:security - Issue with CORS origin linked to API key - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742122627a2421791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论