# ValueError: CORS preflight request failed

- **ID:** `python/starlette-cors-middleware`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Starlette 的 CORSMiddleware 配置不正确，例如 allow_origins 未包含请求来源。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   app.add_middleware(CORSMiddleware, allow_origins=['http://localhost:3000'], allow_methods=['*'], allow_headers=['*'])
   ```
2. **** (80% success)
   ```
   allow_origin_regex='https?://.*'
   ```

## Dead Ends

- **** — 浏览器不允许通配符与凭证同时使用。 (90% fail)
- **** — 预检请求会失败因为未允许 OPTIONS。 (60% fail)
