security: CAPA privilege escalation, CSV injection, AI rate-limit, prompt injection guard, open redirect, timing-safe cron secret, server-only admin client, notifications RLS

This commit is contained in:
2026-07-12 17:33:58 +08:00
parent c0ec6660ef
commit c80091c8d6
7 changed files with 49 additions and 6 deletions
+10
View File
@@ -36,7 +36,17 @@ export async function PATCH(
const { data: { user }, error: authError } = await supabase.auth.getUser()
if (authError || !user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
const { data: profile } = await supabase.from('users').select('role').eq('id', user.id).single()
const role = profile?.role ?? ''
const body = await request.json()
// Only hse/admin can set privileged statuses — owner can only move to in_progress/pending_verification
const privilegedStatuses = ['verified', 'reopened', 'closed']
if (body.status && privilegedStatuses.includes(body.status) && !['hse', 'admin'].includes(role)) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
const allowed = ['description', 'due_date', 'priority', 'status', 'department', 'root_cause_ref']
const update: Record<string, unknown> = {}
for (const key of allowed) {