# 内部错误：gRPC-Web：源 http://example.com 的 CORS 预检因凭据标志失败

- **ID:** `grpc/grpc-web-cors-credentials`
- **领域:** grpc
- **类别:** config_error
- **错误码:** `ECORS`
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

浏览器强制执行 CORS 预检检查失败，因为当客户端发送 withCredentials: true 时，服务器未包含 Access-Control-Allow-Credentials 标头。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Envoy v1.29.0 | active | — | — |
| gRPC-Web v1.4.2 | active | — | — |
| gRPC-Web v1.5.0 | active | — | — |
| Istio v1.21.0 | active | — | — |

## 解决方案

1. ```
   配置代理（Envoy/NGINX）显式返回 Access-Control-Allow-Credentials: true 和 Access-Control-Allow-Origin: http://example.com。
   ```
2. ```
   如果 RPC 不需要身份验证，从客户端移除 `withCredentials: true`。
   ```

## 无效尝试

- **Disabling CORS entirely in the browser** — Browsers enforce CORS; it cannot be disabled by client code. (99% 失败率)
- **Adding Access-Control-Allow-Origin: * only** — With credentials, the origin must be explicit, not wildcard. (90% 失败率)
