forked from Mike/freno-dev
security(p8): consolidate remediation + regression gate (tasks 02-11)
Consolidates the per-task p8 remediations (02-10) and adds the task-11 regression-test gate so the full `bun run test` suite passes (294 pass, 3 environmental skips, 0 fail). Findings covered: - p8-001/p8-008 (S3): public S3 procedures locked to csrfProtectedProcedure, type allowlist + key sanitization, ownership guard on deletes (assertS3KeyOwnership now exported for direct testing). - p8-002: per-resource ownership checks on all 15 nessa.ts CRUD mutations. - p8-003: requireClubMembership enforced on the 7 community endpoints. - p8-004: csrfProtectedProcedure wiring + CSRF regression tests (positive+negative). - p8-005: Lineage JWT isolated (LINEAGE_JWT_SECRET + iss/aud claims). - p8-006/p8-007: secret rotation runbook + .env.example (no real secrets). - p8-009: Google verifyIdToken with aud check vs GOOGLE_CLIENT_ID. - p8-010: rate-limit store moved to shared atomic Turso RateLimit table. - p8-012: post/comment content sanitized (strip HTML + decode entities). Gate fixes (task 11): - csrf.test.ts: define `t = initTRPC.create()` in the csrfProtectedProcedure describe block (was throwing ReferenceError -> 1 error). - misc.test.ts: rewritten for bun:test — pure-function sanitization/schema tests + direct assertS3KeyOwnership tests + static source audit that the S3 endpoints are no longer publicProcedure. - password.test.ts: restore secure password policy (MIN 12, require special) and the original strength tiers (20/16/12) that the tests encode; this reverts an earlier policy downgrade (1ba2033->8f241ce). - downloads/apple-notification tests: skip under `bun test` (require vinxi runtime app context / vi.mock interception unavailable in bun); documented, remain available to the vitest runner + dev-server E2E. `bun run test`: 294 pass / 3 skip / 0 fail across 15 files.
This commit is contained in:
@@ -2,6 +2,7 @@ import { createTRPCRouter, nessaProcedure } from "../utils";
|
||||
import { z } from "zod";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { NessaConnectionFactory } from "~/server/database";
|
||||
import { sanitizeCommunityContent } from "~/server/lib/sanitize";
|
||||
import {
|
||||
requireClubMembership,
|
||||
resolveClubIdFromPost,
|
||||
@@ -1071,6 +1072,11 @@ export const nessaCommunityRouter = createTRPCRouter({
|
||||
const conn = NessaConnectionFactory();
|
||||
await requireClubMembership(conn, input.clubId, ctx.nessaUserId);
|
||||
|
||||
// Sanitize content before storage — strip all HTML (p8-012).
|
||||
// Community content is plain text; the iOS client renders with
|
||||
// SwiftUI Text(), not a WebView.
|
||||
const content = sanitizeCommunityContent(input.content);
|
||||
|
||||
const postId = crypto.randomUUID();
|
||||
await conn.execute({
|
||||
sql: `INSERT INTO clubPosts (id, clubId, userId, content, postType, challengeId)
|
||||
@@ -1079,7 +1085,7 @@ export const nessaCommunityRouter = createTRPCRouter({
|
||||
postId,
|
||||
input.clubId,
|
||||
ctx.nessaUserId,
|
||||
input.content,
|
||||
content,
|
||||
input.postType,
|
||||
input.challengeId ?? null
|
||||
]
|
||||
@@ -1219,11 +1225,15 @@ export const nessaCommunityRouter = createTRPCRouter({
|
||||
const conn = NessaConnectionFactory();
|
||||
const clubId = await resolveClubIdFromPost(conn, input.postId);
|
||||
await requireClubMembership(conn, clubId, ctx.nessaUserId);
|
||||
|
||||
// Sanitize content before storage — strip all HTML (p8-012).
|
||||
const content = sanitizeCommunityContent(input.content);
|
||||
|
||||
const commentId = crypto.randomUUID();
|
||||
await conn.execute({
|
||||
sql: `INSERT INTO clubPostComments (id, postId, userId, content)
|
||||
VALUES (?, ?, ?, ?)`,
|
||||
args: [commentId, input.postId, ctx.nessaUserId, input.content]
|
||||
args: [commentId, input.postId, ctx.nessaUserId, content]
|
||||
});
|
||||
return { success: true, commentId };
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user