Skip to content

gateway: clear unbound scopes for trusted-proxy auth#57692

Merged
jacobtomlinson merged 2 commits into
openclaw:mainfrom
jacobtomlinson:fix/fix-99
Mar 30, 2026
Merged

gateway: clear unbound scopes for trusted-proxy auth#57692
jacobtomlinson merged 2 commits into
openclaw:mainfrom
jacobtomlinson:fix/fix-99

Conversation

@jacobtomlinson

Copy link
Copy Markdown
Contributor

Summary

  • extract the unbound-scope clearing decision into a dedicated ws-connect policy helper
  • clear self-declared scopes for device-less trusted-proxy connects the same way token/password shared auth already does in this path

Changes

  • update the ws message-handler to use the shared helper when deciding whether to wipe unbound scopes
  • add policy-level coverage for token, password, trusted-proxy, preserve, and reject branches

Validation

  • Ran pnpm test -- src/gateway/server/ws-connection/connect-policy.test.ts
  • Ran pnpm test -- src/gateway/server.auth.browser-hardening.test.ts -t "clears scopes for trusted-proxy non-control-ui browser sessions"
  • Ran local agentic review with claude -p "/review" and addressed the follow-up test coverage/comments it flagged

Notes

  • Residual risk or follow-up: a targeted src/gateway/server.auth.control-ui.test.ts trusted-proxy case currently returns CONTROL_UI_DEVICE_IDENTITY_REQUIRED before this helper is reached, so this change keeps validation scoped to the affected non-control-ui path

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Mar 30, 2026
@greptile-apps

greptile-apps Bot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extracts the inline unbound-scope-clearing predicate from message-handler.ts into the dedicated helper shouldClearUnboundScopesForMissingDeviceIdentity and, in doing so, plugs a gap: authMethod === "trusted-proxy" was not previously listed alongside "token" and "password", so device-less trusted-proxy connects could retain self-declared scopes. The refactoring is clean and the helper is straightforward to reason about.

  • The new helper correctly returns true on any non-allow decision (short-circuit), and on the allow path only when none of the explicit preservation guards apply.
  • Strict === true on the optional trustedProxyAuthOk boolean is safe; every call site derives it from isTrustedProxyControlUiOperatorAuth, which always returns a proper boolean.
  • Test coverage is solid for all five named branches; one minor gap: the trustedProxyAuthOk: true assertion piggy-backs on authMethod: "token" which already makes the condition true, so the trustedProxyAuthOk branch isn't truly isolated (see inline comment).

Confidence Score: 5/5

Safe to merge; the only finding is a minor test-isolation suggestion with no impact on production behaviour.

All remaining feedback is P2 (test-quality style). The logic change is correct, the extraction is clean, and the targeted non-control-UI trusted-proxy scope-clearing behaviour is now consistent with token/password auth.

No files require special attention.

Important Files Changed

Filename Overview
src/gateway/server/ws-connection/connect-policy.ts Adds shouldClearUnboundScopesForMissingDeviceIdentity helper, extending scope-clearing to cover authMethod === "trusted-proxy" (the new behaviour) alongside the existing token/password/trustedProxyAuthOk conditions. Logic is correct; the === true strict check on the optional boolean is safe given call sites always supply a proper boolean.
src/gateway/server/ws-connection/message-handler.ts Replaces the inline scope-clearing predicate with the new helper. The call site correctly threads all five parameters; no semantic change other than what the helper itself introduces.
src/gateway/server/ws-connection/connect-policy.test.ts Adds a new test covering token, password, trusted-proxy, preserve, and reject branches. Minor gap: the trustedProxyAuthOk: true assertion doesn't isolate that condition (authMethod: "token" is already sufficient), but all targeted behaviors are otherwise validated.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/server/ws-connection/connect-policy.test.ts
Line: 344-352

Comment:
**`trustedProxyAuthOk: true` test case doesn't isolate the branch**

The fourth assertion pairs `authMethod: "token"` with `trustedProxyAuthOk: true`. Because `authMethod === "token"` is already sufficient to return `true`, `trustedProxyAuthOk` has no observable effect in this test – dropping it wouldn't change the result. To actually exercise the `trustedProxyAuthOk === true` leaf of the OR condition, the authMethod should be something that matches none of the explicit strings (e.g. `"none"` or `undefined`):

```suggestion
    expect(
      shouldClearUnboundScopesForMissingDeviceIdentity({
        decision: { kind: "allow" },
        controlUiAuthPolicy: nonControlUi,
        preserveInsecureLocalControlUiScopes: false,
        authMethod: undefined,
        trustedProxyAuthOk: true,
      }),
    ).toBe(true);
```

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

Reviews (1): Last reviewed commit: "gateway: clear unbound scopes for truste..." | Re-trigger Greptile

Comment thread src/gateway/server/ws-connection/connect-policy.test.ts
@jacobtomlinson

Copy link
Copy Markdown
Contributor Author

Follow-up: the latest head commit updates the test to isolate the trusted proxy boolean branch by setting authMethod to undefined while trustedProxyAuthOk is true.

@jacobtomlinson
jacobtomlinson merged commit 8b88b92 into openclaw:main Mar 30, 2026
8 checks passed
@jacobtomlinson
jacobtomlinson deleted the fix/fix-99 branch March 30, 2026 13:19
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
* gateway: clear unbound scopes for trusted-proxy auth

* gateway: isolate trusted-proxy scope test branch
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
* gateway: clear unbound scopes for trusted-proxy auth

* gateway: isolate trusted-proxy scope test branch
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
* gateway: clear unbound scopes for trusted-proxy auth

* gateway: isolate trusted-proxy scope test branch
Tardisyuan pushed a commit to Tardisyuan/openclaw that referenced this pull request Apr 30, 2026
* gateway: clear unbound scopes for trusted-proxy auth

* gateway: isolate trusted-proxy scope test branch
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
* gateway: clear unbound scopes for trusted-proxy auth

* gateway: isolate trusted-proxy scope test branch
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
* gateway: clear unbound scopes for trusted-proxy auth

* gateway: isolate trusted-proxy scope test branch
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* gateway: clear unbound scopes for trusted-proxy auth

* gateway: isolate trusted-proxy scope test branch
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
* gateway: clear unbound scopes for trusted-proxy auth

* gateway: isolate trusted-proxy scope test branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant