Skip to content

Add baseline HTTP security headers to gateway responses#6906

Closed
QuantumEdu wants to merge 1 commit intoopenclaw:mainfrom
QuantumEdu:security/baseline-http-headers
Closed

Add baseline HTTP security headers to gateway responses#6906
QuantumEdu wants to merge 1 commit intoopenclaw:mainfrom
QuantumEdu:security/baseline-http-headers

Conversation

@QuantumEdu
Copy link
Copy Markdown

@QuantumEdu QuantumEdu commented Feb 2, 2026

Summary

  • Add a centralized setSecurityHeaders() helper in http-common.ts that applies four OWASP-recommended headers to every HTTP response
  • Call it early in handleRequest() in server-http.ts, covering all gateway endpoints (hooks, tools, OpenAI, Control UI, etc.)

Headers added

Header Value Purpose
X-Content-Type-Options nosniff Prevents MIME-sniffing attacks
X-Frame-Options SAMEORIGIN Mitigates clickjacking when CSP is absent
Referrer-Policy same-origin Limits referrer leakage to same origin
Permissions-Policy camera=(), microphone=(), geolocation=() Disables unused browser features

All four headers are additive and non-breaking. They follow the baseline set proposed in #6675.

Test plan

  • Start gateway with node dist/index.js gateway
  • curl -sI http://localhost:18789/ and verify all four headers are present
  • Confirm Control UI, SSE streams, and API endpoints all include the headers
  • Run existing test suite to verify no regressions

Addresses part of #6675.

Generated with Claude Code

Greptile Overview

Greptile Summary

This PR introduces a centralized setSecurityHeaders() helper (src/gateway/http-common.ts) and invokes it near the top of the gateway HTTP request handler (src/gateway/server-http.ts) so that most gateway endpoints consistently emit a baseline set of OWASP-recommended response headers (nosniff, frame options, referrer policy, and a restrictive permissions policy). This aligns response hardening across the various HTTP handlers (hooks, tools, OpenAI/OpenResponses, Control UI, etc.) without having to duplicate header setting logic in each endpoint.

Confidence Score: 4/5

  • This PR is generally safe to merge; it adds standard response headers with minimal behavioral impact.
  • Changes are small and localized (one helper + one call site). The only notable gap is that the early return for WebSocket upgrades means the new headers won’t cover the 101 handshake, which may conflict with the stated goal of applying headers to every gateway response.
  • src/gateway/server-http.ts (WebSocket upgrade early return)

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Apply four OWASP-recommended security headers to every HTTP response
from the gateway server:

- X-Content-Type-Options: nosniff (prevents MIME-sniffing)
- X-Frame-Options: SAMEORIGIN (mitigates clickjacking)
- Referrer-Policy: same-origin (limits referrer leakage)
- Permissions-Policy: camera=(), microphone=(), geolocation=()

Headers are set centrally in handleRequest() before routing, ensuring
coverage across all endpoints (hooks, tools, OpenAI, Control UI, etc.).

Addresses part of openclaw#6675.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@openclaw-barnacle openclaw-barnacle bot added the gateway Gateway runtime label Feb 2, 2026
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 2, 2026

Additional Comments (1)

src/gateway/server-http.ts
[P1] WebSocket upgrade path now skips all response header hardening.

handleRequest() returns early for Upgrade: websocket, so the baseline security headers won’t be applied to the 101 Switching Protocols handshake. If the intent is “every gateway response”, this is a gap for any WS clients (e.g., Control UI/web sockets) and is easy to miss because the function name/comment says “every response”.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/gateway/server-http.ts
Line: 238:244

Comment:
[P1] WebSocket upgrade path now skips all response header hardening.

`handleRequest()` returns early for `Upgrade: websocket`, so the baseline security headers won’t be applied to the 101 Switching Protocols handshake. If the intent is “every gateway response”, this is a gap for any WS clients (e.g., Control UI/web sockets) and is easy to miss because the function name/comment says “every response”.

How can I resolve this? If you propose a fix, please make it concise.

@mudrii

This comment was marked as spam.

@openclaw-barnacle
Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Mar 7, 2026
@openclaw-barnacle
Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #pr-thunderdome-dangerzone on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants