[Repo Assist] fix(security): apply TokenSanitizer to WSL diagnostic output - #300
Merged
shanselman merged 2 commits intoMay 10, 2026
Conversation
DiagnosticFormatter.SanitizeForDiagnostic and the engine-level SanitizeForDiagnostic only applied SecretRedactor.Redact, which catches key=value patterns (e.g. gateway-token=...) but not raw token formats that appear when a CLI tool echoes its arguments in an error message (e.g. 'auth failed with token <64-char-hex>'). Add a TokenSanitizer.Sanitize pass after SecretRedactor.Redact so that bare 64-char hex tokens and long base64url tokens in subprocess stdout/stderr are also redacted before they reach diagnostics logs or setup state. Addresses item #4 from issue #281 (token redaction gaps in failure diagnostics for the WSL local gateway onboarding path). Test coverage added: - LocalGatewaySetupSecretRedactorTests: 15 tests for the key-value redaction regex (gateway-token, bootstrap-token, setup-code, etc.) - LocalGatewaySetupDiagnosticFormatterTests: 7 tests for the full sanitization pipeline, including raw hex token in stderr Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
23 tasks
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
shanselman
marked this pull request as ready for review
May 10, 2026 22:06
Collaborator
|
Validated locally on Windows after latest changes: \.\build.ps1, \dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore, and \dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore\ all passed. Note: build.ps1 still reports the existing Windows 10 SDK detection warning, but the build completed successfully. |
shanselman
deleted the
repo-assist/fix-diagnostic-token-sanitization-2026-05-09-2ae27281bd1bbc56
branch
May 10, 2026 22:16
30 tasks
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.
🤖 Repo Assist — automated AI assistant.
Summary
DiagnosticFormatter.SanitizeForDiagnostic(and the engine-level copy) applied onlySecretRedactor.Redact, which uses a regex that matches key=value patterns (gateway-token=...,bootstrap-token=..., etc). It did not cover raw token formats that appear when a CLI tool echoes its own arguments in an error message, for example:TokenSanitizeralready hasBareGatewayHexTokenPattern([0-9a-f]{64}) andLongBase64UrlPattern([A-Za-z0-9_-]{43}) that catch these. The fix simply chains both sanitizers together.Root cause
Both
SanitizeForDiagnosticmethods (lines ~730 and ~1150 inLocalGatewaySetup.cs) ended afterSecretRedactor.Redact.TokenSanitizer.Sanitizewas already used elsewhere in the file (line 2159) for the same purpose but was missing from the diagnostic path.Fix
Both
SanitizeForDiagnosticcopies updated identically.Relation to issue #281
This addresses item #4 from issue #281:
The
--tokenflag value itself is a CLI argument handled byRedactArgument, which replaces the whole argument. The gap this PR closes is raw tokens that appear in subprocess error output (stdout/stderr), not in the argument list.Test Status
New tests added (24 total):
LocalGatewaySetupSecretRedactorTests(15 tests) — key-value patterns:gateway-token=,bootstrap-token=,device-token:,auth-token=,setup-code=,setup_code=,secret:,private-key=; case-insensitive; non-secret text unchanged; empty stringLocalGatewaySetupDiagnosticFormatterTests(7 tests) — exit code included; stdout/stderr included; empty stdout/stderr omitted; key-value gateway token in stdout redacted; raw 64-char hex token in stderr redacted ← the new scenario; long output truncated; null bytes strippedBaseline comparison (Linux runner):
dotnet test OpenClaw.Tray.Tests --no-restore— 718 passed / 7 pre-existing failures / 1 skipped (was 694/7/1 before; same 7 pre-existing failures, 24 new passing tests)dotnet test OpenClaw.Shared.Tests --no-restore— all passed ✅ (exit code 0)build.ps1— requires Windows; infrastructure limitation on Linux runner