Repository navigation
fix(service-bridge): resurrect soft-deleted shadow users + adjacent hardening (#50, #272) - #28
Merged
Merged
Conversation
…coverage (#50) Adds the issue #50 boundaries the mocked specs could not prove: - service-bridge.pg.spec.ts (new): real Postgres ON CONFLICT upsert — idempotency, planted-real-user untouched, foreign-workspace not matched, concurrent convergence, no-workspace 503, soft-delete resurrection (T-046 red). - service-bridge.service.spec.ts: conflict target (email, workspaceId), no role/password rewrite, no-workspace-before-insert, name fallback, uniform 403, soft-delete resurrection unit proof (T-036 red). - shadow-user.spec.ts: lookalike-domain suffix table + derivation boundary. - dto/provision-user.dto + mint-session.dto validation: externalId charset is the no-injection boundary (rejects @, whitespace, >128, non-ASCII). Companion bug-tracker: cccvu/wiki-v2#272 (P5 red tests here; P1-P3 platform-side). Test plan: docs/test-plans/issue-50-docmost-bridge.md
…ardening (#50, docmost#272) Fixes the fork-side defect the #50 coverage exposed (companion tracker docmost#272), plus the adjacent latent defects the review hunt surfaced. Flips the intentionally-red tests green at root cause; no test weakened. - P5/F3 (service-bridge.service.ts): the provisioning ON CONFLICT upsert now self-heals a fork-owned shadow row back to the "plain, live member" shape — clears `deletedAt` (a soft-deleted user is resurrected; previously mintSession refused "deleted" forever), forces `role: 'member'` (de-escalates a tampered row; the literal is never caller-supplied, so this STRENGTHENS no-escalation), and refreshes `name`/`emailVerifiedAt`. Never touches `password`/`email`. Flips T-036 (unit) + T-046 (real-PG); T-030's key-set assertion updated to pin the new columns and prove role is only ever `member`. Adds T-047 (real-PG de-escalation proof). - F1 (service-bridge.service.ts disqualify): use the platform-wide `isUserDisabled` (deactivatedAt OR deletedAt) so a DEACTIVATED shadow member is refused — the mint path checking only `deletedAt` was a fail-open divergence from every native auth entrypoint. - F2 (shadow-user.ts shadowEmailFor): lower-case the derived address at the single chokepoint both the case-sensitive upsert and case-insensitive findByEmail flow through, so case-variant externalIds can't duplicate/cross-map. Adds T-048 (real-PG convergence). - F7 (shadow-user.ts isShadowEmail): require exactly one `@` + an exact domain match, rejecting embedded-`@` lookalikes a bare endsWith() accepted. - F4 (workspace-resolver.ts): deterministic pick (createdAt asc, id asc tiebreak) + warn when >1 non-deleted workspace (single-tenant invariant breach) instead of a silent non-deterministic flip; no hard-fail (avoids an outage on an accidental 2nd workspace). - F5 (workspace-resolver.ts resolveUserWorkspaceId): exclude soft-deleted users and reject a null workspace_id rather than returning null typed as string (no bogus PDP anchor). - F6 (service-auth.guard.ts): rate-limit the unauthenticated (missing/wrong-secret) path per client IP (the DoS backstop previously covered only authenticated calls); treat a whitespace-only configured secret as unconfigured (503). Co-Authored-By: Claude Opus 4.8 <[email protected]>
PMQ9
force-pushed
the
fix/issue-50-272-shadow-session
branch
from
September 13, 2026 04:28
670c7f7 to
c4a89b7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Paired fork half of cccvu/wiki-v2 issue 50 / issue 272. The platform (super-repo) PR repoints the submodule to this branch and carries the platform-side fixes; merge this fork PR first, then the super PR.
What this does
Adds the fork-side real-dependency coverage the #50 shadow-session work needs, and fixes the fork defect it exposed (docmost#272 P5) plus adjacent latent defects the review hunt surfaced — all in the CCC-owned
apps/server/src/service-bridge/tree (no upstream-owned files touched). Bug-exposing tests were committed red first (commit 1), then fixed at root cause (commit 2); every red is now green.Fixes
provisionShadowUserON CONFLICTupsert now self-heals a fork-owned shadow row to the "plain, live member" shape: clearsdeletedAt(resurrects a soft-deleted shadow user — previouslymintSessionrefused "deleted" forever), forcesrole: 'member'(de-escalates a tampered row; the literal is never caller-supplied, so this strengthens no-escalation), and refreshesname/emailVerifiedAt. Never touchespassword/email.disqualifyuses the platform-wideisUserDisabled(deactivatedAtORdeletedAt), so a deactivated shadow member is refused (was a mint fail-open; every native auth entrypoint already enforces this).shadowEmailForlower-cases the derived address (the single chokepoint both the case-sensitive upsert and case-insensitivefindByEmailuse), so case-variantexternalIds can't create duplicate / cross-mapped rows.isShadowEmailrequires exactly one@and an exact domain match (rejects embedded-@lookalikes a bareendsWith()accepted).WorkspaceResolver.resolveDefaultWorkspaceIdis deterministic (createdAt, thenidtiebreak) and warns on >1 non-deleted workspace (single-tenant invariant breach) instead of a silent non-deterministic flip; no hard-fail.resolveUserWorkspaceIdexcludes soft-deleted users and rejects a nullworkspace_id(no bogus PDP anchor).ServiceAuthGuardrate-limits the unauthenticated (missing/wrong-secret) path via a single coarseanonbucket, and treats a whitespace-only configured secret as unconfigured (503). Deliberately not keyed onreq.ip:main.tssetstrustProxy: true, soreq.ipisX-Forwarded-For-derived (attacker-controlled) — a per-IP key would let a spoofed header bypass the limit and grow the window map without bound. All legitimate callers hold the secret (separate bucket), so all traffic on this path is illegitimate and capping it collectively is the intent.Tests
New/strengthened specs under
apps/server/src/service-bridge/:service-bridge.service.spec.ts— T-030 (conflict key-set, strengthened to pinrole === 'member'), T-031/T-032/T-033, T-036 (P5, now green), F1 (deactivated), deactivated added to the uniform-403 T-033 set.service-bridge.pg.spec.ts(new, real-PG) — T-040…T-046 (T-046 P5 now green), T-047 (F3 de-escalation on real ON CONFLICT), T-048 (F2 case convergence).shadow-user.spec.ts— T-034 lookalike table + embedded-@(F7) + case-normalization (F2).dto/dto-validation.spec.ts— T-035 (ProvisionUserDto/MintSessionDtocharset guard).workspace-resolver.spec.ts— F4 (deterministic + warn), F5 (soft-delete filter, null-workspace 404).service-auth.guard.spec.ts— F6 (anon rate-limit 429, XFF-spoof cannot bypass, valid-credential not starved, whitespace-secret 503).Verified locally:
pnpm exec jest src/authz src/service-bridge src/editor-compat(pg specs self-skip); fullsrc/service-bridgewith a real Postgres (AUTHZ_REQUIRE_PG=1) → 27 suites / 258 tests green;nest buildclean; super-repocheck-upstream-boundary.shclean (no upstream-file divergence, no brand marks).Risk & rollback
Low. All changes are additive/behavioral within CCC-owned service-bridge code; no schema migration, no upstream-owned file touched. The two behavioral shifts a reviewer should weigh: (a) a re-provision now de-escalates
roletomember(intended self-heal; mint was already fail-closed on non-member), and (b)shadowEmailFornow lower-cases (no-op for existing lowercase-UUID ids; no data migration needed). Rollback = revert the two commits.🤖 Generated with Claude Code