【发布时间】:2021-12-30 13:13:24
【问题描述】:
我正在 Django 中构建一个接受来自其他域的请求的后端,所以我使用 django-cors-headers 来处理 CORS。不过,我遇到了一个外部域访问我的后端的障碍,因为他们的请求代码 a) 设置了 withCredentials 并且 b) 在请求中有一些额外的标头。
这两者都应该与他们能够访问我的后端无关,但我得到了 Access-Control-Allow-Credentials' header in the response is '' which must be 'true' 和 Request header field [field_name] is not allowed by Access-Control-Allow-Headers in preflight response. 的预期错误。第二个,但我找不到太多关于最佳实践的信息。
我想弄清楚的是
- 设置这两个标志是否安全?请求中还包含其他通过令牌处理身份验证的标头,所以我不确定这里是否存在很多安全风险
- 我是否应该告诉我的用户我的后端不允许凭据和其他标头(因为它们不是代码工作所必需的)?
- Access-Control-Allow-Headers 的文档指定
‘The value “*” only counts as a special wildcard value for requests without credentials (requests without HTTP cookies or HTTP authentication information). In requests with credentials, it is treated as the literal header name “*” without special semantics. Note that the Authorization header can’t be wildcarded and always needs to be listed explicitly.’我是否认为我实际上无法同时设置Access-Control-Allow-Credentials = true和Access-Control-Allow-Headers = '*'?
【问题讨论】:
标签: django cors django-cors-headers