gateway: clear unbound scopes for trusted-proxy auth#57692
Conversation
Greptile SummaryThis PR extracts the inline unbound-scope-clearing predicate from
Confidence Score: 5/5Safe 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.
|
| 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
|
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. |
* gateway: clear unbound scopes for trusted-proxy auth * gateway: isolate trusted-proxy scope test branch
* gateway: clear unbound scopes for trusted-proxy auth * gateway: isolate trusted-proxy scope test branch
* gateway: clear unbound scopes for trusted-proxy auth * gateway: isolate trusted-proxy scope test branch
* gateway: clear unbound scopes for trusted-proxy auth * gateway: isolate trusted-proxy scope test branch
* gateway: clear unbound scopes for trusted-proxy auth * gateway: isolate trusted-proxy scope test branch
* gateway: clear unbound scopes for trusted-proxy auth * gateway: isolate trusted-proxy scope test branch
* gateway: clear unbound scopes for trusted-proxy auth * gateway: isolate trusted-proxy scope test branch
* gateway: clear unbound scopes for trusted-proxy auth * gateway: isolate trusted-proxy scope test branch
Summary
trusted-proxyconnects the same way token/password shared auth already does in this pathChanges
Validation
pnpm test -- src/gateway/server/ws-connection/connect-policy.test.tspnpm test -- src/gateway/server.auth.browser-hardening.test.ts -t "clears scopes for trusted-proxy non-control-ui browser sessions"claude -p "/review"and addressed the follow-up test coverage/comments it flaggedNotes
src/gateway/server.auth.control-ui.test.tstrusted-proxy case currently returnsCONTROL_UI_DEVICE_IDENTITY_REQUIREDbefore this helper is reached, so this change keeps validation scoped to the affected non-control-ui path