Skip to content

fix(integrations): keep a connector's routing state off the pod read - #1731

Merged
lilyshen0722 merged 3 commits into
mainfrom
kai/b1-routing-state-redaction
Sep 18, 2026
Merged

lilyshen0722 merged 3 commits into
mainfrom
kai/b1-routing-state-redaction

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What

GET /api/integrations/:podId answers every member of the pod, and returned each row whole. chatId, linkedUserId, relayMap and messageBuffer are a connector's routing state — where a reply lands, and the identity inbound messages are authored as — not the pod's content, so a member of a shared pod could read another member's connector to that depth.

Viewer projection. withoutRoutingState / withRoutingState in backend/models/integrationPublicConfig.ts. The connector's creator and an instance administrator get the row whole; every other member gets linked (derived from chatId) and keeps chatTitle. Applied in the route (backend/routes/integrations.ts), not inline at a call site, and to the toJSON() output so the existing credential strip still runs.

linked is written on both paths — the owner's own view reads it too, or a connected connector would render as unconnected for its owner (one reader, one field).

Server-owned keys. relayMap, messageBuffer and webhookListenerEnabled join SERVER_OWNED_CONFIG_KEYS. The bridges write all three; a client body that sets one names a destination or starts a listener the caller was never granted.

Frontend. ChatRoom.tsx's four config.chatId reads move to config.linked — it was the only chatId reader in src, and no frontend test asserts it or those status strings. Frontend suite run at this head, before Vera's read: 108/108 suites, 877/877 tests (cd frontend && npm test -- --watchAll=false; npm ci installed clean in this clone). Three paths feed telegramIntegration and all three read correctly: the projected pod list (gets linked), existingIntegration (from that same list), and the POST-create response, which carries none — correct, since a connector is unbound until the chat binds.

Proof

  • backend/__tests__/unit/routes/integrations.routingState.test.js — 5/5 on real Integration/Pod/User rows over memory Mongo, so the real toJSON transform and the projection both run: member read redacted (with accessToken still stripped), creator read whole, admin read whole, an unbound connector reported as linked: false rather than absent, and a write body carrying the three keys persisted without them.
  • Security + integrations route suites: 208/208.
  • npm run lint:ts: 0 errors.

No leak-matrix rows are added (Wren 69288): KNOWN_EXPOSURES is empty on main so there was no row to shrink, and seeding routing sentinels would add 8 ALLOWED_DISCLOSURES rows for readers that are exempt by design — surface without a check. The dedicated suite above is the guard instead.

Scope

Ported from the recovered pre-switch work at Wren's spec (69283). The rest of that stash was superseded by main and is not here: credential strip, pod access (canViewPod/isPodMember), pod-keyed gates, relayMap.podId, bridge chatType, mintConnectCode, stripServerOwnedConfig.

Review fix: the write routes echo the row too (e0d7a393)

Vera (69314/69315): the pod read was right, but the redaction had a second read path. PATCH /api/integrations/:id is authorised by canDeleteIntegration, which also admits the pod's creator — who may not have created the connector. It returned res.json(updated) whole, so a no-op PATCH ({ isActive: true }) handed that member chatId, linkedUserId, relayMap and messageBuffer back.

Fixed in this commit, plus the same defect one route over:

  • PATCH /:id and POST /:id/connect-code now return projectConnectorForViewer(row, viewer), the same projection as the pod read. The connect-code echo shares both the gate and the shape (canDeleteIntegration); it is narrower — it 409s once a chat is bound — but linkedUserId is written when live relay flips on, which can precede the bind. The minted code still comes back to the member who minted it: the code is what they came for and it is not routing state.
  • One viewer, one place. resolveConnectorViewer (admin/creator resolution) and projectConnectorForViewer (the projection) are shared by all three responses, so the read and write gates cannot drift into disagreeing about who sees routing state.
  • The agent-runtime integrations route was checked and is safe (it whitelists channel/group fields only).

Tests (integrations.routingState.test.js, now 8/8): a pod creator who is not the connector's creator PATCHes another member's pod-scoped row → linked: true, chatTitle kept, no chatId/linkedUserId/relayMap/messageBuffer, accessToken still stripped; the connector's creator gets the row whole from the same PATCH; the connect-code re-mint by that pod creator returns the code with linkedUserId gone and linked: false.

Mutation check: restoring the unprojected res.json(updated) on PATCH fails 2 of the 8.

Placement (Wren 69319): the projection lives with the rest of the Integration JSON contract — projectIntegrationForViewer(row, { requesterId, isAdmin }) in backend/models/integrationPublicConfig.ts. The route keeps only the admin/creator lookup (resolveConnectorViewer) and the three call sites, so a fourth echo cannot appear without meeting the same helper.

Frontend is untouched by these commits — frontend/src/components/ChatRoom.tsx is still blob 1de62ca5, so the owner pair posted against c0ce84fe still binds to the shipped file, and the 877/877 frontend result carries.

UI evidence: the pair that shows the change (Wren 69321)

The owner pair proves inertness; the redacted view is the only place this PR changes pixels, so it gets a second pair. Viewer = the pod's creator, who is not the connector's creator; connector bound with no chatTitle, so the swapped text is what renders.

main (origin/main) branch (fa6d9537)
card status line Chat -1001234567890 Telegram chat connected
dialog state line Connected to chat -1001234567890. Connected to this chat.

Both shots at 1440×900; image blobs 6121784587… (before) and 8e43b91f32… (after, a distinct file). Source blobs: ChatRoom.tsx 65bc2359 → 1de62ca5; routes/integrations.ts 43ef4477 → eeb3cfda. The backend differs between these two shots as well as the component — main returns chatId to that member and the branch returns linked — which is the change itself, not a held-constant.

Verification at fa6d9537: routingState 8/8 (incl. the PATCH-echo and connect-code-echo guard); model integrationPublicConfig 10/10 (4 new viewer-projection cases); integrations route + model + security tier 18 suites / 215 tests; two-way-integration-e2e 23/23 (Node 20); npm run lint:ts 0 errors.

GET /api/integrations/:podId answers every member of the pod, and returned each
row whole: chatId, linkedUserId, relayMap and messageBuffer are the bridge's
routing state — where a reply lands, and the identity inbound messages are
authored as — not the pod's content. A member of a shared pod could read
another member's connector to that depth.

withoutRoutingState / withRoutingState in integrationPublicConfig project the
row for the viewer. The connector's creator and an instance administrator see
it whole; every other member gets `linked` (derived from chatId, so no surface
branches on an id it is no longer given) and keeps chatTitle. ChatRoom's four
chatId reads move to `linked`, including for the creator, who needs the flag on
both paths.

relayMap, messageBuffer and webhookListenerEnabled join
SERVER_OWNED_CONFIG_KEYS: the bridges write all three, and a client body that
sets one names a destination or starts a listener the caller was never granted.

Tests: integrations.routingState.test.js, real Integration/Pod/User rows on
memory Mongo so both the toJSON credential strip and the projection run —
member read redacted, creator and admin reads whole, an unlinked connector
reported as linked: false, and a write body carrying the three server-owned
keys persisted without them.
The pod read redacted a connector's routing state; PATCH /:id and the
connect-code re-mint echoed the row whole to anyone canDeleteIntegration
admits, which includes the pod's creator — who may not have created the
connector. Both now go through the same viewer projection as the pod read,
resolved by one shared helper so the two gates cannot drift apart.
Wren 69319: the projection belongs with the Integration JSON contract, so a
fourth echo cannot appear without noticing. projectIntegrationForViewer(row,
{ requesterId, isAdmin }) lives in integrationPublicConfig.ts; the route keeps
only the admin/creator lookup and the three call sites.
@lilyshen0722
lilyshen0722 merged commit be324c3 into main Sep 18, 2026
24 of 25 checks passed
samxu01 pushed a commit that referenced this pull request Sep 18, 2026
A change whose acceptance is visual has no tier today: jsdom has no layout
engine, so a card that still shows the field it should redact and a flex bug
that clips a row both pass every render test. PR #1731 needed before/after
evidence for exactly that and the recipe lived in one seat's shell history.

The runbook records the path that cost real time to rederive, all of it
measured on this machine rather than read off the code:

- the backend's CORS allow-list IS FRONTEND_URL, so every frontend port you
  serve must be in it or the app looks broken (CORS + net::ERR_FAILED rather
  than a layout bug);
- REACT_APP_API_URL is baked in via an explicit vite `define` — no env var at
  runtime will move it — and it must be set because the localhost fallback is
  :5000, which AirPlay owns on some machines;
- the repo `.env` is the source of truth for the PG user the container was
  initialised with; the compose defaults authenticate as a role that does not
  own the DB and the API answers `degraded` rather than failing;
- a before/after pair needs the base revision in a worktree, and that worktree
  needs `server.fs.allow` covering BOTH the worktree root (realpath — /tmp is
  /private/tmp) and the checkout the symlinked node_modules point at, or every
  webfont 403s and the two screenshots differ for the wrong reason;
- which viewer you capture as is the test: the integration's creator sees the
  routing state in both revisions, a member who is not the creator sees the fix.

scripts/ui-evidence-shot.mjs writes a full-page PNG and a body.innerText dump,
and prints non-2xx responses and console errors. The text dump is the evidence
— a text-only agent cannot read the PNG — and the worked example is a one-line
diff plus a three-field payload table.

Docs plus one script; no product code.
lilyshen0722 added a commit that referenced this pull request Sep 18, 2026
…es (#1739)

* docs(runbooks): local UI render harness, and the script it uses

A change whose acceptance is visual has no tier today: jsdom has no layout
engine, so a card that still shows the field it should redact and a flex bug
that clips a row both pass every render test. PR #1731 needed before/after
evidence for exactly that and the recipe lived in one seat's shell history.

The runbook records the path that cost real time to rederive, all of it
measured on this machine rather than read off the code:

- the backend's CORS allow-list IS FRONTEND_URL, so every frontend port you
  serve must be in it or the app looks broken (CORS + net::ERR_FAILED rather
  than a layout bug);
- REACT_APP_API_URL is baked in via an explicit vite `define` — no env var at
  runtime will move it — and it must be set because the localhost fallback is
  :5000, which AirPlay owns on some machines;
- the repo `.env` is the source of truth for the PG user the container was
  initialised with; the compose defaults authenticate as a role that does not
  own the DB and the API answers `degraded` rather than failing;
- a before/after pair needs the base revision in a worktree, and that worktree
  needs `server.fs.allow` covering BOTH the worktree root (realpath — /tmp is
  /private/tmp) and the checkout the symlinked node_modules point at, or every
  webfont 403s and the two screenshots differ for the wrong reason;
- which viewer you capture as is the test: the integration's creator sees the
  routing state in both revisions, a member who is not the creator sees the fix.

scripts/ui-evidence-shot.mjs writes a full-page PNG and a body.innerText dump,
and prints non-2xx responses and console errors. The text dump is the evidence
— a text-only agent cannot read the PNG — and the worked example is a one-line
diff plus a three-field payload table.

Docs plus one script; no product code.

* docs(runbooks): the local .env is untracked — make one before sourcing it

Vera, on #1739: `.env` is not tracked, only `.env.example` is. That is right, and
it made the first command in the runbook fail on a fresh clone while the prose
pointed the reader at a file that does not exist ("the repo .env", "already in
.env").

- new step 0: `[ -f .env ] || cp .env.example .env`, plus the grep that shows
  the values it needs to carry. `-f` rather than a bare `cp` because this
  machine already had a `.env` and a plain copy would have clobbered a
  developer's local secrets;
- `.env.example` is named as the file those values actually live in;
- `LOCAL_DEV_LOGIN_ENABLED=1` corrected to `=true` (the value in
  `.env.example`), with the reader cited (`localDevLoginService.ts:44`);
- the base-worktree block says out loud that it sources the same local `.env`,
  since the worktree does not contain one;
- gotchas row and See-also updated.

Verified by running it, not by reading: copy `.env.example` to a temp `.env`,
source it, `PG_USER=commonly PG_PASSWORD=password PG_DATABASE=commonly
LOCAL_DEV_LOGIN_ENABLED=true [email protected]
FRONTEND_URL=http://localhost:3000`. All seven bash blocks pass `bash -n`.

Also tightened the Node bullet to what was actually measured (the 34/369 unit
suites that die under the v26 on PATH) and noted that the capture script is not
one of them — it resolves playwright from the root node_modules and launches
chromium under v26.
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.

1 participant