Repository navigation
fix(#502): refuse the native space hard delete in remote mode - #58
Merged
Merged
Conversation
POST /api/spaces/delete ran an unconditional DELETE FROM spaces (every page, version, comment, grant and attachment) behind only CASL Manage Settings, i.e. PDP space#administer — which a delegated manage_members holder and the direct admin of an ARCHIVED space both hold. It bypassed the governed model (archive → workspace-admin restore, docmost#193). - authz/space-delete: SpaceHardDeleteInterceptor 404s SpaceController.deleteSpace for every caller in AUTHZ_MODE=remote, before CASL, ValidationPipe and the handler, and forwards one `space.hard_delete_refused` audit row through PlatformAuditClient (not subject to the API_AUDIT_ENABLED kill switch). Native mode is inert. - app.module.ts (seam #4): registered innermost, after the per-principal rate limiter, so refusals are rate-limited and land in the docmost#467 access row. Not in AuthzModeModule (CollabAppModule has no PlatformAuditModule). - static-route-scan: callsSpaceHardDelete handler tell; fitness spec pins the refused set to the routes that reach .deleteSpace( (both directions) and the spaces delete sink / attachment-purge producers to their current callers. - client (seams 170/171): in remote mode space settings show an archive-only note instead of the Delete button, with a console link for workspace admins. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e (review round 1) Security (L3): the fitness inventory matched FILES, so an upstream SpaceService.bulkDelete looping spaceRepo.deleteSpace — plus a new route calling it — stayed green while that route went unrefused. - space-hard-delete.fitness.spec: a TS-AST scanner attributes every sink occurrence to its enclosing Class.method and the spec pins the exact list (so a new method, or a second call, reds). Comments and string contents never count, which also drops the regex comment stripper that misread `'image/*'`. - Adds the workspace delete as a sink (spaces.workspace_id cascades), pinned to none — invariant I25 now holds literally. - Meta-guard: the bulkDelete scenario, per-occurrence counting, comments, every Kysely/raw-SQL shape, the watcher unwatch. - "innermost" → "registered after the rate limiter" (imported modules' interceptors run inside it) in app.module.ts and the interceptor doc; the docmost#467 wiring spec comment likewise. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.
TL;DR
This is the fork half of the fix for cccvu/wiki-v2 issue 502. In
AUTHZ_MODE=remote, the engine's native space delete (POST /api/spaces/delete, an unconditionalDELETE FROM spaces) now answers 404 for every caller and the refusal is audited, so archive is the only way to remove a space. Native (standalone) mode is unchanged.Context
SpaceService.deleteSpace→SpaceRepo.deleteSpace, aDELETE FROM spaces.Manage Settings. In remote mode that comes from PDPspace#administer, which on a live space includes a delegatedmanage_membersbinding holder. On an archived space the direct admin keeps it: the+ adminbranch sits outside- archived(pdp/schema.zed:138).space.deletedrow written after the delete, and a refused attempt left nothing.Related issues
What changed
No controller, service or repo is touched. The only upstream-owned edits are:
the composition registration in
app.module.ts(seam fix(authz): harden PLATFORM_AUTHZ_TIMEOUT_MS parse (empty/typo → deny-all self-DoS) #4);the space-settings row in
space-details.tsx(seam feat: user should have option to define maximum file size in environment variables docmost/docmost#170), plus its new test.authz/space-delete/space-hard-delete.interceptor.ts(new, CCC-owned):SpaceHardDeleteInterceptor.Controller.handleragainstSPACE_HARD_DELETE_ROUTES = {'SpaceController.deleteSpace'}, the same pattern asNarrowingSettleInterceptor.throwError(() => new NotFoundException())before the handler, so CASL,ValidationPipeand the delete never run.space.hard_delete_refuseddomain row throughPlatformAuditClientdirectly, so theAPI_AUDIT_ENABLEDkill switch cannot drop it.req.user.user.id), the workspace, the attempted space id only if it is a UUID (asresourceId, never thespaceIdcolumn), client evidence and user agent, plusmetadata{outcome:'denied', reason:'archive_only', route}.app.module.ts(seam fix(authz): harden PLATFORM_AUTHZ_TIMEOUT_MS parse (empty/typo → deny-all self-DoS) #4): registered as anAPP_INTERCEPTORright afterPrincipalRateLimitInterceptor, which makes it innermost.api.postaccess row as a 404.AuthzModeModuleorAuthzModule.CollabAppModuleloads those withoutPlatformAuditModule, so the collab process would fail to boot.authz/route-guard/static-route-scan.ts: adds acallsSpaceHardDeletehandler-body tell, next tomintsNativeSession.space-details.tsx(seam feat: user should have option to define maximum file size in environment variables docmost/docmost#170): in remote mode the "Delete space" row shows "Spaces can't be permanently deleted here. A workspace admin can archive this space instead; archived spaces can be restored." instead of the Delete button.usePlatformAdminContext). That reuses the header's cached query, so no extra request is made.Why an interceptor and not a guard:
req.user.How this was tested
space-hard-delete.interceptor.spec.ts(17 tests):null, array and string bodies all 404, and none is echoed into the row;req.userit still 404s and writes no row;space-hard-delete-http.spec.ts: boots the realSpaceControlleron Fastify, with the interceptor registered asAPP_INTERCEPTORandmain.ts'sValidationPipe.{}andnullall return 404; CASL anddeleteSpaceare never called; exactly one row is forwarded.{}returns 400, and an admin's valid request reaches CASL and the delete.space-hard-delete.fitness.spec.ts(static):.deleteSpace(, checked in both directions.DELETE FROM spaces(Kysely or raw SQL) appears only inspace.repo.ts..deleteSpace(callers are only the controller and the service.app.module.tsis pinned.space-details.test.tsx:readOnly: no row.pnpm exec jest src/authz src/service-bridge src/editor-compat: 98 suites, 1057 passed, 0 failed.pnpm --filter client test: 50 files, 369 passed.tsc --noEmit -p tsconfig.build.json: clean. ESLint on the changed server files: clean.AWS / infra apply
N/A. Code only. No migration, config, secret or Terraform change.
Checklist
Scope
Tests
Docs & contracts
README/docs// an ADR), or N/A.Safety (this is a security-first, deny-by-default platform)
UPSTREAM_MODIFICATIONS.md); proprietary/authz logic stays out-of-process.Housekeeping
Known limitations / follow-ups
/v1 ?permanent=true, or trash them and let retention purge them. This is cccvu/wiki-v2 issue 589.🤖 Generated with Claude Code