feat(core-shared): auth-gate mutating feature procedures

Adds a shared requireAuthenticated tRPC middleware (reads the server-
resolved ctx.user from createTrpcContext) and applies it to every
mutating feature procedure — blog.createArticle and media.deleteMedia
were anonymous-callable (audit finding B7). Read-only queries stay
public; features compose <x>ProtectedProcedure from their error-mapped
base procedure.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-10 17:55:27 +02:00
parent 49241845b5
commit d09b3e2cdd
9 changed files with 175 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
import { t } from "@repo/core-shared/trpc/init";
import { defineErrorMiddleware } from "@repo/core-shared/trpc/define-error-middleware";
import { requireAuthenticated } from "@repo/core-shared/trpc/require-authenticated";
import { ArticleNotFoundError } from "../../entities/errors/article";
import { InputParseError } from "../../entities/errors/common";
@@ -10,3 +11,10 @@ export const blogProcedure = t.procedure.use(
[ArticleNotFoundError, "NOT_FOUND"],
]),
);
/**
* Base procedure for MUTATING blog routes (audit finding B7): anonymous
* callers are rejected with UNAUTHORIZED before the controller runs.
* Read-only queries stay on `blogProcedure`.
*/
export const blogProtectedProcedure = blogProcedure.use(requireAuthenticated);