Skip to content

security: redact gateway tokens + avoid query-string auth leaks#274

Open
christniel39-glitch wants to merge 1 commit into
abhi1693:masterfrom
christniel39-glitch:security/harden-token-handling
Open

security: redact gateway tokens + avoid query-string auth leaks#274
christniel39-glitch wants to merge 1 commit into
abhi1693:masterfrom
christniel39-glitch:security/harden-token-handling

Conversation

@christniel39-glitch
Copy link
Copy Markdown

@christniel39-glitch christniel39-glitch commented Mar 13, 2026

Summary

This hardens token handling paths to reduce accidental credential disclosure in logs, URLs, and UI payloads.

What changed

  • Redacted gateway secrets from read APIs:
    • GatewayRead now returns has_token instead of raw token.
    • CRUD gateway endpoints map DB model -> safe read model.
  • Removed query-string token usage for gateway connectivity checks:
    • Added POST /api/v1/gateways/status/check (JSON body).
    • Frontend gateway connection checks now use this POST endpoint.
  • Kept status checks usable without exposing tokens:
    • Server resolves and reuses saved gateway token by URL when caller omits token.
  • Stopped URL token injection in gateway RPC URL builder:
    • auth token is kept in connect payload, not URL query.
  • Installer output hardening:
    • install.sh no longer prints LOCAL_AUTH_TOKEN in bootstrap summary.
  • Safer defaults/docs alignment:
    • backend/.env.example now sets secure header defaults (nosniff, DENY, strict-origin-when-cross-origin).
    • Security docs updated to reflect token redaction and POST status-check guidance.

Validation

  • Backend changed modules compile via py_compile.
  • Frontend builds successfully (npm run build).

Notes

  • This PR focuses on token-leak reduction and safer defaults, without changing deployment topology or auth mode semantics.

@christniel39-glitch
Copy link
Copy Markdown
Author

Follow-up from local security audit + hardening pass.

Recommended merge order:

  1. security: redact gateway tokens + avoid query-string auth leaks #274 (this PR): token-handling and leakage hardening
  2. security: bump clerk-backend-api and cryptography #275: dependency/security bump (clerk-backend-api + cryptography)

Why this order:

Both are designed to preserve current Mission Control UX while reducing risk.

@christniel39-glitch
Copy link
Copy Markdown
Author

@abhi1693 heads-up: this is ready for review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens gateway credential handling across the backend and frontend to reduce accidental token exposure (API payloads, URLs/query strings, logs, and installer output) while preserving gateway connectivity checks.

Changes:

  • Backend gateway read responses now redact secrets by returning has_token instead of token, and CRUD endpoints map DB models to the safe read schema.
  • Added POST /api/v1/gateways/status/check to move gateway status checks (including optional token) into a JSON body; server can reuse a saved token by gateway URL when omitted.
  • Removed token injection into gateway RPC URLs, updated frontend gateway UI to reflect token redaction, and hardened installer/docs/default security headers.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
install.sh Redacts LOCAL_AUTH_TOKEN from bootstrap summary output.
frontend/src/lib/gateway-form.ts Switches gateway connectivity check to POST JSON request via customFetch.
frontend/src/app/gateways/[gatewayId]/page.tsx Removes token usage in status params and displays token state via has_token.
frontend/src/app/gateways/[gatewayId]/edit/page.tsx Avoids pre-filling token; only sends token on update when explicitly edited.
frontend/src/api/generated/model/gatewayRead.ts Updates generated GatewayRead to use has_token instead of token.
docs/reference/security.md Documents token redaction + recommends POST status-check endpoint.
backend/app/services/openclaw/session_service.py Reuses stored gateway token server-side when caller omits token (resolved by URL).
backend/app/services/openclaw/gateway_rpc.py Stops appending auth tokens to gateway URLs (keeps auth in connect payload).
backend/app/schemas/gateways.py Changes read schema from token to has_token.
backend/app/schemas/gateway_api.py Adds request model for POST-based status checks.
backend/app/api/gateways.py Maps Gateway DB model → GatewayRead with has_token; updates list/create/get/update responses.
backend/app/api/gateway.py Adds POST /gateways/status/check endpoint using JSON body payload.
backend/.env.example Sets secure default values for common security response headers.

Comment on lines +96 to +103
const response = await customFetch<{
data: GatewaysStatusResponse;
status: number;
headers: Headers;
}>("/api/v1/gateways/status/check", {
method: "POST",
body: JSON.stringify(payload),
});
Comment on lines +103 to +104
gateways = [item for item in items if isinstance(item, Gateway)]
return [_to_gateway_read(gateway) for gateway in gateways]
Comment on lines 116 to 125
can_query_saved_gateway = organization_id is not None and hasattr(self.session, "exec")
if can_query_saved_gateway and (
params.gateway_allow_insecure_tls is None
or params.gateway_disable_device_pairing is None
or token is None
):
gateway_query = Gateway.objects.filter_by(url=raw_url)
if organization_id is not None:
gateway_query = gateway_query.filter_by(organization_id=organization_id)
gateway = await gateway_query.first(self.session)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants