diff --git a/docs/final-hardening/backup-restore.md b/docs/final-hardening/backup-restore.md new file mode 100644 index 0000000..71f1c5c --- /dev/null +++ b/docs/final-hardening/backup-restore.md @@ -0,0 +1,32 @@ +# Backups and restoration + +## What exists + +1. **Hostinger backups** (hPanel → Websites → webcenta.com → **Files → Backups**). This is the plan's automatic backups of files and databases; the page shows the available dates and retention for your plan. *Check it once now* so you know the latest restore point. +2. **On-demand logical backup:** `scripts/backup.sh` writes a gzip-compressed SQL dump (consistent InnoDB snapshot, no locks): + ```bash + DATABASE_URL='mysql://USER:PASSWORD@HOST:3306/DATABASE' bash scripts/backup.sh ./backups + ``` + Run it from a trusted computer with temporary Remote MySQL access (hPanel → Databases → Remote MySQL; remove the access afterwards). Alternatively use phpMyAdmin → Export (SQL). +3. **Restore drill:** `scripts/restore-drill.sh` restores a dump into a scratch database and verifies it (run in CI on every push, so the procedure is known to work). + +Recommended retention: keep Hostinger's automatic backups, plus a manual dump before every risky change (bulk actions, migrations, credential changes), stored encrypted off the server for 30 days. + +## Restoring the database + +1. **Take a backup of the current state first** (even if damaged). +2. Create an empty database in hPanel → Databases (e.g. `…_restore`). +3. Restore into it: + * **Hostinger backup:** hPanel → Backups → Databases → choose the date → *Restore* into the new database (or download and import with phpMyAdmin). + * **Dump file:** `gunzip -c webcenta-YYYYMMDD.sql.gz | mysql -h HOST -u USER -p NEWDATABASE`, or phpMyAdmin → Import. +4. Check it: run `SOURCE_URL=… SCRATCH_URL=… bash scripts/restore-drill.sh file.sql.gz` locally, or browse key tables (Listing, User, AdminUser) in phpMyAdmin. +5. Switch: set `DATABASE_URL` in hPanel to the restored database and redeploy. On start the app applies any newer migrations automatically ("auto-migrate" in the runtime log). +6. Verify: the site loads, an admin can sign in, Admin → Scheduler shows the cron running. + +## Restoring files + +The app itself is rebuilt from GitHub on every deploy; no file restore is needed for code. Uploaded media lives under `STORAGE_LOCAL_DIR` (outside `public_html`). Restore that folder from the Hostinger file backup if media was lost. + +## Encryption key + +Settings secrets and admin authenticator seeds are encrypted with `FIELD_ENCRYPTION_KEY`. A database backup is only fully usable with the key that was active when it was taken. **Store a copy of the key securely offline** (password manager), separately from database backups. diff --git a/docs/final-hardening/checklist.md b/docs/final-hardening/checklist.md new file mode 100644 index 0000000..86c43fa --- /dev/null +++ b/docs/final-hardening/checklist.md @@ -0,0 +1,124 @@ +# Final hardening — checklist + +☑ done and verified · ◐ done, partly verifiable here (reason given) · ✗ owner action / not possible here. +Baseline: `main` at `0f336ea`. Evidence: [test-results.md](test-results.md), [screenshots](screenshots/), [responsive-audit.json](responsive-audit.json). + +## 1. Test notifications only in Admin — ☑ +- Removed the "Send a test notification" button, its client code and the public `/api/push/test` endpoint (now 404). Users keep only "Turn notifications on/off". +- **Admin → Push notifications → Test push notification**: + 1. Enter a recipient's account email → *Find devices*. + 2. Pick one device (platform, installed app, last confirmed, last accepted, failures). + 3. Set title, message and destination → *Send test to this device*. +- The result is the push service's real answer (accepted with HTTP status, or the failure category). Nothing is faked. +- It is sent to that one subscription only (addressed by id, never fan-out). Recorded as kind `TEST`, separate from user notifications (EVENT), reminders and promotional announcements (CAMPAIGN), and never added to anyone's notification centre. Audited as `push.test` with the subscription id and outcome, never the endpoint or keys. Rate-limited to 20 per 10 minutes per administrator. +- Tests: DB (only the chosen subscription is called, recorded as TEST) and E2E (no button for users, endpoint 404, one TEST delivery of two devices, no endpoint in the audit log). + +## 2. Advertising frequency and placement — ☑ (◐ live fill) +- **Root causes of crowding:** the homepage placements sat at fixed positions (after sections 2 and 4) whatever their size, nothing coordinated ads across a page, and the responsive banner rendered three containers. +- **Central placement manager** (`src/server/ads/manager.ts` plus the guard in ``): + - On the server, the feed is planned in whole sections: never first or last, at least *N* sections apart, at most the page maximum, each placement once. + - In the browser, the guard checks every slot against the real layout, in document order, before anything loads: + - one instance per placement (no duplicates from re-renders or navigation); + - at least the minimum distance between ads (default 700 px); + - at most the page maximum (home 3, app page 3, browse pages 1); + - at most 2 on phones; + - mobile and desktop switches respected. + - Rejected slots collapse before requesting anything. + - The responsive banner position counts as one ad. +- **Compact sponsored unit on app pages:** + - A "Ready to try {app}?" box after the app's details contains a dashed, labelled "Advertisement" native unit (reserved 160 px, capped at 360 px) above a "Visit official website" button. + - The Visit button at the top of the page has no ad near it. + - The 300 × 250 moved to the end of the page, after the reviews. +- **Admin controls** (Settings → Ad placements, clamped so no configuration can stack ads): + - maximum ads on the homepage, app pages, browse pages and phones; + - minimum distance in px; + - content sections between ads; + - phones on/off and tablets/computers on/off; + - each placement on/off, including the new compact app-page unit; + - provider priority; + - an AdSense unit id per placement. +- Sizes by device are unchanged: + - phones get native, 300 × 250 and 320 × 50; + - tablets get 468 × 60; + - desktops get 728 × 90, and 160 × 600 on wide screens. +- AdSense is still used only when approved, preferred and configured, otherwise Adsterra, and never both in one slot. +- Tests: + - DB: feed planning. + - E2E at 1440 and 390 px on the home, search and app pages: + - loaded ads ≤ the maximum; + - each pair ≥ 700 px apart; + - no overlaps; + - the compact unit sits inside the Visit box and is labelled; + - none on sign-in; + - the tab bar stays inside the screen. +- Limitation: real ad fill cannot be observed here (tests use a non-existent ad host and so generate no impressions). + +## 3. Security — ☑ (details in [security-audit.md](security-audit.md)) +- **New:** + - step-up confirmation for sensitive admin actions; + - new-device admin sign-in emails; + - a per-address admin sign-in limit; + - the client address now taken from trusted proxy hops (was spoofable); + - security event log, an Account and request security dashboard, and alert emails; + - search rate limits that let verified crawlers through; + - admin import and bulk rate limits; + - COOP, `X-Permitted-Cross-Domain-Policies` and an extended Permissions-Policy. +- **Verified existing controls:** + - MFA, scrypt hashing, lockout, host-only Strict cookies; + - RBAC with audit; + - no unsafe SQL; + - escaped output and a safe markdown renderer; + - CSRF protection (Next.js origin checks, Better Auth, SameSite); + - SSRF protection (DNS pinning, redirect checks, size and time limits); + - upload re-encoding; + - clickjacking headers. +- Docs: [incident-response.md](incident-response.md), [backup-restore.md](backup-restore.md); Hostinger limitations and the optional Cloudflare recommendation are in the audit. +- Tests: + - DB: step-up (missing, wrong, reused and valid codes; 10-minute window; lockout counting), event counting and alert-once, rate-limit recording, crawler verification. + - E2E: an invitation is refused without confirmation, refused with a wrong code and accepted with a valid one; the security dashboard shows failed sign-ins and sessions; security headers. + - Existing security suite (XSS, CSRF, SSRF, IDOR, uploads, session isolation, brute force, RBAC): passing. + +## 4. Import clean-up and duplicates — ☑ +- Duplicate detection (normalised host, registrable domain, existing listings, queued, importing or imported records) now **links** the duplicate to the existing listing (`duplicateOfListingId`). Bulk publishing and automatic publishing re-check for a live listing on the same website and refuse duplicates (with the reason in the audit log). +- **Daily `imports.cleanup`** (retention configurable, default 30 days): + - It deletes only queue entries that never became a listing: confirmed duplicates and permanent failures. It also deletes long-dead scheduler jobs and re-queues stuck imports. + - It never touches listings, developer submissions, reviews, saved apps, claims, appeals or moderation records. + - Every run is logged (what and why) and shown under Import web apps → *Clean-up history*. +- Automatic publishing still requires every check to pass (no failed check, external malware source, risk threshold, allowed category, complete record, no open reports) and now also "not a duplicate". +- Tests: DB (only old, listing-less duplicates and permanent failures are deleted; recent, retryable and linked records are kept; the log names what was removed). + +## 5. Bulk approval — ☑ +- **Import web apps:** + - selection: select all eligible, select visible, deselect all, individual rows; + - actions: publish selected, publish all eligible, send for review, exclude, retry selected, retry all failed, plus the existing reject, archive, run checks and move; + - counts and confirmations before running. +- **Submissions** (new): + - selection: select all eligible, select visible, deselect all; + - actions: approve selected, approve all eligible, request more information, reject, suspend (published listings); + - a reason is required for reject, information and suspend; + - confirmation dialogs with counts; + - an authenticator confirmation for reject and suspend. +- **Per-row eligibility column.** Each record goes through the same checks as an individual approval: + - automated checks finished without a failure; + - no open security alert or report; + - complete (logo, description ≥ 80 characters); + - not a licence-evidence, manual-review or high-risk category. +- Ineligible records are skipped with their reason. Every bulk action is audited (administrator, time, affected records) and rate-limited. +- Tests: DB (five records → one eligible approved, four skipped with exact reasons; reject and request information with reasons; suspend only published listings). E2E (real imported submissions, select visible, approve → the published count matches exactly; reject without a reason is refused). + +## 6. Developer updates and user notifications — ☑ +- Developers submitting an update to a published app can write **"What changed?"** (shown to people who saved the app). +- On approval Webcenta records the **changed fields** on the revision. Previous versions remain in the revision history. Metadata (tags, languages, countries) is recorded but never notifies anyone, and typo-level edits do not count. +- People who saved the app get one in-app notification per meaningful update. The message reads "An app in your saved list has been updated." followed by the developer's summary or a list of what changed, with a View action, and is also pushed to their devices if they allow it. It is not repeated for the same update, sent at most once a day per app, and respects the existing "updates to saved apps" preference. +- Tests: DB (change classification; meaningful update → one notification with the summary, none the second time; a tags-only update queues nothing). + +## 7. Desktop profile navigation — ☑ +- On desktop, account pages show **"Back to marketplace"** at the top of the settings navigation and a **Home › Account › Section** breadcrumb. The sidebar is sticky and scrolls within the screen. On phones, the list-and-screen layout is unchanged. +- Tests: E2E at 1280 px (the breadcrumb and back link work, no overflow) and 390 px (phone layout unchanged); responsive audit. + +## 8. SEO — ☑ (✗ verification is the owner's action) — see [seo-guide.md](seo-guide.md) +- Sitemap https://webcenta.com/sitemap.xml and robots https://webcenta.com/robots.txt verified (valid XML, correct inclusions and exclusions, sitemap linked). Admin and developer hosts are noindex. +- **New:** Google HTML-file verification and Bing XML-file verification served from Settings (meta tags already supported); IndexNow also on suspension, removal and reinstatement. +- App pages: unique title and description, canonical URL, Open Graph, honest structured data (verified by E2E). + +## 9–10. Tests, deployment, report — see [test-results.md](test-results.md) diff --git a/docs/final-hardening/incident-response.md b/docs/final-hardening/incident-response.md new file mode 100644 index 0000000..ef88557 --- /dev/null +++ b/docs/final-hardening/incident-response.md @@ -0,0 +1,59 @@ +# Security incident response + +Keep this procedure with the people who administer Webcenta. Record every incident (step 7). + +## 1. Notice and confirm +Triggers include: +* an email from "[Webcenta Admin] Security activity" or "New sign-in to your account"; +* a user report; +* something unexpected in the admin portal. + +To confirm, open **admin.webcenta.com → Security → Account and request security** and check: +* recent warnings (type, source address, count, time); +* locked accounts; +* active administrator sessions (address and browser); +* configuration changes and sensitive administrator actions; +* **Audit log** (Admin → Audit), filtered by administrator, action or time. + +## 2. Contain: revoke sessions +* **One administrator:** Security → Active administrator sessions → *Revoke all their sessions* (confirm with your authenticator code), or Administrators → *Suspend* (also revokes sessions). +* **All administrators at once:** admin sessions are database rows, so suspend the affected accounts or, in an emergency, run `UPDATE AdminSession SET revokedAt = NOW() WHERE revokedAt IS NULL;` in phpMyAdmin. Everyone is signed out, and Super Administrators sign in again with MFA. +* **A user account:** Admin → Users → the user → *Suspend* (their sessions stop working). +* **A developer organisation:** Admin → Developers → *Suspend* (their listings can no longer be changed). +* **A malicious listing:** Admin → Listings → *Suspend* or *Remove* (step-up required), or Security → alerts. + +## 3. Disable compromised accounts +* Suspend the administrator, user or developer as above. +* For a compromised **administrator**: after investigation, a Super Administrator re-invites them or resets their MFA (Administrators page). They choose a new password and enrol a new authenticator. + +## 4. Rotate credentials +Change them where they live, then redeploy (hPanel → Websites → webcenta.com → Node.js → Environment variables → Save → redeploy). + +| Secret | Where | Effect of rotating | +|---|---|---| +| `USER_AUTH_SECRET` | hPanel env | signs every user out | +| `CRON_SECRET` | hPanel env (and Admin → Settings → Scheduled tasks if set there) | the cron script picks it up from the new build automatically | +| `DATABASE_URL` password | hPanel → Databases → change password, then hPanel env | — | +| SMTP password, OAuth client secrets, API keys | the provider's console, then Admin → Settings (encrypted) or hPanel env | — | +| `FIELD_ENCRYPTION_KEY` | **do not change casually**: it decrypts stored settings secrets and admin TOTP seeds; re-enter integration secrets afterwards | — | +| GitHub access | GitHub → Settings → Applications (Hostinger app) | redeploys stop until re-authorised | + +## 5. Restore data +If data was altered or deleted, restore from backup ([backup-restore.md](backup-restore.md)). Restore into a new database first, compare, then switch. Never restore over production without a fresh backup of the current state. + +## 6. Investigate +* **Audit log:** what each administrator did, from which address. +* **Security log:** failed sign-ins, lockouts, rate limits, denials, new devices. +* **Admin sign-in history:** `AdminLoginEvent` (success, failure reason, address, browser). +* **Hosting runtime log** (hPanel → Node.js → Logs, or the Hostinger API): application errors, `[webcenta] cron tick`, refused requests. +* **Listing history:** Admin → Listings → the listing (status changes, revisions, scans). + +## 7. Record and resolve +Write down: +* when it was noticed and how; +* what was affected (accounts, listings, data); +* the actions taken, with times; +* the root cause; +* the follow-up (fix, new rule, communication). + +If personal data may have been exposed, check the legal notification duties in your jurisdiction (for example, 72 hours under the GDPR) and inform affected users. diff --git a/docs/final-hardening/responsive-audit.json b/docs/final-hardening/responsive-audit.json new file mode 100644 index 0000000..3fb37f9 --- /dev/null +++ b/docs/final-hardening/responsive-audit.json @@ -0,0 +1,6 @@ +{ + "generatedAt": "2026-11-14T06:05:26.198Z", + "engine": "Chromium (Playwright device emulation)", + "checks": 160, + "problems": [] +} diff --git a/docs/final-hardening/responsive/account-1440x900.jpg b/docs/final-hardening/responsive/account-1440x900.jpg new file mode 100644 index 0000000..0e848fa Binary files /dev/null and b/docs/final-hardening/responsive/account-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/account-320x568.jpg b/docs/final-hardening/responsive/account-320x568.jpg new file mode 100644 index 0000000..a31a344 Binary files /dev/null and b/docs/final-hardening/responsive/account-320x568.jpg differ diff --git a/docs/final-hardening/responsive/account-390x844.jpg b/docs/final-hardening/responsive/account-390x844.jpg new file mode 100644 index 0000000..e9817fa Binary files /dev/null and b/docs/final-hardening/responsive/account-390x844.jpg differ diff --git a/docs/final-hardening/responsive/account-768x1024.jpg b/docs/final-hardening/responsive/account-768x1024.jpg new file mode 100644 index 0000000..32a6e2d Binary files /dev/null and b/docs/final-hardening/responsive/account-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/app-1440x900.jpg b/docs/final-hardening/responsive/app-1440x900.jpg new file mode 100644 index 0000000..e8f82d4 Binary files /dev/null and b/docs/final-hardening/responsive/app-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/app-320x568.jpg b/docs/final-hardening/responsive/app-320x568.jpg new file mode 100644 index 0000000..f82d87d Binary files /dev/null and b/docs/final-hardening/responsive/app-320x568.jpg differ diff --git a/docs/final-hardening/responsive/app-390x844.jpg b/docs/final-hardening/responsive/app-390x844.jpg new file mode 100644 index 0000000..f7f59f9 Binary files /dev/null and b/docs/final-hardening/responsive/app-390x844.jpg differ diff --git a/docs/final-hardening/responsive/app-768x1024.jpg b/docs/final-hardening/responsive/app-768x1024.jpg new file mode 100644 index 0000000..e6b2cc7 Binary files /dev/null and b/docs/final-hardening/responsive/app-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/apps-1440x900.jpg b/docs/final-hardening/responsive/apps-1440x900.jpg new file mode 100644 index 0000000..491f959 Binary files /dev/null and b/docs/final-hardening/responsive/apps-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/apps-320x568.jpg b/docs/final-hardening/responsive/apps-320x568.jpg new file mode 100644 index 0000000..26e2703 Binary files /dev/null and b/docs/final-hardening/responsive/apps-320x568.jpg differ diff --git a/docs/final-hardening/responsive/apps-390x844.jpg b/docs/final-hardening/responsive/apps-390x844.jpg new file mode 100644 index 0000000..d1ab5ba Binary files /dev/null and b/docs/final-hardening/responsive/apps-390x844.jpg differ diff --git a/docs/final-hardening/responsive/apps-768x1024.jpg b/docs/final-hardening/responsive/apps-768x1024.jpg new file mode 100644 index 0000000..7174e23 Binary files /dev/null and b/docs/final-hardening/responsive/apps-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/collections-1440x900.jpg b/docs/final-hardening/responsive/collections-1440x900.jpg new file mode 100644 index 0000000..0f8a8d9 Binary files /dev/null and b/docs/final-hardening/responsive/collections-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/collections-320x568.jpg b/docs/final-hardening/responsive/collections-320x568.jpg new file mode 100644 index 0000000..3091462 Binary files /dev/null and b/docs/final-hardening/responsive/collections-320x568.jpg differ diff --git a/docs/final-hardening/responsive/collections-390x844.jpg b/docs/final-hardening/responsive/collections-390x844.jpg new file mode 100644 index 0000000..5fe12e4 Binary files /dev/null and b/docs/final-hardening/responsive/collections-390x844.jpg differ diff --git a/docs/final-hardening/responsive/collections-768x1024.jpg b/docs/final-hardening/responsive/collections-768x1024.jpg new file mode 100644 index 0000000..e3ea13f Binary files /dev/null and b/docs/final-hardening/responsive/collections-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/games-1440x900.jpg b/docs/final-hardening/responsive/games-1440x900.jpg new file mode 100644 index 0000000..8d23a52 Binary files /dev/null and b/docs/final-hardening/responsive/games-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/games-320x568.jpg b/docs/final-hardening/responsive/games-320x568.jpg new file mode 100644 index 0000000..0f90e01 Binary files /dev/null and b/docs/final-hardening/responsive/games-320x568.jpg differ diff --git a/docs/final-hardening/responsive/games-390x844.jpg b/docs/final-hardening/responsive/games-390x844.jpg new file mode 100644 index 0000000..3e02a54 Binary files /dev/null and b/docs/final-hardening/responsive/games-390x844.jpg differ diff --git a/docs/final-hardening/responsive/games-768x1024.jpg b/docs/final-hardening/responsive/games-768x1024.jpg new file mode 100644 index 0000000..1b01601 Binary files /dev/null and b/docs/final-hardening/responsive/games-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/home-1440x900.jpg b/docs/final-hardening/responsive/home-1440x900.jpg new file mode 100644 index 0000000..480f187 Binary files /dev/null and b/docs/final-hardening/responsive/home-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/home-320x568.jpg b/docs/final-hardening/responsive/home-320x568.jpg new file mode 100644 index 0000000..1c404b1 Binary files /dev/null and b/docs/final-hardening/responsive/home-320x568.jpg differ diff --git a/docs/final-hardening/responsive/home-390x844.jpg b/docs/final-hardening/responsive/home-390x844.jpg new file mode 100644 index 0000000..a1cd8c5 Binary files /dev/null and b/docs/final-hardening/responsive/home-390x844.jpg differ diff --git a/docs/final-hardening/responsive/home-768x1024.jpg b/docs/final-hardening/responsive/home-768x1024.jpg new file mode 100644 index 0000000..08858a1 Binary files /dev/null and b/docs/final-hardening/responsive/home-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/notifications-1440x900.jpg b/docs/final-hardening/responsive/notifications-1440x900.jpg new file mode 100644 index 0000000..5f81123 Binary files /dev/null and b/docs/final-hardening/responsive/notifications-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/notifications-320x568.jpg b/docs/final-hardening/responsive/notifications-320x568.jpg new file mode 100644 index 0000000..0879641 Binary files /dev/null and b/docs/final-hardening/responsive/notifications-320x568.jpg differ diff --git a/docs/final-hardening/responsive/notifications-390x844.jpg b/docs/final-hardening/responsive/notifications-390x844.jpg new file mode 100644 index 0000000..fdc446f Binary files /dev/null and b/docs/final-hardening/responsive/notifications-390x844.jpg differ diff --git a/docs/final-hardening/responsive/notifications-768x1024.jpg b/docs/final-hardening/responsive/notifications-768x1024.jpg new file mode 100644 index 0000000..267242a Binary files /dev/null and b/docs/final-hardening/responsive/notifications-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/privacy-1440x900.jpg b/docs/final-hardening/responsive/privacy-1440x900.jpg new file mode 100644 index 0000000..381ed27 Binary files /dev/null and b/docs/final-hardening/responsive/privacy-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/privacy-320x568.jpg b/docs/final-hardening/responsive/privacy-320x568.jpg new file mode 100644 index 0000000..153bea8 Binary files /dev/null and b/docs/final-hardening/responsive/privacy-320x568.jpg differ diff --git a/docs/final-hardening/responsive/privacy-390x844.jpg b/docs/final-hardening/responsive/privacy-390x844.jpg new file mode 100644 index 0000000..16e7478 Binary files /dev/null and b/docs/final-hardening/responsive/privacy-390x844.jpg differ diff --git a/docs/final-hardening/responsive/privacy-768x1024.jpg b/docs/final-hardening/responsive/privacy-768x1024.jpg new file mode 100644 index 0000000..a52d5f4 Binary files /dev/null and b/docs/final-hardening/responsive/privacy-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/profile-1440x900.jpg b/docs/final-hardening/responsive/profile-1440x900.jpg new file mode 100644 index 0000000..014c2cb Binary files /dev/null and b/docs/final-hardening/responsive/profile-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/profile-320x568.jpg b/docs/final-hardening/responsive/profile-320x568.jpg new file mode 100644 index 0000000..90eb343 Binary files /dev/null and b/docs/final-hardening/responsive/profile-320x568.jpg differ diff --git a/docs/final-hardening/responsive/profile-390x844.jpg b/docs/final-hardening/responsive/profile-390x844.jpg new file mode 100644 index 0000000..03a6887 Binary files /dev/null and b/docs/final-hardening/responsive/profile-390x844.jpg differ diff --git a/docs/final-hardening/responsive/profile-768x1024.jpg b/docs/final-hardening/responsive/profile-768x1024.jpg new file mode 100644 index 0000000..267fd3b Binary files /dev/null and b/docs/final-hardening/responsive/profile-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/recently-viewed-1440x900.jpg b/docs/final-hardening/responsive/recently-viewed-1440x900.jpg new file mode 100644 index 0000000..12237ba Binary files /dev/null and b/docs/final-hardening/responsive/recently-viewed-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/recently-viewed-320x568.jpg b/docs/final-hardening/responsive/recently-viewed-320x568.jpg new file mode 100644 index 0000000..4d45541 Binary files /dev/null and b/docs/final-hardening/responsive/recently-viewed-320x568.jpg differ diff --git a/docs/final-hardening/responsive/recently-viewed-390x844.jpg b/docs/final-hardening/responsive/recently-viewed-390x844.jpg new file mode 100644 index 0000000..ab90080 Binary files /dev/null and b/docs/final-hardening/responsive/recently-viewed-390x844.jpg differ diff --git a/docs/final-hardening/responsive/recently-viewed-768x1024.jpg b/docs/final-hardening/responsive/recently-viewed-768x1024.jpg new file mode 100644 index 0000000..835da44 Binary files /dev/null and b/docs/final-hardening/responsive/recently-viewed-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/reviews-1440x900.jpg b/docs/final-hardening/responsive/reviews-1440x900.jpg new file mode 100644 index 0000000..3d5ab8b Binary files /dev/null and b/docs/final-hardening/responsive/reviews-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/reviews-320x568.jpg b/docs/final-hardening/responsive/reviews-320x568.jpg new file mode 100644 index 0000000..1db41d0 Binary files /dev/null and b/docs/final-hardening/responsive/reviews-320x568.jpg differ diff --git a/docs/final-hardening/responsive/reviews-390x844.jpg b/docs/final-hardening/responsive/reviews-390x844.jpg new file mode 100644 index 0000000..e7668af Binary files /dev/null and b/docs/final-hardening/responsive/reviews-390x844.jpg differ diff --git a/docs/final-hardening/responsive/reviews-768x1024.jpg b/docs/final-hardening/responsive/reviews-768x1024.jpg new file mode 100644 index 0000000..21f1fb9 Binary files /dev/null and b/docs/final-hardening/responsive/reviews-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/saved-1440x900.jpg b/docs/final-hardening/responsive/saved-1440x900.jpg new file mode 100644 index 0000000..ecddbdd Binary files /dev/null and b/docs/final-hardening/responsive/saved-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/saved-320x568.jpg b/docs/final-hardening/responsive/saved-320x568.jpg new file mode 100644 index 0000000..0adbc4f Binary files /dev/null and b/docs/final-hardening/responsive/saved-320x568.jpg differ diff --git a/docs/final-hardening/responsive/saved-390x844.jpg b/docs/final-hardening/responsive/saved-390x844.jpg new file mode 100644 index 0000000..465071f Binary files /dev/null and b/docs/final-hardening/responsive/saved-390x844.jpg differ diff --git a/docs/final-hardening/responsive/saved-768x1024.jpg b/docs/final-hardening/responsive/saved-768x1024.jpg new file mode 100644 index 0000000..0c25719 Binary files /dev/null and b/docs/final-hardening/responsive/saved-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/search-1440x900.jpg b/docs/final-hardening/responsive/search-1440x900.jpg new file mode 100644 index 0000000..41a77d5 Binary files /dev/null and b/docs/final-hardening/responsive/search-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/search-320x568.jpg b/docs/final-hardening/responsive/search-320x568.jpg new file mode 100644 index 0000000..6a0b2b1 Binary files /dev/null and b/docs/final-hardening/responsive/search-320x568.jpg differ diff --git a/docs/final-hardening/responsive/search-390x844.jpg b/docs/final-hardening/responsive/search-390x844.jpg new file mode 100644 index 0000000..c564e09 Binary files /dev/null and b/docs/final-hardening/responsive/search-390x844.jpg differ diff --git a/docs/final-hardening/responsive/search-768x1024.jpg b/docs/final-hardening/responsive/search-768x1024.jpg new file mode 100644 index 0000000..ba90337 Binary files /dev/null and b/docs/final-hardening/responsive/search-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/security-1440x900.jpg b/docs/final-hardening/responsive/security-1440x900.jpg new file mode 100644 index 0000000..2adac21 Binary files /dev/null and b/docs/final-hardening/responsive/security-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/security-320x568.jpg b/docs/final-hardening/responsive/security-320x568.jpg new file mode 100644 index 0000000..39e7710 Binary files /dev/null and b/docs/final-hardening/responsive/security-320x568.jpg differ diff --git a/docs/final-hardening/responsive/security-390x844.jpg b/docs/final-hardening/responsive/security-390x844.jpg new file mode 100644 index 0000000..f1ebc07 Binary files /dev/null and b/docs/final-hardening/responsive/security-390x844.jpg differ diff --git a/docs/final-hardening/responsive/security-768x1024.jpg b/docs/final-hardening/responsive/security-768x1024.jpg new file mode 100644 index 0000000..ce54de2 Binary files /dev/null and b/docs/final-hardening/responsive/security-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/signin-1440x900.jpg b/docs/final-hardening/responsive/signin-1440x900.jpg new file mode 100644 index 0000000..480f187 Binary files /dev/null and b/docs/final-hardening/responsive/signin-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/signin-320x568.jpg b/docs/final-hardening/responsive/signin-320x568.jpg new file mode 100644 index 0000000..1c404b1 Binary files /dev/null and b/docs/final-hardening/responsive/signin-320x568.jpg differ diff --git a/docs/final-hardening/responsive/signin-390x844.jpg b/docs/final-hardening/responsive/signin-390x844.jpg new file mode 100644 index 0000000..0e33a98 Binary files /dev/null and b/docs/final-hardening/responsive/signin-390x844.jpg differ diff --git a/docs/final-hardening/responsive/signin-768x1024.jpg b/docs/final-hardening/responsive/signin-768x1024.jpg new file mode 100644 index 0000000..08858a1 Binary files /dev/null and b/docs/final-hardening/responsive/signin-768x1024.jpg differ diff --git a/docs/final-hardening/responsive/signup-1440x900.jpg b/docs/final-hardening/responsive/signup-1440x900.jpg new file mode 100644 index 0000000..480f187 Binary files /dev/null and b/docs/final-hardening/responsive/signup-1440x900.jpg differ diff --git a/docs/final-hardening/responsive/signup-320x568.jpg b/docs/final-hardening/responsive/signup-320x568.jpg new file mode 100644 index 0000000..a06afbc Binary files /dev/null and b/docs/final-hardening/responsive/signup-320x568.jpg differ diff --git a/docs/final-hardening/responsive/signup-390x844.jpg b/docs/final-hardening/responsive/signup-390x844.jpg new file mode 100644 index 0000000..0e33a98 Binary files /dev/null and b/docs/final-hardening/responsive/signup-390x844.jpg differ diff --git a/docs/final-hardening/responsive/signup-768x1024.jpg b/docs/final-hardening/responsive/signup-768x1024.jpg new file mode 100644 index 0000000..08858a1 Binary files /dev/null and b/docs/final-hardening/responsive/signup-768x1024.jpg differ diff --git a/docs/final-hardening/screenshots/account-desktop-1280.jpg b/docs/final-hardening/screenshots/account-desktop-1280.jpg new file mode 100644 index 0000000..25ee901 Binary files /dev/null and b/docs/final-hardening/screenshots/account-desktop-1280.jpg differ diff --git a/docs/final-hardening/screenshots/admin-security-activity-1440.jpg b/docs/final-hardening/screenshots/admin-security-activity-1440.jpg new file mode 100644 index 0000000..95e9492 Binary files /dev/null and b/docs/final-hardening/screenshots/admin-security-activity-1440.jpg differ diff --git a/docs/final-hardening/screenshots/admin-step-up-1440.jpg b/docs/final-hardening/screenshots/admin-step-up-1440.jpg new file mode 100644 index 0000000..381f898 Binary files /dev/null and b/docs/final-hardening/screenshots/admin-step-up-1440.jpg differ diff --git a/docs/final-hardening/screenshots/admin-submissions-bulk-1440.jpg b/docs/final-hardening/screenshots/admin-submissions-bulk-1440.jpg new file mode 100644 index 0000000..a22cad3 Binary files /dev/null and b/docs/final-hardening/screenshots/admin-submissions-bulk-1440.jpg differ diff --git a/docs/final-hardening/screenshots/admin-test-push-1440.jpg b/docs/final-hardening/screenshots/admin-test-push-1440.jpg new file mode 100644 index 0000000..a5b4e18 Binary files /dev/null and b/docs/final-hardening/screenshots/admin-test-push-1440.jpg differ diff --git a/docs/final-hardening/screenshots/ads-app-1440.jpg b/docs/final-hardening/screenshots/ads-app-1440.jpg new file mode 100644 index 0000000..02a536f Binary files /dev/null and b/docs/final-hardening/screenshots/ads-app-1440.jpg differ diff --git a/docs/final-hardening/screenshots/ads-home-1440.jpg b/docs/final-hardening/screenshots/ads-home-1440.jpg new file mode 100644 index 0000000..a4a1c32 Binary files /dev/null and b/docs/final-hardening/screenshots/ads-home-1440.jpg differ diff --git a/docs/final-hardening/screenshots/ads-search-390.jpg b/docs/final-hardening/screenshots/ads-search-390.jpg new file mode 100644 index 0000000..2fddea6 Binary files /dev/null and b/docs/final-hardening/screenshots/ads-search-390.jpg differ diff --git a/docs/final-hardening/security-audit.md b/docs/final-hardening/security-audit.md new file mode 100644 index 0000000..9274356 --- /dev/null +++ b/docs/final-hardening/security-audit.md @@ -0,0 +1,145 @@ +# Security audit and hardening (November 2026) + +An audit of the actual Webcenta code and its Hostinger deployment. No system is impossible to attack; this documents the defences in depth that exist, what this round added, and the risks that remain. + +## 1. Administrator accounts + +| Control | Status | Where | +|---|---|---| +| Separate admin identity (not user accounts), invitation only, no public sign-up | existing | `src/server/admin/*`, `AdminInvitation` | +| Mandatory TOTP MFA before any admin page or action; replay of a used time-step refused | existing | `adminVerifyMfa` | +| Password hashing: scrypt (N=2¹⁵, r=8, p=1, 64-byte key, per-user salt), constant-time compare; dummy hash for unknown emails (no timing-based enumeration) | existing | `src/server/admin/crypto.ts` | +| Account lockout: 5 failures (password or code) → 15 min lock; all sessions revoked on lock | existing | `auth.ts` | +| **Per-address limit across accounts** (password spraying): 20 attempts / 15 min | **new** | `adminLoginAction` | +| Sessions: random 256-bit token, only its SHA-256 stored; 8 h absolute, 30 min idle; revocable; revoked on role/status change | existing | `AdminSession` | +| Cookie: `__Host-wc_admin`, HttpOnly, Secure (https), SameSite=Strict, host-only on admin.webcenta.com (never sent to the public site or developers portal) | existing | `setCookie` | +| **Step-up re-authentication** (fresh authenticator code, valid 10 min on that session) for: inviting administrators, changing roles or status, revoking sessions, credential/payment/security settings, security policy and blocklist, removing or suspending listings, bulk reject/archive/suspend. Wrong codes count towards the lockout. | **new** | `src/server/admin/step-up.ts` | +| **New-device sign-in alert**: email to the administrator when a browser and network not seen in 90 days signs in | **new** | `alertIfNewDevice` | +| **Client address from trusted proxy hops only** (previously the first X-Forwarded-For entry, which a client can forge, was logged) | **fixed** | `reqMeta` | +| Role-based permissions checked on the server for every page and action; denials audited and now counted | existing + monitoring | `permissions.ts`, `assertAdmin` | +| Audit log of administrative actions (who, what, when, address) | existing | `AuditLog` | +| Optional admin IP allow-list | existing | Settings → Security | + +## 2. Common web attacks + +* **SQL injection.** All queries go through Prisma or tagged-template `$queryRaw`/`$executeRaw` (parameterised). The audit found **no** `$queryRawUnsafe`/`$executeRawUnsafe` and no string-built SQL. +* **XSS.** React escapes all output. The only `dangerouslySetInnerHTML` uses are: + * JSON-LD (serialised with `<` escaped); + * the policy renderer (`src/lib/markdown.ts`), which escapes everything first and emits only headings, lists, emphasis and https/relative links. + + Imported descriptions are plain text. The strict CSP (nonce + `strict-dynamic`, `object-src 'none'`, `base-uri 'self'`) limits the impact of any injection. +* **CSRF.** + * Server actions: Next.js rejects cross-origin action requests (Origin/Host check; seen in the E2E logs as "Invalid Server Actions request"). + * Better Auth: checks the origin of auth requests ("Invalid origin"). + * Admin cookie: SameSite=Strict. + * Beacons/APIs: validate the origin. +* **Access control / IDOR.** + * Every user, developer and admin action resolves ownership on the server: favourites, collections, reviews, settings and notifications by user id; developer listings by organisation membership and role; admin by permission. + * Covered by `security.spec.ts` ("broken access control"). +* **Authentication attacks.** + * Better Auth rate limits: sign-in 10 / 5 min, sign-up 10 / h, password reset 5 / h, verification email 5 / h. + * Generic error messages. + * Reset and verification tokens are single-use and expire. + * OAuth account linking requires a verified local email and never trusts provider-asserted email blindly. + * **New:** failed sign-ins and auth rate-limit hits are counted per address in the security log. +* **SSRF** (website import, scanner, domain verification). + * `safeFetch` resolves DNS and blocks private, loopback, link-local, metadata and reserved ranges. + * It re-checks every redirect hop and pins the resolved address (DNS-rebinding safe). + * It applies timeouts and response-size caps. + * Tested in `security.spec.ts` (metadata redirect) and `tests/unit/ssrf.test.ts`. +* **Uploads.** + * Size limits per kind. + * Decoded by sharp with a 40-megapixel cap. + * Only JPEG/PNG/WebP/AVIF accepted, then **re-encoded to WebP** (strips scripts, metadata and polyglots). + * Random UUID storage keys. + * Served from `/media` with a strict content type and `nosniff`. + * Executables rejected (E2E "malicious uploads"). +* **Clickjacking.** + * `X-Frame-Options: DENY` and CSP `frame-ancestors 'none'` everywhere. + * The only exception is Webcenta's own sandboxed ad frames (`frame-ancestors 'self'`). +* **HTTP headers** (verified by E2E): + * HSTS (1 year, includeSubDomains) in production; + * CSP with a per-request nonce; + * `nosniff`; + * `Referrer-Policy: strict-origin-when-cross-origin`; + * a Permissions-Policy denying camera, microphone, geolocation, payment, USB and (**new**) serial, HID, Bluetooth, motion sensors and display capture; + * **new:** `Cross-Origin-Opener-Policy: same-origin`; + * **new:** `X-Permitted-Cross-Domain-Policies: none`. + + The CSP still allows what OAuth (redirect-based), the PWA, analytics and ads need. + +## 3. Bots and abuse + +| Surface | Protection | +|---|---| +| Sign-in, sign-up, reset, verification | Better Auth limits (above) + security log | +| Admin sign-in | account lockout + per-address limit (new) | +| **Search page and suggestions** | **new:** 60 searches/min per address; **600/min for verified search-engine crawlers** (reverse DNS → forward DNS confirmation, Google/Bing/Apple/DuckDuckGo/Yandex). A user agent alone is never trusted, and no crawler is blocked from public pages. | +| Reviews, reports, contact form, uploads, domain checks, push subscription | existing per-user/per-address limits | +| **Admin imports and bulk actions** | **new:** 30 import requests / 10 min and 60 bulk actions / 10 min per administrator | +| Scheduler endpoint | secret (constant-time compare), refused calls now counted | +| Duplicate submissions | buttons disabled while pending; atomic claims for imports, checks and approvals | + +CAPTCHA is not used: the existing limits, lockouts and monitoring cover the observed risks without adding friction for normal users. If sign-up abuse appears in the security log, a challenge on sign-up only (e.g. Cloudflare Turnstile, free) is the next step. + +## 4. Monitoring and alerts (new) + +* `SecurityEvent` table: one row per type, source and hour, so floods stay small. It records: + * failed admin and user sign-ins; + * lockouts; + * new-device admin sign-ins; + * failed confirmation codes; + * permission denials; + * rate-limit hits; + * refused scheduler calls; + * threat-intelligence matches on imports or submissions. + + No passwords, tokens, cookies or request bodies. Kept for 90 days. +* **Admin → Security → Account and request security**: + * counts for the last 24 h, activity by type, recent warnings; + * locked accounts; + * active admin sessions, with "Revoke all their sessions"; + * configuration changes and sensitive admin actions. +* Scheduled job **security.alerts** (every 15 minutes) emails administrators once per event row when a threshold is reached: + * any admin lockout, new-device sign-in or suspicious import; + * 3 wrong confirmation codes; + * 10 admin sign-in failures from one address; + * 5 permission denials; + * 10 refused scheduler calls; + * 50 user sign-in failures from one address; + * 20 rate-limit hits for one key. + +## 5. Database + +* **Credentials.** The application uses one MySQL user scoped to its own database. On Hostinger Business, MySQL users are per-database; remote access is off unless explicitly enabled. Keep it off, and use phpMyAdmin or a temporary remote grant for maintenance. +* **Connection.** 127.0.0.1 on the same server: no network exposure. +* **Secrets.** + * `DATABASE_URL`, auth secrets and the encryption key exist only in hPanel environment variables and the build's `.env.production` (mode 0600, outside `public_html`). + * Integration secrets saved in Admin → Settings are AES-256-GCM encrypted in the database. + * Passwords are scrypt hashes. + * Admin TOTP seeds are encrypted. +* **Logs.** The audit log, security log and push log never store passwords, tokens, cookies, push endpoints or keys. Settings audits record changed field names, not values (`settings.spec.ts`). IP addresses are stored for security purposes and purged (security events 90 days, history 180 days). +* **Backups and restore:** see [backup-restore.md](backup-restore.md). + +## 6. Hostinger Business: what it provides, what it does not + +From the hosting configuration seen through the Hostinger API and hPanel: + +* **Provided:** a free SSL certificate and HTTPS redirect, server-level isolation between accounts, managed MySQL, scheduled backups (shown in hPanel → Files → Backups), and the Node.js app behind LiteSpeed. +* **Not provided as a configurable feature** (not exposed by the hosting API for this plan): a web application firewall with custom rules, bot management, advanced DDoS mitigation, or network-level rate limiting/geo-blocking. Webcenta therefore applies its protections at the application level (above). + +**Recommendation (optional, not activated):** put webcenta.com behind **Cloudflare's free plan**. It adds: +* DDoS absorption; +* managed WAF rules (limited on the free tier); +* bot fight mode; +* edge rate-limiting rules; +* origin IP hiding. + +It requires changing the domain's nameservers (a DNS change, so your decision). Afterwards set Admin → Settings → Security → trusted proxy hops so client addresses stay correct (`CF-Connecting-IP`). Paid tiers add better WAF and bot rules; none is needed to run safely today. + +## 7. Remaining risks + +* A stolen admin password **and** authenticator together grant access. This is mitigated by the new-device email, short sessions, step-up for the most damaging actions and revocation; hardware keys (WebAuthn) would remove this risk and are a possible future addition. +* Application-level rate limiting uses the database. A large distributed flood (DDoS) would reach the server before any limit applies; only an edge service (above) solves that. +* Third-party ad scripts run in sandboxed frames without access to the page, but their content is controlled by the ad network (block unsuitable categories in the Adsterra dashboard). +* Imports trust what websites say about themselves; every import still passes the security checks and moderation rules before publication. diff --git a/docs/final-hardening/seo-guide.md b/docs/final-hardening/seo-guide.md new file mode 100644 index 0000000..4a62134 --- /dev/null +++ b/docs/final-hardening/seo-guide.md @@ -0,0 +1,80 @@ +# Search engines: Google and Bing + +Webcenta's public pages are built to be indexed. The admin portal and developer portal are not: they send `X-Robots-Tag: noindex, nofollow`, their robots.txt is `Disallow: /`, and they require sign-in. Indexing is never instant and rankings are never guaranteed. + +## Addresses + +| What | URL | +|---|---| +| Sitemap (single file, up to 40 000 listings) | https://webcenta.com/sitemap.xml | +| robots.txt | https://webcenta.com/robots.txt | +| Google Search Console | https://search.google.com/search-console | +| Bing Webmaster Tools | https://www.bing.com/webmasters/ | + +**Sitemap content.** +* Included: home, `/apps`, `/categories`, every public category (except 18+ gates), every published app page with its last content change, editorial collections, About and the policies. +* Excluded: accounts, sign-in, search results, drafts, rejected, suspended or removed listings, sample listings, admin, developer pages and APIs. + +It is generated on request, so it changes as soon as a listing is published, updated or removed. If the catalogue approaches 40 000 apps, it should be split into a sitemap index (noted in `src/app/sitemap.ts`). + +**robots.txt.** +* Allows the whole public site. +* Disallows only private or low-value paths (`/account`, `/signin`, `/search`, `/go/`, `/api/`…). +* Links the sitemap. + +robots.txt is not access control: private pages are protected by sign-in and carry `noindex`. + +**App pages.** Each published app page has: +* its own title and description (from the app's summary, category and publisher); +* a canonical URL (`/app/`); +* Open Graph and Twitter data with the app's real screenshot or logo; +* `WebApplication` structured data (a SoftwareApplication type). + +A price appears only for genuinely free apps, and a rating only when real reviews exist. Nothing is invented. + +## Google Search Console + +1. Go to https://search.google.com/search-console → *Add property*. +2. Choose a method. + * **Simplest on Hostinger: "URL prefix" property `https://webcenta.com/` with the *HTML tag* method.** + 1. Google shows ``. + 2. Copy only `XXXX` into **Admin → Settings → Search engines & IndexNow → Google Search Console verification code** and Save. + 3. Back in Google, press *Verify*. + + No file upload and no DNS change. + * *HTML file*: Google gives a file such as `google1a2b3c4d5e6f7a8b.html`. + 1. Enter that **file name** in Admin → Settings → Search engines & IndexNow → *Google HTML verification file name*. + 2. Webcenta then serves the file at `https://webcenta.com/google1a2b3c4d5e6f7a8b.html` with the exact content Google expects. + 3. Press *Verify*. + * *DNS TXT (Domain property: covers all subdomains):* add the TXT record Google shows in hPanel → Domains → DNS / Nameservers. This is a DNS change, so only do it if you want a Domain property. +3. Ownership is only confirmed when Google says so in Search Console. +4. After verification, open *Sitemaps* → enter `sitemap.xml` → *Submit*. +5. Monitor: + * *Pages* (indexed / not indexed, with reasons); + * *Sitemaps* (discovered URLs); + * *URL inspection* for a specific app page; + * *Performance* (clicks and queries; it takes a few days to fill). + +## Bing Webmaster Tools + +1. Go to https://www.bing.com/webmasters/ and sign in. +2. Easiest: **Import from Google Search Console** (after step 3 above). It copies the verified site and sitemap. +3. Otherwise *Add site* `https://webcenta.com/` and verify with one of these: + * the *Meta tag*: copy the `content` of `msvalidate.01` into Admin → Settings → Search engines & IndexNow → *Bing verification code*; + * the *XML file*: copy the code between `` and `` into *Bing XML file code*. Webcenta serves `https://webcenta.com/BingSiteAuth.xml`. +4. *Sitemaps* → *Submit sitemap* → `https://webcenta.com/sitemap.xml`. +5. Monitor *Site Explorer*, *URL Inspection* and *Crawl* (crawl errors, blocked URLs). + +## IndexNow (Bing, Yandex, Seznam, Naver and others; not Google) + +Webcenta already supports IndexNow: +1. Create a key (any 8–128 letters, digits or dashes; Bing can generate one). +2. Enter it in **Admin → Settings → Search engines & IndexNow → IndexNow key**. +3. Webcenta serves it at `https://webcenta.com/indexnow-key.txt` (*Test connection* checks this). + +From then on Webcenta notifies IndexNow when an app page is: +* published; +* updated; +* suspended, removed or reinstated (new in this release). + +Only public `/app/…` URLs are ever sent: never private pages or unapproved listings. The notifications run in the scheduler. diff --git a/docs/final-hardening/test-results.md b/docs/final-hardening/test-results.md new file mode 100644 index 0000000..05a0c0c --- /dev/null +++ b/docs/final-hardening/test-results.md @@ -0,0 +1,67 @@ +# Final hardening — test results + +Local runs: MariaDB 10.11, the production standalone build, Chromium (Playwright). GitHub Actions repeats everything (MariaDB 10.11 and MySQL 8.0) on the pull request. + +| Check | Result | +|---|---| +| ESLint | ✅ 0 errors, 0 warnings | +| TypeScript (`tsc --noEmit`) | ✅ | +| Production build (webpack, standalone) | ✅ | +| Migration `20261115120000_hardening_security_events` | ✅ additive only (3 columns, 1 table); schema diff after applying = empty | +| Unit + database tests (Vitest) | ✅ **347 / 347** (27 files; 10 new in `tests/db/hardening.test.ts`, 1 updated) | +| New E2E suite `hardening.spec.ts` | ✅ **8 / 8** | +| Updated E2E suite `repair.spec.ts` | ✅ **10 / 10** (ads now checked against the placement rules) | +| Full E2E regression (journeys, desktop, tablet, mobile) | ✅ **150 passed**, 1 failed. The failure was an existing race in `hosts.spec.ts` (it waited for a URL the page already had before sign-out finished); the test now waits for the session cookie to disappear and passes 3 / 3. | +| Responsive audit (16 pages × 10 viewports, incl. the 8 requested) | ✅ **160 checks, 0 problems**: no overflow, nothing off-screen, tab bar inside the screen, no console or runtime errors ([responsive-audit.json](responsive-audit.json), images in `responsive/`) | + +## What the new tests actually do + +**Notifications** +* User notification page: no test button. `POST /api/push/test` returns 404. +* A user turns on notifications on two devices. In the admin, *Find devices* lists both; *Send test to this device* sends exactly **one** TEST delivery. No other delivery is created, and the audit log contains no endpoint. +* The result shows the push service's real answer (a made-up subscription is reported as not accepted). +* DB: the test push calls the push service for the chosen subscription only. Update notifications: one per meaningful update, never twice, none for tags-only updates; the developer's summary is used. + +**Advertising** +* Home, search and app pages at 1440 px: + * loaded ads ≤ the maximum, every pair ≥ 700 px apart, no overlap; + * the compact sponsored unit sits inside the "Ready to try" box, labelled, above "Visit official website"; + * no ads on sign-in or sign-up. +* At 390 px: ≤ 2 ads, no 728 × 90, 468 × 60 or 160 × 600, the tab bar stays on screen, no overflow. +* The six Adsterra frames are byte-exact; AdSense priority (DB test). + +**Security** +* E2E: + * inviting an administrator after the confirmation window expired is refused (nothing created), refused with a wrong code, and accepted with a valid code; + * the security dashboard shows failed admin sign-ins, activity by type and active sessions; + * security headers (DENY, nosniff, COOP, Referrer-Policy, Permissions-Policy, CSP frame-ancestors / object-src). +* DB: step-up (missing, wrong and reused codes, the 10-minute window, failures counted towards lockout); event counting and alert-once; rate-limit recording; crawler verification (a user agent alone is not trusted). +* Existing security suite, all passing: XSS, CSRF, SSRF, IDOR, uploads, session isolation, brute force, RBAC. + +**Import and moderation** +* E2E: two real imports → security checks → *Select visible* → *Approve selected*. The number of newly published listings equals exactly the number reported approved; ineligible ones are listed. *Reject* without a reason is refused. +* DB: eligibility reasons (checks not finished, failed check, missing logo, short description), bulk approve, reject and request information, suspend only published listings; clean-up deletes only old listing-less duplicates and failures, and logs them. + +**SEO** +* `sitemap.xml` is valid XML (`application/xml`), contains public pages and no private paths, other hosts or sample listings. +* `robots.txt` allows the site and links the sitemap; the admin host is `Disallow: /` and `noindex`. +* Google and Bing verification files are served only when configured, with the exact content. +* An app page has its title, description, canonical URL, Open Graph and honest JSON-LD. + +**Navigation** +* At 1280 px, account pages show "Back to marketplace" (works) and the breadcrumb, with no overflow. At 390 px the phone layout is unchanged. + +## Screenshots (`screenshots/`) +* `admin-test-push-1440` +* `admin-step-up-1440` +* `admin-security-activity-1440` +* `admin-submissions-bulk-1440` +* `account-desktop-1280` +* `ads-home-1440`, `ads-app-1440`, `ads-search-390` + +Plus the responsive set in `responsive/`. + +## Not verifiable here +* Real phones, real push delivery and real ad fill: no devices or outbound network in the test environment. +* Google and Bing ownership verification: only the owner can complete it. +* The live site from this container: the network policy blocks it, so production is checked through Hostinger's API (build log, runtime log, cron output). diff --git a/next.config.ts b/next.config.ts index daa0b84..e694500 100644 --- a/next.config.ts +++ b/next.config.ts @@ -42,7 +42,10 @@ const nextConfig: NextConfig = { { key: "X-Content-Type-Options", value: "nosniff" }, { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" }, { key: "X-Frame-Options", value: "DENY" }, - { key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=(), payment=(), usb=()" }, + // Isolates Webcenta's windows from pages it opens (ads, OAuth providers use full redirects, not popups). + { key: "Cross-Origin-Opener-Policy", value: "same-origin" }, + { key: "X-Permitted-Cross-Domain-Policies", value: "none" }, + { key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=(), payment=(), usb=(), serial=(), hid=(), bluetooth=(), magnetometer=(), gyroscope=(), accelerometer=(), display-capture=()" }, ...(process.env.NODE_ENV === "production" ? [{ key: "Strict-Transport-Security", value: "max-age=31536000; includeSubDomains" }] : []), diff --git a/playwright.config.ts b/playwright.config.ts index 780ea21..2b99dba 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -49,7 +49,7 @@ export default defineConfig({ }, projects: [ { name: "journeys", testMatch: /journeys\.spec\.ts/, use: { ...devices["Desktop Chrome"] } }, - { name: "desktop", testMatch: /(marketplace|responsive|security|pwa|reviews|settings|hosts|consent|growth|repair|audit-screens|responsive-audit)\.spec\.ts/, use: { ...devices["Desktop Chrome"] } }, + { name: "desktop", testMatch: /(marketplace|responsive|security|pwa|reviews|settings|hosts|consent|growth|repair|hardening|audit-screens|responsive-audit)\.spec\.ts/, use: { ...devices["Desktop Chrome"] } }, { name: "tablet", testMatch: /(marketplace|responsive)\.spec\.ts/, use: { ...devices["iPad (gen 7) landscape"], browserName: "chromium" } }, { name: "mobile", testMatch: /(marketplace|responsive|pwa)\.spec\.ts/, use: { ...devices["Pixel 7"] } }, ], diff --git a/prisma/migrations/20261115120000_hardening_security_events/migration.sql b/prisma/migrations/20261115120000_hardening_security_events/migration.sql new file mode 100644 index 0000000..a7df3b4 --- /dev/null +++ b/prisma/migrations/20261115120000_hardening_security_events/migration.sql @@ -0,0 +1,29 @@ +-- AlterTable +ALTER TABLE `AdminSession` ADD COLUMN `stepUpAt` DATETIME(3) NULL; + +-- AlterTable +ALTER TABLE `ImportCandidate` ADD COLUMN `duplicateOfListingId` VARCHAR(191) NULL; + +-- AlterTable +ALTER TABLE `ListingRevision` ADD COLUMN `changeSummary` VARCHAR(300) NULL, + ADD COLUMN `changedFields` JSON NULL; + +-- CreateTable +CREATE TABLE `SecurityEvent` ( + `id` VARCHAR(191) NOT NULL, + `type` VARCHAR(40) NOT NULL, + `severity` VARCHAR(10) NOT NULL DEFAULT 'info', + `source` VARCHAR(191) NOT NULL, + `detail` VARCHAR(500) NULL, + `hour` DATETIME(3) NOT NULL, + `count` INTEGER NOT NULL DEFAULT 1, + `firstAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `lastAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), + `alertedAt` DATETIME(3) NULL, + + INDEX `SecurityEvent_hour_idx`(`hour`), + INDEX `SecurityEvent_type_hour_idx`(`type`, `hour`), + UNIQUE INDEX `SecurityEvent_type_source_hour_key`(`type`, `source`, `hour`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + diff --git a/prisma/schema/admin.prisma b/prisma/schema/admin.prisma index 8d0cba6..d455982 100644 --- a/prisma/schema/admin.prisma +++ b/prisma/schema/admin.prisma @@ -81,6 +81,8 @@ model AdminSession { ipAddress String? userAgent String? @db.Text revokedAt DateTime? @db.DateTime(3) + /// Last time the administrator re-confirmed with an authenticator code (sensitive actions). + stepUpAt DateTime? @db.DateTime(3) createdAt DateTime @default(now()) @db.DateTime(3) admin AdminUser @relation(fields: [adminId], references: [id], onDelete: Cascade) diff --git a/prisma/schema/catalog.prisma b/prisma/schema/catalog.prisma index 982ff8e..2817b1d 100644 --- a/prisma/schema/catalog.prisma +++ b/prisma/schema/catalog.prisma @@ -351,6 +351,10 @@ model ListingRevision { data Json /// Reviewer-visible notes from the submitter. submitterNotes String? @db.Text + /// Developer's public "what changed" summary (shown to users who saved the app). + changeSummary String? @db.VarChar(300) + /// Fields that differ from the previously approved version (set on approval). + changedFields Json? submittedById String? submittedAt DateTime? @db.DateTime(3) reviewedById String? diff --git a/prisma/schema/growth.prisma b/prisma/schema/growth.prisma index b9708e4..77ac947 100644 --- a/prisma/schema/growth.prisma +++ b/prisma/schema/growth.prisma @@ -115,6 +115,8 @@ model ImportCandidate { failedStage String? @db.VarChar(40) errorCategory String? @db.VarChar(40) retryable Boolean @default(true) + /// The existing listing this import duplicates (set by duplicate detection; never published). + duplicateOfListingId String? createdByAdminId String? createdAt DateTime @default(now()) @db.DateTime(3) processedAt DateTime? @db.DateTime(3) diff --git a/prisma/schema/security.prisma b/prisma/schema/security.prisma index ea27b1b..889714b 100644 --- a/prisma/schema/security.prisma +++ b/prisma/schema/security.prisma @@ -155,3 +155,25 @@ model MonitoringPolicy { allowAutoApproval Boolean @default(false) updatedAt DateTime @updatedAt @db.DateTime(3) } + +/// Security-relevant activity (failed sign-ins, lockouts, rate limiting, permission denials, +/// new-device admin sign-ins, blocked requests), counted per type, source and hour so a flood +/// produces one row, not millions. Never contains passwords, tokens or cookies. Kept 90 days. +model SecurityEvent { + id String @id @default(uuid(7)) + type String @db.VarChar(40) + severity String @default("info") @db.VarChar(10) + /// Source: an IP address, an account id or a rate-limit scope (no secrets). + source String @db.VarChar(191) + detail String? @db.VarChar(500) + hour DateTime @db.DateTime(3) + count Int @default(1) + firstAt DateTime @default(now()) @db.DateTime(3) + lastAt DateTime @default(now()) @db.DateTime(3) + /// An alert email was sent for this row. + alertedAt DateTime? @db.DateTime(3) + + @@unique([type, source, hour]) + @@index([hour]) + @@index([type, hour]) +} diff --git a/src/app/(public)/account/layout.tsx b/src/app/(public)/account/layout.tsx index 46245f9..68ec888 100644 --- a/src/app/(public)/account/layout.tsx +++ b/src/app/(public)/account/layout.tsx @@ -1,5 +1,5 @@ import type { Metadata } from "next"; -import { AccountBackLink, AccountNav } from "@/components/account/account-nav"; +import { AccountBackLink, AccountBreadcrumb, AccountNav } from "@/components/account/account-nav"; import { developerOrigin } from "@/lib/hosts"; import { requireUser } from "@/server/auth/session"; import { unreadCount } from "@/server/community/notifications"; @@ -16,12 +16,13 @@ export default async function AccountLayout({ children }: { children: React.Reac const unread = await unreadCount(user.id); return (
-
diff --git a/src/app/(public)/app/[slug]/page.tsx b/src/app/(public)/app/[slug]/page.tsx index bf22ce8..a6cf9b5 100644 --- a/src/app/(public)/app/[slug]/page.tsx +++ b/src/app/(public)/app/[slug]/page.tsx @@ -202,12 +202,23 @@ export default async function AppPage({ params, searchParams }: Props) { )} - {/* Separated from the app's own content by its label and spacing; never next to the Visit button. */} - + {/* Closing call to action after the app's own information. The compact sponsored unit sits + between them, labelled and boxed so it can never be mistaken for this app's content; + the button at the top of the page has no ad near it. */} +
+

Ready to try {listing.name}?

+ +
+ Visit official website +

Opens {domain} · you’ll see a notice before leaving Webcenta

+
+
+ + diff --git a/src/app/(public)/apps/page.tsx b/src/app/(public)/apps/page.tsx index d2e2058..d423205 100644 --- a/src/app/(public)/apps/page.tsx +++ b/src/app/(public)/apps/page.tsx @@ -1,6 +1,6 @@ import type { Metadata } from "next"; import Link from "next/link"; -import { Ad } from "@/components/ads/ad"; +import { AdBanner } from "@/components/ads/ad"; import { CategoryIcon } from "@/components/category-icon"; import { StoreListSection } from "@/components/store-sections"; import { EmptyState } from "@/components/states"; @@ -47,7 +47,7 @@ export default async function AppsPage() { <> -
+ {FEATURED_CATEGORIES.map((slug, i) => )} )} diff --git a/src/app/(public)/c/[slug]/page.tsx b/src/app/(public)/c/[slug]/page.tsx index de5c178..8fdd309 100644 --- a/src/app/(public)/c/[slug]/page.tsx +++ b/src/app/(public)/c/[slug]/page.tsx @@ -3,7 +3,7 @@ import Link from "next/link"; import { notFound } from "next/navigation"; import { ChevronRight } from "lucide-react"; import { CategoryIcon } from "@/components/category-icon"; -import { Ad } from "@/components/ads/ad"; +import { AdBanner } from "@/components/ads/ad"; import { FilterBar } from "@/components/filter-bar"; import { Pagination } from "@/components/pagination"; import { CardGrid } from "@/components/rail"; @@ -82,7 +82,7 @@ export default async function CategoryPage({ params, searchParams }: Props) { ) : ( )} -
+ ); diff --git a/src/app/(public)/page.tsx b/src/app/(public)/page.tsx index 94913c9..b4da671 100644 --- a/src/app/(public)/page.tsx +++ b/src/app/(public)/page.tsx @@ -1,6 +1,7 @@ import Link from "next/link"; import { Fragment } from "react"; -import { Ad } from "@/components/ads/ad"; +import { Ad, AdBanner } from "@/components/ads/ad"; +import { adPolicy, feedPositions } from "@/server/ads/manager"; import { ChartNoAxesColumn, LayoutGrid, ShieldCheck, Sparkles } from "lucide-react"; import { CategoryIcon } from "@/components/category-icon"; import { AppCard } from "@/components/app-card"; @@ -31,6 +32,9 @@ export default async function HomePage({ searchParams }: { searchParams: Promise const ranked = new Set(["popular", "trending", "top-rated"]); const chip = "inline-flex shrink-0 items-center gap-2 whitespace-nowrap rounded-full border border-border bg-surface px-4 py-2 text-sm font-semibold shadow-card transition hover:border-brand/40 hover:text-brand"; + const feed = rails.filter((r) => r !== featured); + const policy = await adPolicy(); + const adSlots = feedPositions(feed.length, policy.max.home, policy.minSectionsBetween, ["home-native", "home-display", "banner"]); return (
{welcome &&

Your email is confirmed. Welcome to Webcenta!

} @@ -76,12 +80,11 @@ export default async function HomePage({ searchParams }: { searchParams: Promise Listings appear here once they have been reviewed and published. Check back soon. ) : ( - rails.filter((r) => r !== featured).map((r, i) => ( + feed.map((r, i) => ( - {/* Ads sit between whole sections, never inside a row of apps. */} - {i === 1 && } - {i === 3 && } + {/* Ads sit between whole sections, never inside a row of apps, spaced by the placement manager. */} + {adSlots.get(i) === "banner" ? : adSlots.get(i) ? : null} )) )} diff --git a/src/app/(public)/search/page.tsx b/src/app/(public)/search/page.tsx index bde11cf..63a070e 100644 --- a/src/app/(public)/search/page.tsx +++ b/src/app/(public)/search/page.tsx @@ -1,6 +1,6 @@ import type { Metadata } from "next"; import { after } from "next/server"; -import { Ad } from "@/components/ads/ad"; +import { AdBanner } from "@/components/ads/ad"; import { FilterBar } from "@/components/filter-bar"; import { Pagination } from "@/components/pagination"; import { CardGrid } from "@/components/rail"; @@ -21,6 +21,14 @@ export async function generateMetadata({ searchParams }: Props): PromiseYou searched very quickly. Wait a minute and try again.; + } + } const ctx = await getViewerContext(); const [result, tree] = await Promise.all([searchListings(ctx, filters), getCategoryTree(ctx.maxAgeRating)]); if (filters.q && filters.page === 1) { @@ -41,7 +49,7 @@ export default async function SearchPage({ searchParams }: Props) { )} {result.truncated &&

Showing the best matches. Refine your search to see more specific results.

} -
+
); diff --git a/src/app/admin-host/(portal)/admins/page.tsx b/src/app/admin-host/(portal)/admins/page.tsx index fda121b..c7fb9c2 100644 --- a/src/app/admin-host/(portal)/admins/page.tsx +++ b/src/app/admin-host/(portal)/admins/page.tsx @@ -1,3 +1,4 @@ +import { StepUpCard } from "@/components/portal/step-up-card"; import { ActionForm } from "@/components/ui/action-form"; import { Card, Field, inputClass } from "@/components/ui/form"; import { DataTable, StatusPill, td } from "@/components/portal/table"; @@ -21,6 +22,7 @@ export default async function AdminsPage() { return ( <>

Administrators

+

Invite an administrator

diff --git a/src/app/admin-host/(portal)/imports/page.tsx b/src/app/admin-host/(portal)/imports/page.tsx index 46dc94a..64d5547 100644 --- a/src/app/admin-host/(portal)/imports/page.tsx +++ b/src/app/admin-host/(portal)/imports/page.tsx @@ -7,7 +7,7 @@ import { formatDate } from "@/lib/labels"; import { db } from "@/server/db"; import { requireAdmin } from "@/server/admin/auth"; import { bulkImportsAction, queueImportsAction } from "@/server/actions/admin"; -import { eligibleCount } from "@/server/importer/bulk"; +import { eligibleListingIds } from "@/server/importer/bulk"; import { BulkForm } from "@/components/portal/bulk-form"; import { getSection } from "@/server/settings/store"; import { getAllCategoriesTree } from "@/server/catalog/admin-categories"; @@ -18,13 +18,15 @@ export default async function ImportsAdmin({ searchParams }: { searchParams: Pro await requireAdmin("imports.manage"); const status = (await searchParams).status; const filter = ["QUEUED", "IMPORTING", "IMPORTED", "FAILED", "SKIPPED"].includes(status ?? "") ? status : undefined; - const [counts, rows, tree, s, eligible] = await Promise.all([ + const [counts, rows, tree, s, eligibleSet, cleanups] = await Promise.all([ db.importCandidate.groupBy({ by: ["status"], _count: { _all: true } }), db.importCandidate.findMany({ where: filter ? { status: filter as never } : {}, orderBy: [{ processedAt: "desc" }, { priority: "desc" }, { createdAt: "asc" }], take: 200 }), getAllCategoriesTree(), getSection("imports"), - eligibleCount(), + eligibleListingIds(), + db.auditLog.findMany({ where: { action: "imports.cleanup" }, orderBy: { createdAt: "desc" }, take: 10, select: { id: true, createdAt: true, metadata: true } }), ]); + const eligible = eligibleSet.size; const n = (k: string) => counts.find((c) => c.status === k)?._count._all ?? 0; // Review state of imported listings (status, latest scan) for the table. const listings = await db.listing.findMany({ @@ -78,7 +80,7 @@ export default async function ImportsAdmin({ searchParams }: { searchParams: Pro const pendingRev = l?.revisions[0] && ["SUBMITTED", "AUTOMATED_CHECKS", "UNDER_REVIEW"].includes(l.revisions[0].status) ? l.revisions[0] : undefined; return ( - + {r.name ?? r.domain}
{r.url}{r.reviewRequired && <>
Review required} {r.categorySlug} {r.source} @@ -107,6 +109,24 @@ export default async function ImportsAdmin({ searchParams }: { searchParams: Pro })} + +

Clean-up history

+

The daily clean-up deletes duplicate and permanently failed queue entries after {s.num("cleanupRetentionDays") || 30} days. It never deletes listings, developer submissions, reviews or saved apps.

+ {cleanups.length === 0 ?

Nothing has been cleaned up yet.

: ( +
    + {cleanups.map((c) => { + const m = (c.metadata ?? {}) as { deletedDuplicates?: number; deletedFailed?: number; deletedDeadJobs?: number; resetImporting?: number; duplicates?: Array<{ domain: string }>; failed?: Array<{ domain: string; category?: string }> }; + return ( +
  • +
    {formatDate(c.createdAt)}: {m.deletedDuplicates ?? 0} duplicate(s), {m.deletedFailed ?? 0} failed import(s), {m.deletedDeadJobs ?? 0} failed job(s) deleted; {m.resetImporting ?? 0} stuck import(s) re-queued +

    Duplicates: {(m.duplicates ?? []).map((d) => d.domain).join(", ") || "—"}. Failed: {(m.failed ?? []).map((d) => `${d.domain} (${d.category ?? "error"})`).join(", ") || "—"}.

    +
    +
  • + ); + })} +
+ )} +
); } diff --git a/src/app/admin-host/(portal)/push/page.tsx b/src/app/admin-host/(portal)/push/page.tsx index d2a8e7c..a31c442 100644 --- a/src/app/admin-host/(portal)/push/page.tsx +++ b/src/app/admin-host/(portal)/push/page.tsx @@ -6,18 +6,22 @@ import { DataTable, StatusPill, td } from "@/components/portal/table"; import { formatDate } from "@/lib/labels"; import { db } from "@/server/db"; import { requireAdmin } from "@/server/admin/auth"; -import { sendPushAction } from "@/server/actions/admin"; +import { sendPushAction, testPushAction } from "@/server/actions/admin"; import { getSection } from "@/server/settings/store"; import { pushDiagnostics } from "@/server/push/diagnostics"; export const metadata = { title: "Push notifications" }; const weekAgo = () => new Date(Date.now() - 7 * 86_400_000); -const KIND_LABEL: Record = { CAMPAIGN: "Announcement", EVENT: "Notification", REMINDER: "Reminder" }; +const KIND_LABEL: Record = { CAMPAIGN: "Announcement (promotional)", EVENT: "User notification", REMINDER: "Reminder", TEST: "Test (admin)" }; -export default async function PushAdmin({ searchParams }: { searchParams: Promise<{ kind?: string }> }) { +export default async function PushAdmin({ searchParams }: { searchParams: Promise<{ kind?: string; recipient?: string }> }) { await requireAdmin("push.send"); - const kind = (await searchParams).kind; + const sp = await searchParams; + const kind = sp.kind; + // Test push: the devices of one chosen user (by email). Endpoints and keys are never shown. + const recipientEmail = (sp.recipient ?? "").trim().toLowerCase().slice(0, 254); + const recipient = recipientEmail ? await db.user.findUnique({ where: { email: recipientEmail }, select: { id: true, name: true, email: true, pushNotifications: true, pushSubscriptions: { orderBy: { updatedAt: "desc" }, select: { id: true, platform: true, standalone: true, lastSyncedAt: true, lastSuccessAt: true, failureCount: true } } } }) : null; const since = weekAgo(); const [subscribers, signedIn, log, week, cfg, d] = await Promise.all([ db.pushSubscription.count({ where: { failureCount: { lt: 5 } } }), @@ -41,7 +45,7 @@ export default async function PushAdmin({ searchParams }: { searchParams: Promis
    {(["CAMPAIGN", "EVENT", "REMINDER"] as const).map((k) => { const w = week.find((x) => x.kind === k); - return
  • {KIND_LABEL[k]}s, last 7 days
    {w?._count._all ?? 0} sent · {w?._sum.delivered ?? 0} accepted · {w?._sum.failed ?? 0} failed
  • ; + return
  • {KIND_LABEL[k]}, last 7 days
    {w?._count._all ?? 0} sent · {w?._sum.delivered ?? 0} accepted · {w?._sum.failed ?? 0} failed
  • ; })}
@@ -58,8 +62,9 @@ export default async function PushAdmin({ searchParams }: { searchParams: Promis {stat("Devices not eligible", d.notEligible, `${d.unhealthy} failing repeatedly · ${d.optedOut} opted out`)} {stat("Last accepted delivery", d.lastAcceptedAt ? formatDate(d.lastAcceptedAt) : "never", d.lastAttemptAt ? `Last attempt ${formatDate(d.lastAttemptAt)}` : undefined)} -
+

Error categories

{d.categories.length ?
    {d.categories.map((c) =>
  • {c.category}: {c.count}
  • )}
:

No failures.

}
+

By type

{d.kinds.length ?
    {d.kinds.map((k) =>
  • {KIND_LABEL[k.kind] ?? k.kind}: {k.accepted} accepted · {k.failed} failed
  • )}
:

No attempts yet.

}

By device type

{d.platforms.length ?
    {d.platforms.map((p) =>
  • {p.platform}: {p.accepted} accepted · {p.failed} failed · {p.expired} expired
  • )}
:

No attempts yet.

}

Subscribed devices

    {d.subscriptionsByPlatform.map((p) =>
  • {p.platform}: {p.count}
  • )}
  • iPhone/iPad Home Screen apps: {d.iosStandalone}
@@ -71,6 +76,32 @@ export default async function PushAdmin({ searchParams }: { searchParams: Promis )} + +

Test push notification

+

Sends one test notification to one device of the user you choose. It is never sent to anyone else, it does not appear in anyone's notification centre, and it is logged as a test.

+
+ + +
+ {recipientEmail && !recipient &&

No account with that email.

} + {recipient && (recipient.pushSubscriptions.length === 0 + ?

{recipient.name} has no device with notifications turned on. Ask them to open Account → Notifications on the device and turn notifications on (on iPhone/iPad, from the Home Screen app).

+ : ( + + + + + {!recipient.pushNotifications &&

This user turned push copies off; a test is still allowed so you can diagnose the device.

} +
+ + +
+