Repository navigation
feat(api): WS attach accepts OIDC JWTs, not just API keys (closes #807) - #809
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesTenant-aware WS attach authentication
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
…PI keys The WebSocket `/attach` proxy (`BoxliteWsProxyService`) authenticated upgrades only as an API key, so a browser/OIDC login (JWT) — which works for REST — was rejected 401 on the attach upgrade and cloud `exec` output never streamed. Closes #807. `authenticate` now falls through to JWT when the bearer is not an API key: verify via the existing `JwtStrategy.verifyToken` (same JWKS/issuer/audience as the HTTP path; no hand-rolled verification), map `sub`/`uid` like `JwtStrategy.validate`, take the organization from the URL `{prefix}` tenant (`ATTACH_PATH` now captures it), and require org membership — identical to the API-key path and to the membership-only HTTP exec/attach routes. Mirrors current behavior exactly: membership-only (no permission gate — there is no box:exec permission and the HTTP path enforces none), no rate-limiting, and a JWT with no/`default` tenant is rejected (org ambiguous for a multi-org user). `JwtStrategy` is nullable under `skipConnections`; `authenticate` never throws so the fire-and-forget upgrade caller can't leak a hung socket. Security boundary (cross-org box access) — please review.
b7059ac to
259eeba
Compare
What
The API's WS
/attachproxy authenticated upgrades only as an API key, so abrowser/OIDC login (Auth0 JWT) — which works for REST — was rejected 401 on the
attach upgrade and cloud
execoutput never streamed. Closes #807. (PR #804already made the CLI surface this loudly instead of a silent
exit 0.)Change
BoxliteWsProxyService.authenticatenow falls through to JWT when the bearer isnot an API key:
JwtStrategy.verifyToken(same JWKS/issuer/audience asthe HTTP path — no hand-rolled verification),
sub/uidlikeJwtStrategy.validate,{prefix}tenant (ATTACH_PATHnow captures it),Mirrors current behavior exactly (per scope discussion): membership-only — no
permission gate (there is no
box:execpermission and the HTTP exec/attach routesenforce none), no rate-limiting, and a JWT with no/
defaulttenant is rejected(org ambiguous for a multi-org user).
JwtStrategyis nullable underskipConnections;authenticatenever throws, so the fire-and-forget upgradecaller can't leak a hung socket.
Verification
boxlite-ws-proxy.service.spec.ts: API-key regression + JWTmember / non-member / cross-org / no-tenant / invalid-token / skipConnections /
uid-claim, plusmatchAttachPathtenant capture. Verified RED→GREEN (the JWTacceptance + membership-check tests fail when the JWT path is neutered).
nx test apigreen (140 tests).Cross-org access boundary. The membership check
organizationUserService.findOne(urlTenant, userId)is what stops a JWT userattaching to boxes in an org they don't belong to — please scrutinize that and
the URL-tenant extraction.
Summary by CodeRabbit
Bug Fixes
/attachupgrade authentication by adding tenant-aware routing and validating both API keys and JWTs with correct precedence.Tests