Files
AHMED 8e577165cf Security fixes from pentest 2026-10-09 (F1, F2, F4, F7)
- F2: per-IP rate limits on POST /api/users, /login, /forgot-password
  via new Next middleware (5/h signup, 10/15min login, 5/h forgot);
  429 + Retry-After, generic Arabic error, no UX change
- F7: ghost-email logins burn the same PBKDF2 cost (600k/32/sha256)
  as real verifies, closing response-time user enumeration
- F4: HSTS max-age=63072000; includeSubDomains on all routes
- F1: Traefik pagelimit (60/min, burst 120) + connlimit (in-flight 50)
  on the page router; apilimit untouched
- Pentester accounts (ids 42-48) deleted in prod DB
2026-10-09 17:00:15 +03:00
..

أنور بي آي — web

Next.js 15 + Payload 3 app: Arabic RTL paywalled content site.

Stack

  • Next.js 15.4 (App Router, standalone output) + React 19
  • Payload 3.90 (Postgres adapter, Lexical richText)
  • Stripe subscriptions (35 SAR/month, test mode)

Collections

  • users — auth; role: free | vip | admin, stripeCustomerId
  • posts — title, slug, dek, access (free|vip), teaser, content (lexical), category, cover, readingMinutes, publishedAt, status (draft|published)
  • media — image uploads

Access control: public REST reads only status=published; VIP content is withheld from non-VIP (field-level read rule + paywall page never selects it for them).

Env vars

Var Purpose
DATABASE_URI Postgres connection string
PAYLOAD_SECRET Payload encryption/ signing secret
AGENT_API_KEY Agent API auth (x-agent-key header)
NEXT_PUBLIC_SITE_URL Public URL (baked at build)
STRIPE_SECRET_KEY / STRIPE_PUBLISHABLE_KEY / STRIPE_PRICE_ID / STRIPE_WEBHOOK_SECRET Optional — unset = "pending" mode

Agent API

# create draft (always draft; publish via /admin only)
curl -X POST http://localhost:3000/api/agent/posts \
  -H "x-agent-key: $AGENT_API_KEY" -H 'Content-Type: application/json' \
  -d '{"title":"...","slug":"my-post","dek":"...","category":"وكلاء","access":"vip","teaser":"...","readingMinutes":8,"content":{"root":{"type":"root","children":[],"format":"","indent":0,"version":1}}}'

# update (cannot change status)
curl -X PUT http://localhost:3000/api/agent/posts/my-post -H "x-agent-key: $AGENT_API_KEY" ...

Omitting cover assigns the per-category default cover.

Seed

npm run covers   # regenerate public/covers/*.jpg
npx payload migrate
npx payload run src/seed.ts   # idempotent (skips existing slugs)

Seeds: 12 posts (6 free + 6 VIP, 6 categories), admin admin@anwarpi.ai / AnwarPi-Admin-2026!, test users free@test.anwarpi.ai / Free1234!, vip@test.anwarpi.ai / Vip1234!.

Docker deploy

cp .env.production.example .env.production  # fill secrets
docker compose --env-file .env.production up -d --build
docker compose exec web npx payload run src/seed.ts   # first time

Stripe webhook (testing on LAN)

stripe listen --forward-to localhost:3000/api/stripe/webhook

On production (Railway), point the webhook endpoint at the public URL.