直接结论
浏览器收到的响应没有授权当前 Origin;应分别检查 OPTIONS 与真实响应,而不是在所有地方盲目添加通配符。
错误出现在哪里
浏览器 fetch、XMLHttpRequest、字体、模块与 API 网关
根本原因
业务路由、预检处理、重定向目标、代理错误页或凭据策略可能缺少或返回不兼容的 Allow-Origin。
最小复现
CORS
Access to fetch at 'https://api.example.com' from origin 'https://app.example.com' has been blocked by CORS policy修正示例
修复后
Allow only the intended Origin and methods at the API or gateway, handle OPTIONS before authentication when appropriate, and return consistent CORS headers on errors and final responses.验证修复
终端
使用 HTTP / CORS 检查工具,以浏览器真实 Origin 分别检查 OPTIONS 和实际方法。还需要检查
- curl 成功不代表浏览器 CORS 会通过。
- 凭据请求不能使用 Allow-Origin: *。
- 重定向后的最终响应可能使用不同策略。