Full-application audit (5 parallel read-only audits). Two agent
"blockers" were false alarms and verified as already-correct. Real
findings fixed:
- Self-escalation (BLOCKER): migration 024 + schema.sql section 16
extend prevent_member_self_role_change to also block a
non-privileged member changing their own tier_id (self tier
upgrade) and onboarding_completed_at (skipping required
code-of-conduct via a raw PostgREST call). finishOnboarding and
skipOnboarding now set onboarding_completed_at through the service
client AFTER their server-side required-steps check, so the
legitimate path is unaffected.
- Cross-tenant write scoping: added .eq('space_id', member.space_id)
to updateForumThread, deleteForumThread, editComment, deleteComment,
deleteChannel, renameChannel (RLS-only -> defence-in-depth).
- generateInviteCode: crypto.getRandomValues, widened to 8 chars
(was Math.random, ~21 bits, enumerable under the join rate limit).
- SafeMarkdown: dropped iframe and the global style attribute
(no unsandboxed embeds / UI-redress); markdown + safe HTML stay.
- /settings: server-side admin redirect before fetching space and
integration config (was client-hidden only).
- app/(app)/layout.tsx: export const dynamic = 'force-dynamic'.
- Bounded queries: loadComments .limit(500), tasks .limit(2000).
Backlog from the audit is tracked in HANDOFF (import Zod schemas,
types/database.ts + docs regen, email lowercasing, unauthorized-
handling consistency, KB-modal ACL hookup).
271/271 tests pass. Build clean. Migrations 023 + 024 idempotent,
apply via deploy.sh on next deploy.
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
'use client'
|
|
|
|
import ReactMarkdown from 'react-markdown'
|
|
import remarkGfm from 'remark-gfm'
|
|
import rehypeRaw from 'rehype-raw'
|
|
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize'
|
|
|
|
// Renders admin-authored markdown that MAY contain a constrained subset of raw
|
|
// HTML. rehype-raw parses the HTML; rehype-sanitize then strips anything
|
|
// dangerous. The author is a space admin/board member, but a stored-XSS or
|
|
// UI-redress payload would still run in other members' sessions within that
|
|
// tenant, so this is sanitized hard, not trusted:
|
|
// - no `iframe` (no unsandboxed third-party embeds / token theft frame)
|
|
// - no global `style` attribute (no full-viewport overlay redress)
|
|
// - links forced to safe protocols; rel/target locked down
|
|
const schema = {
|
|
...defaultSchema,
|
|
attributes: {
|
|
...defaultSchema.attributes,
|
|
'*': [...(defaultSchema.attributes?.['*'] ?? []), 'className'],
|
|
a: [...(defaultSchema.attributes?.a ?? []), 'target', 'rel'],
|
|
},
|
|
protocols: {
|
|
...defaultSchema.protocols,
|
|
href: ['https', 'http', 'mailto'],
|
|
},
|
|
}
|
|
|
|
export function SafeMarkdown({ children, className }: { children: string; className?: string }) {
|
|
return (
|
|
<div className={`prose prose-sm prose-neutral dark:prose-invert max-w-none break-words ${className ?? ''}`}>
|
|
<ReactMarkdown
|
|
remarkPlugins={[remarkGfm]}
|
|
rehypePlugins={[rehypeRaw, [rehypeSanitize, schema]]}
|
|
>
|
|
{children}
|
|
</ReactMarkdown>
|
|
</div>
|
|
)
|
|
}
|