Skip to content

docs(embed): look up the sub-org on the server in the session example - #27

Merged
behobu merged 1 commit into
mainfrom
docs/server-side-sub-org-lookup
Dec 2, 2026
Merged

behobu merged 1 commit into
mainfrom
docs/server-side-sub-org-lookup

Conversation

@behobu

@behobu behobu commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Summary

The session example in USAGE.md read the sub-org id from the request body (Step 1), and the frontend sent currentUser.subOrgId (Step 2). Copied as-is, a signed-in customer could change that id in their browser and get a session for another customer's sub-org. The public SDK guide (/docs/sdks/embed/auth-tenancy) already says not to accept an org id from the browser as authority, so the package docs contradicted it.

  • Step 1: the backend resolves the sub-org from the signed-in user (getSignedInUser → lookUpMonadSubOrg), returning 401/404 when it can't, and sends a User-Agent header (requests without one can be blocked before they reach the API).
  • After Step 1: short notes on always sending organization_id, users who belong to several tenants (check membership server-side before minting), and session expiry (keep expires_at and remount before it).
  • Step 2: the frontend sends no sub-org id.
  • .changeset/server-side-sub-org-lookup.md: patch bump, so the corrected USAGE.md reaches npm.

Docs only; no code or exported API changes. The onError row is unchanged; the form doesn't yet report Test/Save failures to it, which is tracked as ENG-12581 and should be fixed in the form rather than in these docs.

Related: ENG-12581 (form doesn't report expired sessions via onError), ENG-12582 (/v3/sessions doesn't check organization_id against the key's access).

Test plan

  • pnpm format:check, pnpm typecheck, pnpm test (6/6) pass
  • pnpm lint: 0 errors (5 existing warnings, none in changed files)
  • Behaviour in the notes checked in production on 2026-12-01: an expired session shows "Invalid JWT: token has expired" in the form; a session minted without organization_id gets the key's full access
  • After merge, the changesets release PR publishes the patch version

🤖 Generated with Claude Code

The Step 1 example read the sub-org id from the request body, and the
Step 2 frontend sent currentUser.subOrgId. Copied as-is, that lets a
signed-in customer change the id in their browser and get a session for
another customer's sub-org. The public SDK guide (auth-tenancy) already
says not to accept an org id from the browser as authority.

The backend now resolves the sub-org from the signed-in user, and the
frontend sends no id. Also add a User-Agent header (requests without one
can be blocked before reaching the API) and short notes on always
sending organization_id, multi-tenant users, and session expiry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@behobu behobu self-assigned this Dec 1, 2026
@behobu
behobu requested a review from a team December 1, 2026 21:35

@Credgate Credgate left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice doc update 👍

@behobu
behobu merged commit c20cb2d into main Dec 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants