Repository navigation
feat(authz): per-request /api central audit + per-principal rate limit (#467) - #50
Merged
Merged
Conversation
docmost#467) Deliver invariant #3 of docmost#467 (successor to #27 / ADR 0022) in-process, with no reverse proxy and no new AGPL surface: - ApiAccessAuditInterceptor + ApiAccessAuditService (authz/request-controls/): one uniform per-request `access` audit row for every authenticated Docmost /api request, forwarded fire-and-forget through the existing PlatformAuditClient seam. Rows are docmost#320-clean (clientEvidence via the shared request-evidence helper) and carry a `priority` hint ('low' for reads) so the sink sheds reads before security-relevant mutations under overload. - PrincipalRateLimitInterceptor (authz/request-controls/): a per-principal rate limit for authenticated /api traffic, keyed on the VERIFIED req.user.user.id in a SINGLE bucket per principal (not the stock per-handler key a cross-endpoint scraper would evade). Interceptor, not guard, because the controller-scoped JwtAuthGuard runs after the global guards; fails OPEN on Redis outage; mode enforce|count|off. - Both are global APP_INTERCEPTORs registered in seam #4 in a load-bearing order (AuditActor -> ApiAccessAudit -> PrincipalRateLimit): the audit interceptor wraps the rate limiter so a 429 is still audited; the limiter is innermost so it rejects before the handler. Pinned by request-controls.wiring.spec.ts. - Export PlatformAuditClient from PlatformAuditModule; extract the shared docmost#320 clientEvidence builder to request-evidence.ts. Tests: rate-limit (keying/skip/fail-open/count/429), access-audit (shape/clientEvidence/ 429-audited/native no-op), wiring+order, and the audited-AND-limited composition proof. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Author
|
Paired super-repo PR: cccvu/wiki-v2#481 (the audit-sink delivery contract, |
Keeps the docmost#455 fork changes (notification-socket force-close, service-bridge session revoke) alongside the docmost#467 request-controls interceptors. No file overlap; clean merge. Re-pins the super gitlink target.
…w round 1) DevOps review (L3): forward() used undici's timeout-less global fetch, and docmost#467 newly routes a PER-REQUEST /api access stream through it — so a slow-not-down platform sink under /api load could accumulate unbounded in-flight forwards on the fork container. Add AbortSignal.timeout (env PLATFORM_AUDIT_FORWARD_TIMEOUT_MS, default 2000ms); an abort surfaces as a transport error in the existing catch (logged AUDIT_FORWARD_FAILED, row dropped loudly) exactly like any other failure, so loss stays alarmed and the request path is untouched. Co-Authored-By: Claude Opus 4.8 <[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
CCC authorization integration (fork-owned,
apps/server/src/authz/): two globalAPP_INTERCEPTORs for authenticated Docmost/apitraffic — a uniform per-request central-audit row and a per-principal rate limit — plus the shared docmost#320 clientEvidence helper. Delivers wiki-v2 docmost#467 (invariant #3) in-process; the sink + edge changes live in the paired cccvu/wiki-v2 PR.What changed
New fork-owned dir
apps/server/src/authz/request-controls/:api-access-audit.interceptor.ts+api-access-audit.service.ts— oneeventCategory:'access'row per authenticated/apirequest, forwarded fire-and-forget through the existingPlatformAuditClientseam. Rows are Cannot upload Image in webui in localhost docmost/docmost#320-clean (sharedauthz/audit/request-evidence.ts), carry apriorityhint (readslow, mutationsnormal), and never include the body /Authorization. No-op in native mode.principal-rate-limit.interceptor.ts— per-principal limit keyed on the VERIFIEDreq.user.user.idin a SINGLE bucket (principal:<id>, not the stock per-(class,handler)key a cross-endpoint scraper would evade). Default200/10s, block10s; fails OPEN on Redis outage;enforce|count|off.Why interceptors, not guards: the two global
APP_GUARDs run before the controller-scopedJwtAuthGuard, soreq.useris unset at global-guard time (a guard could only key on the unverified cookie — a documented bypass). Interceptors run after all guards, soreq.useris the verified principal.Seam #4 (
app.module.ts) registers both as globalAPP_INTERCEPTORs in a load-bearing order —AuditActorInterceptor→ApiAccessAuditInterceptor→PrincipalRateLimitInterceptor— so the audit interceptor WRAPS the rate limiter and a 429 is still audited, and the limiter is innermost so it rejects before the handler. Also exportsPlatformAuditClientfromPlatformAuditModuleand extracts the shared docmost#320 evidence builder.UPSTREAM_MODIFICATIONS.mdseam #4 updated (7 changes; interceptor order pinned).Testing
principal-rate-limit.interceptor.spec.ts(keying / single-bucket-across-endpoints / distinct principals / skip @public+no-principal / fail-open reject+hang / count mode / 429+Retry-After),api-access-audit.interceptor.spec.ts(one docmost#320-clean row / priority / skip / 429 audited / fire-and-forget / native no-op),request-controls.wiring.spec.ts(registration + order source pin + the audited-AND-limited composition proof). Existingplatform-auditspecs stay green (the evidence refactor is behavior-preserving).scripts/check-upstream-boundary.shexit 0; lint + typecheck clean.Notes
app.module.tsis upstream-touched (documented seam fix(authz): harden PLATFORM_AUTHZ_TIMEOUT_MS parse (empty/typo → deny-all self-DoS) #4); everything else is fork-ownedauthz/.Tracks: wiki-v2 docmost#467.
🤖 Generated with Claude Code