fix(security-scan): handle SecretRef gateway auth credentials#674
Open
NePav wants to merge 1 commit into
Open
Conversation
The gateway_auth check in runSecurityScan called .trim() directly on
gateway.auth.token / gateway.auth.password values. These fields may be
plain strings OR SecretRef objects ({source:"vault", ref:"op://..."},
{source:"file", path:"..."}, etc.), in which case .trim is not a function
and the entire scan crashes with:
TypeError: ((intermediate value) ?? "").trim is not a function
This made /api/security-audit and /api/security-scan return 500 for any
install using SecretRef-based gateway auth (a common pattern with vault
integrations).
Fix introduces a small hasCredential() helper that treats:
- string: trim and check length (original behavior)
- non-null object (SecretRef): credential is configured; resolution
happens at runtime by OpenClaw
Verified with pnpm typecheck and existing security-scan unit tests.
Reproduces with gateway.auth.token = { source: "file", path: "/path/to/token" }
or any other SecretRef shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a crash in
runSecurityScanwhengateway.auth.tokenorgateway.auth.passwordis a SecretRef object (e.g.{ source: 'vault', ref: 'op://...' },{ source: 'file', path: '/path/to/token' }) rather than a plain string. The current code calls.trim()directly on these values, which throws:This makes both
GET /api/security-auditandPOST /api/security-scanreturn HTTP 500 for any install using SecretRef-based gateway auth — a common pattern with vault integrations on OpenClaw 2026.5+. The /debug page surfaces it as "Security scan error" in the logs, and the Settings panel's "Run security scan" button silently fails.Repro
~/.openclaw/openclaw.jsonsnippet that triggers it:{ "gateway": { "auth": { "mode": "token", "token": { "source": "file", "path": "/Users/me/.openclaw/secrets/gateway-token" } } } }Click "Run security scan" in Settings → 500. Server logs show the TypeError above.
Fix
Introduces a small
hasCredential()helper in thegateway_authcheck that treats:If both branches fail (undefined / null), behavior is identical to before.
Test plan
pnpm typecheckcleanpnpm vitest run src/lib/__tests__/security-scan— 4/4 pass (existing tests still green; no behavior change for the string path they cover)gateway.auth.token,GET /api/security-auditnow returns 200 withgateway_auth: passinstead of 500gateway.auth.token, scan still returns the same pass/fail as beforegateway.auth.token = '', scan still returnsgateway_auth: failas beforegateway.authat all, scan still returnsgateway_auth: failas beforeNotes
gateway_authsecurity item is "is auth configured at all", which a SecretRef satisfies.