# Starlette CORS中间件错误：无效的CORS来源

- **ID:** `python/starlette-multiple-cors-origins`
- **领域:** python
- **类别:** auth_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

CORS中间件配置了允许的来源列表，但请求的Origin头不在列表中，导致被拒绝。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Add the exact origin to `allow_origins` list, or use a regex pattern with `allow_origin_regex`.
   ```
2. **** (90% 成功率)
   ```
   If credentials are needed, cannot use wildcard; use specific origins.
   ```

## 无效尝试

- **** — Adding the origin to the list after the request doesn't help because the middleware checks at request time. (90% 失败率)
- **** — Using wildcard `*` with credentials is not allowed in browsers, so it fails for credentialed requests. (85% 失败率)
