1.4 KiB
1.4 KiB
Task 05: Auth & CSRF на POST /api/posts/preview
Assigned to: Antigravity (Implementation Orchestrator)
Priority: MEDIUM (security)
Date: 2026-08-21
Base SHA: 4b8c6b10395452a3fd1ff7ea4eb919289b66f33f
Scope
- Add
validateCsrfOrigin(req)toPOST /api/posts/preview(src/app/api/posts/preview/route.ts). - Require authenticated session (
requireAuthenticatedUser(req)) onPOST /api/posts/preview:- Post preview is step 1 of giveaway creation wizard which immediately calls
POST /api/giveaways(already requiring authentication). - Prevents open VK API proxy abuse and unauthenticated server token quota draining.
- User-scoped rate limit:
expensiveApiRateLimiter.assertAllowed('post-preview:' + sessionUser.id).
- Post preview is step 1 of giveaway creation wizard which immediately calls
- Preserve
resolveEffectiveCapabilitiestruthfulness from actualpost.resolvedAuthType(Phase 2.3.1 invariant). - Update UI in
src/app/giveaways/new/page.tsxto handle 401 cleanly with redirect/re-login prompt. - Create test suite
tests/post-preview-guard.test.ts:- Cross-site POST with untrusted Origin -> 403 Forbidden.
- POST without authenticated session -> 401 Unauthorized.
VK_SERVICE_TOKENnever leaked in response.- Legitimate authenticated same-origin request -> 200 OK with accurate effective capabilities.
- Verify gate and submit report to
agents/antigravity/done/TASK-2026-08-21-05-post-preview-auth.md.