Skip to content

[AI-assisted] fix(gateway): sanitize error responses to prevent information disclosure#2387

Merged
thewilloftheshadow merged 1 commit intoopenclaw:mainfrom
robbyczgw-cla:fix/issue-2383-error-detail-leak
Jan 26, 2026
Merged

[AI-assisted] fix(gateway): sanitize error responses to prevent information disclosure#2387
thewilloftheshadow merged 1 commit intoopenclaw:mainfrom
robbyczgw-cla:fix/issue-2383-error-detail-leak

Conversation

@robbyczgw-cla
Copy link
Contributor

Summary

Replaces raw error messages with a generic Internal Server Error response to prevent leaking internal error details to HTTP clients.

Problem

The catch block in src/gateway/server-http.ts (line 297) returns String(err) directly to clients:

} catch (err) {
  res.statusCode = 500;
  res.end(String(err));  // ← Exposes internal error details
}

This code path is reachable before authentication (e.g., if loadConfig() throws), meaning unauthenticated users can receive internal error messages that may leak:

  • File paths
  • Config structure
  • Stack traces

Solution

} catch (err) {
  res.statusCode = 500;
  res.end("Internal Server Error");  // Generic message
}

Error details are still logged server-side for debugging.

Testing

  • ✅ Build passes (pnpm build)
  • ✅ Linter passes (pnpm lint)
  • 🔍 Lightly tested - verified fix compiles and error path returns generic message

AI Disclosure

This PR was AI-assisted (Claude/Codex). The issue was discovered through automated code analysis, and the fix was verified to compile correctly.

Fixes #2383

@paragon-review
Copy link

Paragon Review Unavailable

Hi @robbyczgw-cla! To enable Paragon reviews on this repository, please register at https://home.polarity.cc

Once registered, connect your GitHub account and Paragon will automatically review your pull requests.

@openclaw-barnacle openclaw-barnacle bot added the gateway Gateway runtime label Jan 26, 2026
Replace raw error messages with generic 'Internal Server Error' to prevent
leaking internal error details to unauthenticated HTTP clients.

Fixes #2383
@robbyczgw-cla robbyczgw-cla force-pushed the fix/issue-2383-error-detail-leak branch from 40fd6ff to deea834 Compare January 26, 2026 21:10
@thewilloftheshadow thewilloftheshadow self-assigned this Jan 26, 2026
@thewilloftheshadow thewilloftheshadow merged commit 5aa02cf into openclaw:main Jan 26, 2026
17 of 23 checks passed
s4na added a commit to s4na/openclaw that referenced this pull request Jan 30, 2026
## Why

The OpenAI-compatible API endpoints (`openai-http.ts`, `openresponses-http.ts`)
were returning raw `String(err)` in error responses. This can leak sensitive
internal information to HTTP clients:

- Stack traces revealing code structure
- File paths exposing server directory layout
- Internal error messages from dependencies

This is the same class of vulnerability that was fixed in openclaw#2387 for
`server-http.ts`, but these OpenAI-compatible endpoints were missed.

## What

Replace `String(err)` with safe error messages:

- **500 errors (api_error)**: Return generic "Internal server error"
- **400 errors (invalid_request_error)**: Return `err.message` only
  (no stack trace), with fallback to "Invalid request"

## Changes

- `src/gateway/openai-http.ts`: 2 catch blocks sanitized
- `src/gateway/openresponses-http.ts`: 4 catch blocks sanitized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Error details leaked to unauthenticated clients in HTTP handler

2 participants