- Location
- references/observability.md:501
- Finding
- External Error Reports Include Complete Request Headers<![CDATA[
## Vulnerability Details
**File Location**: `references/observability.md:501-516`
**Vulnerability Type**: Sensitive request data exposure through telemetry
**Risk Level**: High
### Vulnerable Code
```typescript
await fetch("https://errors.example.com/report", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${env.ERROR_TOKEN}`,
},
body: JSON.stringify({
error: {
message: error.message,
stack: error.stack,
name: error.name,
},
request: {
url: request.url,
method: request.method,
headers: Object.fromEntries(request.headers),
},
timestamp: Date.now(),
}),
});
```
### Technical Analysis
The error-reporting function serializes every inbound request header and sends the resulting data to an external service. Request headers commonly contain bearer tokens, cookies, API keys, signed authentication values, session identifiers, internal routing information, and tenant-specific metadata.
The complete request URL is also exported. Query strings may contain access tokens, password-reset tokens, signed links, personal information, or other sensitive parameters. Error messages and stack traces can disclose implementation details, internal file paths, data values, or service topology.
This collection exceeds what is normally required to diagnose an application error. Encoding the data as JSON does not protect it from disclosure to the receiving service.
### Attack Path
1. A user sends an authenticated request containing an `Authorization` header, session cookie, API key, or another secret-bearing header.
2. An error occurs while the request is processed.
3. The global error handler invokes the external reporting function.
4. The function converts all request headers into a plain object and includes them in the report.
5. The report is sent to `errors.example.com`.
6. Anyone with access to the external error platform, its storage, backups, logs, or
...[truncated 767 chars]
- Remediation
- <![CDATA[
## Remediation Suggestions
1. Replace complete-header serialization with a strict allowlist of non-sensitive diagnostic fields.
2. Never export `Authorization`, `Cookie`, `Set-Cookie`, `Proxy-Authorization`, API-key headers, CSRF tokens, or custom authentication headers.
3. Remove query strings and URL fragments before recording URLs.
4. Sanitize error messages and stack traces before external transmission.
5. Generate a request identifier and use it to correlate internal logs rather than exporting complete request context.
6. Apply field-length limits and structured schema validation to telemetry.
7. Document the external processor, retention period, access controls, encryption, and deletion policy.
8. Rotate credentials if historical error reports may already contain active secrets.
9. Add automated tests that inject canary secrets into headers and verify that none appear in generated reports.
For example:
```typescript
const url = new URL(request.url);
const report = {
error: {
name: error.name,
message: "Internal processing error",
},
request: {
origin: url.origin,
path: url.pathname,
method: request.method,
requestId: request.headers.get("CF-Ray"),
},
timestamp: Date.now(),
};
```
]]>