diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cd1422c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Version comes from "packageManager" in package.json. + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24 + cache: pnpm + - run: pnpm install --frozen-lockfile + - run: pnpm typecheck + - run: pnpm lint + - run: pnpm test + - run: pnpm build diff --git a/README.md b/README.md index 8df9712..081c253 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ A short-URL pastebin built with **Next.js 16 (App Router) + TypeScript + Drizzle | Layer | Choice | |---|---| -| Framework | Next.js 16.3.3 (App Router), TypeScript | +| Framework | Next.js 16.3.8 (App Router), TypeScript | | UI | Tailwind CSS v4, Geist fonts (`next/font`), lucide-react icons | | ORM | Drizzle (+ postgres.js driver, drizzle-kit migrations) | | Database | PostgreSQL on Supabase (RLS enabled, Data API grants revoked) | @@ -41,7 +41,7 @@ A short-URL pastebin built with **Next.js 16 (App Router) + TypeScript + Drizzle pnpm install ``` -> This repo uses **pnpm** as the package manager and bleeding-edge tooling (TypeScript 7, ESLint 10). `pnpm lint` currently fails because `typescript-eslint` does not support TS 7 yet; typecheck (`pnpm build` / `pnpm typecheck`) is the source of truth. +> This repo uses **pnpm** as the package manager and bleeding-edge tooling (TypeScript 7, ESLint 10). `tsc` is TypeScript 7 (aliased as `@typescript/native`), while the `typescript` package is the TS 6 compatibility build (`@typescript/typescript6`) so `typescript-eslint`, which has no TS 7 API yet, keeps working. Drop the alias once `typescript-eslint` supports TS 7.1+. ### 2. Configure environment @@ -84,7 +84,8 @@ Open http://localhost:3000. | `pnpm dev` | Start dev server | | `pnpm build` | Production build (includes typecheck) | | `pnpm start` | Start production server | -| `pnpm lint` | ESLint (fails until `typescript-eslint` supports TS 7) | +| `pnpm lint` | ESLint | +| `pnpm test` | Unit tests (Vitest) | | `pnpm typecheck` | Type-check only | | `pnpm db:generate` | Generate DB migration | | `pnpm db:migrate` | Apply DB migrations | @@ -137,7 +138,7 @@ Both tables have row-level security enabled, and the Supabase `anon` / `authenti - Upload tokens (one per file): 30 / 10 min per IP - Read (reveal, verify, file downloads): 60 / 60 s per IP - Paste pages (`/[code]`): 120 / 60 s per IP, enforced in the proxy (a page only reveals whether a code exists, but each costs a function run and a query). Fails open if Redis is unreachable. -- Password attempts: 10 failures per paste per IP per hour, and 50 per paste per hour across all IPs, counted across `/verify` and file downloads. Someone guessing locks only their own IP, so they can't lock out the real recipient; the shared limit still bounds guessing spread over many IPs. Once locked, even the correct password gets `429 Too many attempts. Try again later.` (no count or `Retry-After` is revealed) until the window ends. +- Password attempts: 10 failures per paste per IP per hour, and 50 per paste per hour across all IPs, counted across `/verify` and file downloads. Each attempt is counted atomically before the key is compared (and refunded if it was right), so concurrent guesses can't race past the limit. One guessing IP locks only itself; the shared limit bounds guessing spread over many IPs, but it also means guesses from several IPs can lock out the real recipient for the rest of the hour. Once locked, even the correct password gets `429 Too many attempts. Try again later.` (no count or `Retry-After` is revealed) until the window ends. - Upload quota: 300 MB of uploads per IP and 300 MB across all clients per UTC day (pastes live up to 3 days, so the Blob store stays under the 1 GB Hobby limit). The client declares each encrypted file's size when requesting its upload token; the server counts it against the quota in Redis and issues a token capped at exactly that size, so Blob rejects anything larger. Each token stores one blob at exactly `files/` (no random suffix, no overwrite), so a token can't be reused to upload again on a single quota charge. - Per-paste file size check: the declared size is also recorded in Redis per upload path (3 h, one token per path), so `POST /api/pastes` checks the real 100 MB total with one Redis lookup. Files without a record (no Redis, or expired) fall back to a Blob `head()` per file. @@ -150,6 +151,7 @@ Limits are keyed by an HMAC of the client IP (keyed from `PASTE_MASTER_KEY`), so ## Security notes - This is a **server-side** encryption model: the server holds the master key and can decrypt content. It is NOT zero-knowledge like PrivateBin — that trade-off buys short, typable URLs. +- Passwords are **access control, not end-to-end encryption**. The PBKDF2-derived key is the content key, and it is stored wrapped with the master key, so anyone holding both the database and `PASTE_MASTER_KEY` can read password-protected pastes without guessing the password. The password (and the per-paste attempt limits) only stops people who have the link but not that access. - Ciphertext is encrypted at rest with a per-paste key that is itself wrapped by a master key stored only in env. File blobs (and their names) are encrypted client-side before they ever reach object storage. - Content is always rendered through React's text-escaping; the only `dangerouslySetInnerHTML` usages are two small nonce'd inline `` scripts (theme init and the `ld+json` structured data). - The XSS defense is the strict CSP: `nonce` + `strict-dynamic`, no `unsafe-inline`/`unsafe-eval` in production, `script-src-attr 'none'`. diff --git a/eslint.config.mjs b/eslint.config.mjs index 05e726d..c44480d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -5,6 +5,9 @@ import nextTs from "eslint-config-next/typescript"; const eslintConfig = defineConfig([ ...nextVitals, ...nextTs, + // eslint-plugin-react's "detect" calls context.getFilename(), which ESLint + // 10 removed; a fixed version skips detection. + { settings: { react: { version: "19.2" } } }, // Override default ignores of eslint-config-next. globalIgnores([ // Default ignores of eslint-config-next: diff --git a/package.json b/package.json index 7eeabf5..89a75a2 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,11 @@ "build": "next build", "start": "next start", "lint": "eslint", - "typecheck": "tsc --noEmit", + "typecheck": "next typegen && tsc --noEmit", "db:generate": "drizzle-kit generate", "db:migrate": "drizzle-kit migrate", - "db:push": "drizzle-kit push" + "db:push": "drizzle-kit push", + "test": "vitest run" }, "dependencies": { "@upstash/ratelimit": "^2.0.8", @@ -33,11 +34,13 @@ "@types/node": "^26.4.0", "@types/react": "^19.2.18", "@types/react-dom": "^19.2.5", + "@typescript/native": "npm:typescript@^7.0.2", "drizzle-kit": "^0.31.10", "eslint": "^10.9.1", "eslint-config-next": "16.3.8", "tailwindcss": "^4.3.3", - "typescript": "^7.0.2" + "typescript": "npm:@typescript/typescript6@^6.0.2", + "vitest": "^5.1.1" }, "packageManager": "pnpm@11.24.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 89fb08a..ecfa81e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -64,6 +64,9 @@ importers: '@types/react-dom': specifier: ^19.2.5 version: 19.2.5(@types/react@19.2.18) + '@typescript/native': + specifier: npm:typescript@^7.0.2 + version: typescript@7.0.2 drizzle-kit: specifier: ^0.31.10 version: 0.31.10 @@ -72,13 +75,16 @@ importers: version: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) eslint-config-next: specifier: 16.3.8 - version: 16.3.8(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) + version: 16.3.8(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) tailwindcss: specifier: ^4.3.3 version: 4.3.3 typescript: - specifier: ^7.0.2 - version: 7.0.2 + specifier: npm:@typescript/typescript6@^6.0.2 + version: '@typescript/typescript6@6.0.2' + vitest: + specifier: ^5.1.1 + version: 5.1.1(@types/node@26.4.0)(vite@8.3.8(@types/node@26.4.0)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.12)) packages: @@ -159,15 +165,24 @@ packages: '@emnapi/core@1.10.0': resolution: {integrity: sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==} + '@emnapi/core@2.0.0-beta.2': + resolution: {integrity: sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==} + '@emnapi/runtime@1.10.0': resolution: {integrity: sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==} '@emnapi/runtime@1.11.3': resolution: {integrity: sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==} + '@emnapi/runtime@2.0.0-beta.2': + resolution: {integrity: sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==} + '@emnapi/wasi-threads@1.2.1': resolution: {integrity: sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==} + '@emnapi/wasi-threads@2.2.0': + resolution: {integrity: sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==} + '@esbuild-kit/core-utils@3.3.2': resolution: {integrity: sha512-sPRAnw9CdSsRmEtnsl2WXWdyquogVpB3yZ3dgwJfe8zrOzTsV7cJvmwrKVa+0ma5BoiGJ+BoqkMvawbayKUsqQ==} deprecated: 'Merged into tsx: https://tsx.hirok.io' @@ -861,6 +876,13 @@ packages: '@emnapi/core': ^1.7.1 || ^2.0.0-alpha.4 '@emnapi/runtime': ^1.7.1 || ^2.0.0-alpha.4 + '@napi-rs/wasm-runtime@1.2.6': + resolution: {integrity: sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==} + engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} + peerDependencies: + '@emnapi/core': ^1.7.1 || 2.0.0-beta.2 + '@emnapi/runtime': ^1.7.1 || 2.0.0-beta.2 + '@next/env@16.3.8': resolution: {integrity: sha512-Al9zqHVV7TJv0eFuOU4U7Lvv74PTih4Ch63sk2xCIpSTkE3udFnaOcnzP2lQVymiL7yS9Cj2iClUXlR3EQ5sEw==} @@ -935,6 +957,113 @@ packages: resolution: {integrity: sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA==} engines: {node: '>=12.4.0'} + '@oxc-project/types@0.156.0': + resolution: {integrity: sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==} + + '@rolldown/binding-android-arm-eabi@1.2.19': + resolution: {integrity: sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [android] + + '@rolldown/binding-android-arm64@1.2.19': + resolution: {integrity: sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [android] + + '@rolldown/binding-darwin-arm64@1.2.19': + resolution: {integrity: sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [darwin] + + '@rolldown/binding-darwin-x64@1.2.19': + resolution: {integrity: sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [darwin] + + '@rolldown/binding-freebsd-x64@1.2.19': + resolution: {integrity: sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [freebsd] + + '@rolldown/binding-linux-arm-gnueabihf@1.2.19': + resolution: {integrity: sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [linux] + + '@rolldown/binding-linux-arm64-gnu@1.2.19': + resolution: {integrity: sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-arm64-musl@1.2.19': + resolution: {integrity: sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + libc: [musl] + + '@rolldown/binding-linux-ppc64-gnu@1.2.19': + resolution: {integrity: sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [ppc64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-s390x-gnu@1.2.19': + resolution: {integrity: sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [s390x] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-x64-gnu@1.2.19': + resolution: {integrity: sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [glibc] + + '@rolldown/binding-linux-x64-musl@1.2.19': + resolution: {integrity: sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + libc: [musl] + + '@rolldown/binding-openharmony-arm64@1.2.19': + resolution: {integrity: sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [openharmony] + + '@rolldown/binding-wasm32-wasi@1.2.19': + resolution: {integrity: sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==} + engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} + cpu: [wasm32] + + '@rolldown/binding-win32-arm64-msvc@1.2.19': + resolution: {integrity: sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [win32] + + '@rolldown/binding-win32-x64-msvc@1.2.19': + resolution: {integrity: sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [win32] + + '@rolldown/pluginutils@1.1.1': + resolution: {integrity: sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==} + '@rtsao/scc@1.1.0': resolution: {integrity: sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==} @@ -1036,6 +1165,12 @@ packages: '@tybys/wasm-util@0.10.3': resolution: {integrity: sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==} + '@types/chai@5.2.3': + resolution: {integrity: sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==} + + '@types/deep-eql@4.0.2': + resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==} + '@types/esrecurse@4.3.1': resolution: {integrity: sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==} @@ -1238,6 +1373,10 @@ packages: cpu: [x64] os: [win32] + '@typescript/typescript6@6.0.2': + resolution: {integrity: sha512-mbCddXd+jm7hfx7w2YU64/Av4/NqqeG3GoRZgxPcgoTxYjhrcfJRw9ULch71SS4G+Q3bOXFhRvPqjguN0Hyp5w==} + hasBin: true + '@unrs/resolver-binding-android-arm-eabi@1.12.2': resolution: {integrity: sha512-g5T90pqg1bo/7mytQx6F4iBNC0Wsh9cu+z9veDbFjc7HjpesJFWD7QMS0NGStXM075+7dJPPVvBbpZlnrdpi/w==} cpu: [arm] @@ -1440,6 +1579,20 @@ packages: vue-router: optional: true + '@vitest/mocker@5.1.1': + resolution: {integrity: sha512-b2OgTB4+3ImWIVafXKazJXwLKwQxUNnix6b3xUvUTMh7RyXlrtzoxfZr8aEz9zkHOMAS4K5lu3TvFWoiVeVTQg==} + peerDependencies: + msw: ^2.4.9 || ^3.0.0 + vite: ^6.0.0 || ^7.0.0 || ^8.0.0 + peerDependenciesMeta: + msw: + optional: true + vite: + optional: true + + '@vitest/spy@5.1.1': + resolution: {integrity: sha512-6K8C6alQG1/Yc8/ZI22iJS7JEsxPdVzqtqDq+/xM4Z0mGVykemMVjLhqMy/q6/IHYG3kKD8hKSwRen/ZdyI9vQ==} + acorn-jsx@5.3.2: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: @@ -1489,6 +1642,10 @@ packages: resolution: {integrity: sha512-BNoCY6SXXPQ7gF2opIP4GBE+Xw7U+pHMYKuzjgCN3GwiaIR09UUeKfheyIry77QtrCBlC0KK0q5/TER/tYh3PQ==} engines: {node: '>= 0.4'} + assertion-error@2.0.1: + resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==} + engines: {node: '>=12'} + ast-types-flow@0.0.8: resolution: {integrity: sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ==} @@ -1557,6 +1714,10 @@ packages: caniuse-lite@1.0.30001810: resolution: {integrity: sha512-TITQPUkaz+aVk5GL6NhOdwk1aEaNTSDPsGFWrTuhKGtjTF70jL/Oht2W4c6rXUe5fu7Ie19VIahAXHIIiWWNeg==} + chai@6.3.0: + resolution: {integrity: sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==} + engines: {node: '>=18'} + client-only@0.0.1: resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} @@ -1754,6 +1915,9 @@ packages: resolution: {integrity: sha512-c/A0P0oxkACDc+cKWw8evLXK83oBKgn0qPOqCYT4x9uolpCIJAcYvJC9QYKNDRPsTeGyCrQ326jrvgZWdCdK5Q==} engines: {node: '>= 0.4'} + es-module-lexer@2.3.2: + resolution: {integrity: sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==} + es-object-atoms@1.1.2: resolution: {integrity: sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==} engines: {node: '>= 0.4'} @@ -1905,6 +2069,9 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + estree-walker@3.0.3: + resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} + esutils@2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} @@ -1913,6 +2080,10 @@ packages: resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} engines: {node: '>=10'} + expect-type@1.4.0: + resolution: {integrity: sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==} + engines: {node: '>=12.0.0'} + fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -2264,30 +2435,60 @@ packages: cpu: [arm64] os: [android] + lightningcss-android-arm64@1.33.0: + resolution: {integrity: sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [android] + lightningcss-darwin-arm64@1.32.0: resolution: {integrity: sha512-RzeG9Ju5bag2Bv1/lwlVJvBE3q6TtXskdZLLCyfg5pt+HLz9BqlICO7LZM7VHNTTn/5PRhHFBSjk5lc4cmscPQ==} engines: {node: '>= 12.0.0'} cpu: [arm64] os: [darwin] + lightningcss-darwin-arm64@1.33.0: + resolution: {integrity: sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [darwin] + lightningcss-darwin-x64@1.32.0: resolution: {integrity: sha512-U+QsBp2m/s2wqpUYT/6wnlagdZbtZdndSmut/NJqlCcMLTWp5muCrID+K5UJ6jqD2BFshejCYXniPDbNh73V8w==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [darwin] + lightningcss-darwin-x64@1.33.0: + resolution: {integrity: sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [darwin] + lightningcss-freebsd-x64@1.32.0: resolution: {integrity: sha512-JCTigedEksZk3tHTTthnMdVfGf61Fky8Ji2E4YjUTEQX14xiy/lTzXnu1vwiZe3bYe0q+SpsSH/CTeDXK6WHig==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [freebsd] + lightningcss-freebsd-x64@1.33.0: + resolution: {integrity: sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [freebsd] + lightningcss-linux-arm-gnueabihf@1.32.0: resolution: {integrity: sha512-x6rnnpRa2GL0zQOkt6rts3YDPzduLpWvwAF6EMhXFVZXD4tPrBkEFqzGowzCsIWsPjqSK+tyNEODUBXeeVHSkw==} engines: {node: '>= 12.0.0'} cpu: [arm] os: [linux] + lightningcss-linux-arm-gnueabihf@1.33.0: + resolution: {integrity: sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm] + os: [linux] + lightningcss-linux-arm64-gnu@1.32.0: resolution: {integrity: sha512-0nnMyoyOLRJXfbMOilaSRcLH3Jw5z9HDNGfT/gwCPgaDjnx0i8w7vBzFLFR1f6CMLKF8gVbebmkUN3fa/kQJpQ==} engines: {node: '>= 12.0.0'} @@ -2295,6 +2496,13 @@ packages: os: [linux] libc: [glibc] + lightningcss-linux-arm64-gnu@1.33.0: + resolution: {integrity: sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + libc: [glibc] + lightningcss-linux-arm64-musl@1.32.0: resolution: {integrity: sha512-UpQkoenr4UJEzgVIYpI80lDFvRmPVg6oqboNHfoH4CQIfNA+HOrZ7Mo7KZP02dC6LjghPQJeBsvXhJod/wnIBg==} engines: {node: '>= 12.0.0'} @@ -2302,6 +2510,13 @@ packages: os: [linux] libc: [musl] + lightningcss-linux-arm64-musl@1.33.0: + resolution: {integrity: sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + libc: [musl] + lightningcss-linux-x64-gnu@1.32.0: resolution: {integrity: sha512-V7Qr52IhZmdKPVr+Vtw8o+WLsQJYCTd8loIfpDaMRWGUZfBOYEJeyJIkqGIDMZPwPx24pUMfwSxxI8phr/MbOA==} engines: {node: '>= 12.0.0'} @@ -2309,6 +2524,13 @@ packages: os: [linux] libc: [glibc] + lightningcss-linux-x64-gnu@1.33.0: + resolution: {integrity: sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + libc: [glibc] + lightningcss-linux-x64-musl@1.32.0: resolution: {integrity: sha512-bYcLp+Vb0awsiXg/80uCRezCYHNg1/l3mt0gzHnWV9XP1W5sKa5/TCdGWaR/zBM2PeF/HbsQv/j2URNOiVuxWg==} engines: {node: '>= 12.0.0'} @@ -2316,22 +2538,45 @@ packages: os: [linux] libc: [musl] + lightningcss-linux-x64-musl@1.33.0: + resolution: {integrity: sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + libc: [musl] + lightningcss-win32-arm64-msvc@1.32.0: resolution: {integrity: sha512-8SbC8BR40pS6baCM8sbtYDSwEVQd4JlFTOlaD3gWGHfThTcABnNDBda6eTZeqbofalIJhFx0qKzgHJmcPTnGdw==} engines: {node: '>= 12.0.0'} cpu: [arm64] os: [win32] + lightningcss-win32-arm64-msvc@1.33.0: + resolution: {integrity: sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [win32] + lightningcss-win32-x64-msvc@1.32.0: resolution: {integrity: sha512-Amq9B/SoZYdDi1kFrojnoqPLxYhQ4Wo5XiL8EVJrVsB8ARoC1PWW6VGtT0WKCemjy8aC+louJnjS7U18x3b06Q==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [win32] + lightningcss-win32-x64-msvc@1.33.0: + resolution: {integrity: sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [win32] + lightningcss@1.32.0: resolution: {integrity: sha512-NXYBzinNrblfraPGyrbPoD19C1h9lfI/1mzgWYvXUTe414Gz/X1FD2XBZSZM7rRTrMA8JL3OtAaGifrIKhQ5yQ==} engines: {node: '>= 12.0.0'} + lightningcss@1.33.0: + resolution: {integrity: sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==} + engines: {node: '>= 12.0.0'} + locate-path@6.0.0: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} @@ -2351,6 +2596,9 @@ packages: magic-string@0.30.21: resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==} + magic-string@1.4.5: + resolution: {integrity: sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==} + math-intrinsics@1.1.0: resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==} engines: {node: '>= 0.4'} @@ -2388,6 +2636,11 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true + nanoid@3.3.20: + resolution: {integrity: sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + nanoid@6.0.1: resolution: {integrity: sha512-3wVS3i51pE2pi1k5FFL/95BGfVS0kSsvDVuGXHOtxox/TywUmtgq+3qiTOTbs9J7KfHaXPiN171k/A6dBnaXFw==} engines: {node: ^22 || ^24 || >=26} @@ -2466,6 +2719,10 @@ packages: resolution: {integrity: sha512-gXah6aZrcUxjWg2zR2MwouP2eHlCBzdV4pygudehaKXSGW4v2AsRQUK+lwwXhii6KFZcunEnmSUoYp5CXibxtA==} engines: {node: '>= 0.4'} + obug@3.0.0: + resolution: {integrity: sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==} + engines: {node: '>=12.20.0'} + onetime@5.1.2: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} engines: {node: '>=6'} @@ -2524,6 +2781,10 @@ packages: resolution: {integrity: sha512-u82N74LFzG8ca+dD8puPnplTXoGH4fTPpVGuIbt36G3qvNlkvfD0lEAZSxaly3KX8TS/L1A1gsCEmvKmBcVbkQ==} engines: {node: ^10 || ^12 || >=14} + postcss@8.5.33: + resolution: {integrity: sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==} + engines: {node: ^10 || ^12 || >=14} + postgres@3.4.9: resolution: {integrity: sha512-GD3qdB0x1z9xgFI6cdRD6xu2Sp2WCOEoe3mtnyB5Ee0XrrL5Pe+e4CCnJrRMnL1zYtRDZmQQVbvOttLnKDLnaw==} engines: {node: '>=12'} @@ -2578,6 +2839,11 @@ packages: resolution: {integrity: sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} + rolldown@1.2.19: + resolution: {integrity: sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -2667,6 +2933,9 @@ packages: stable-hash@0.0.5: resolution: {integrity: sha512-+L3ccpzibovGXFK+Ap/f8LOS0ahMrHTf3xu7mMLSpEGU0EO9ucaysSylKo9eRDFNhWve/y275iPmIZ4z39a9iA==} + std-env@4.3.0: + resolution: {integrity: sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==} + stop-iteration-iterator@1.1.0: resolution: {integrity: sha512-eLoXW/DHyl62zxY4SCaIgnRhuMr6ri4juEYARS8E6sCEqzKpOiE521Ucofdx+KnDZl5xmvGYaaKCk5FEOxJCoQ==} engines: {node: '>= 0.4'} @@ -2734,6 +3003,14 @@ packages: resolution: {integrity: sha512-nt6AMGKW1p/70DF/hGBdJB57B8Tspmbp5gfJ8ilhLnt7kkr2ye7hzD6NVG8GGErk2HWF34igrL2CXmNIkzKqKw==} engines: {node: '>=18'} + tinybench@6.2.4: + resolution: {integrity: sha512-SQ52jEncXxbMCzJuY2A/jGIbbAu6NYsBWW7grz2pNE+EnzQdoGaoBfpk4qC/opE7qiUcGmGgaGIz5EoHdS1O9w==} + engines: {node: '>=20.0.0'} + + tinyexec@1.3.1: + resolution: {integrity: sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==} + engines: {node: '>=18'} + tinyglobby@0.2.17: resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==} engines: {node: '>=12.0.0'} @@ -2786,6 +3063,11 @@ packages: eslint: ^8.57.0 || ^9.0.0 || ^10.0.0 typescript: '>=4.8.4 <6.1.0' + typescript@6.0.3: + resolution: {integrity: sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==} + engines: {node: '>=14.17'} + hasBin: true + typescript@7.0.2: resolution: {integrity: sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==} engines: {node: '>=16.20.0'} @@ -2817,6 +3099,90 @@ packages: uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} + vite@8.3.8: + resolution: {integrity: sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + peerDependencies: + '@types/node': ^20.19.0 || >=22.12.0 + '@vitejs/devtools': ^0.7.1 || ^0.8.0 + esbuild: ^0.27.0 || ^0.28.0 + jiti: '>=1.21.0' + less: ^4.0.0 + sass: ^1.70.0 + sass-embedded: ^1.70.0 + stylus: '>=0.54.8' + sugarss: ^5.0.0 + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + '@types/node': + optional: true + '@vitejs/devtools': + optional: true + esbuild: + optional: true + jiti: + optional: true + less: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + + vitest@5.1.1: + resolution: {integrity: sha512-trVmzUFOSraCZcI3uZIMD5FqBh4atFkC/XuJP/IU7qtyQay0FCs3Ia+0QiQ2JJwGyWG/xrcBoJNel2+O7kEZ0g==} + engines: {node: ^22.12.0 || ^24.0.0 || >=26.0.0} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@opentelemetry/api': ^1.9.0 + '@types/node': ^22.0.0 || >=24.0.0 + '@vitest/browser-playwright': 5.1.1 + '@vitest/browser-preview': 5.1.1 + '@vitest/browser-webdriverio': ^5.0.0-beta.5 || >=5.0.0 + '@vitest/coverage-istanbul': 5.1.1 + '@vitest/coverage-v8': 5.1.1 + '@vitest/ui': 5.1.1 + happy-dom: '*' + jsdom: '*' + vite: ^6.4.0 || ^7.0.0 || ^8.0.0 + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@opentelemetry/api': + optional: true + '@types/node': + optional: true + '@vitest/browser-playwright': + optional: true + '@vitest/browser-preview': + optional: true + '@vitest/browser-webdriverio': + optional: true + '@vitest/coverage-istanbul': + optional: true + '@vitest/coverage-v8': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + which-boxed-primitive@1.1.1: resolution: {integrity: sha512-TbX3mj8n0odCBFVlY8AxkqcHASw3L60jIuF8jFP78az3C2YhmGvqbHBpAjTRH2/xqYunrJ9g1jSyjCjpoWzIAA==} engines: {node: '>= 0.4'} @@ -2838,6 +3204,11 @@ packages: engines: {node: '>= 8'} hasBin: true + why-is-node-running@3.2.1: + resolution: {integrity: sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==} + engines: {node: '>=20.11'} + hasBin: true + word-wrap@1.2.5: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} @@ -2981,6 +3352,12 @@ snapshots: tslib: 2.8.1 optional: true + '@emnapi/core@2.0.0-beta.2': + dependencies: + '@emnapi/wasi-threads': 2.2.0 + tslib: 2.8.1 + optional: true + '@emnapi/runtime@1.10.0': dependencies: tslib: 2.8.1 @@ -2991,11 +3368,21 @@ snapshots: tslib: 2.8.1 optional: true + '@emnapi/runtime@2.0.0-beta.2': + dependencies: + tslib: 2.8.1 + optional: true + '@emnapi/wasi-threads@1.2.1': dependencies: tslib: 2.8.1 optional: true + '@emnapi/wasi-threads@2.2.0': + dependencies: + tslib: 2.8.1 + optional: true + '@esbuild-kit/core-utils@3.3.2': dependencies: esbuild: 0.18.20 @@ -3412,6 +3799,13 @@ snapshots: '@tybys/wasm-util': 0.10.3 optional: true + '@napi-rs/wasm-runtime@1.2.6(@emnapi/core@2.0.0-beta.2)(@emnapi/runtime@2.0.0-beta.2)': + dependencies: + '@emnapi/core': 2.0.0-beta.2 + '@emnapi/runtime': 2.0.0-beta.2 + '@tybys/wasm-util': 0.10.3 + optional: true + '@next/env@16.3.8': {} '@next/eslint-plugin-next@16.3.8(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))': @@ -3459,6 +3853,62 @@ snapshots: '@nolyfill/is-core-module@1.0.39': {} + '@oxc-project/types@0.156.0': {} + + '@rolldown/binding-android-arm-eabi@1.2.19': + optional: true + + '@rolldown/binding-android-arm64@1.2.19': + optional: true + + '@rolldown/binding-darwin-arm64@1.2.19': + optional: true + + '@rolldown/binding-darwin-x64@1.2.19': + optional: true + + '@rolldown/binding-freebsd-x64@1.2.19': + optional: true + + '@rolldown/binding-linux-arm-gnueabihf@1.2.19': + optional: true + + '@rolldown/binding-linux-arm64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-arm64-musl@1.2.19': + optional: true + + '@rolldown/binding-linux-ppc64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-s390x-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-x64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-x64-musl@1.2.19': + optional: true + + '@rolldown/binding-openharmony-arm64@1.2.19': + optional: true + + '@rolldown/binding-wasm32-wasi@1.2.19': + dependencies: + '@emnapi/core': 2.0.0-beta.2 + '@emnapi/runtime': 2.0.0-beta.2 + '@napi-rs/wasm-runtime': 1.2.6(@emnapi/core@2.0.0-beta.2)(@emnapi/runtime@2.0.0-beta.2) + optional: true + + '@rolldown/binding-win32-arm64-msvc@1.2.19': + optional: true + + '@rolldown/binding-win32-x64-msvc@1.2.19': + optional: true + + '@rolldown/pluginutils@1.1.1': {} + '@rtsao/scc@1.1.0': {} '@swc/helpers@0.5.23': @@ -3539,6 +3989,13 @@ snapshots: tslib: 2.8.1 optional: true + '@types/chai@5.2.3': + dependencies: + '@types/deep-eql': 4.0.2 + assertion-error: 2.0.1 + + '@types/deep-eql@4.0.2': {} + '@types/esrecurse@4.3.1': {} '@types/estree@1.0.9': {} @@ -3559,40 +4016,40 @@ snapshots: dependencies: csstype: 3.2.3 - '@typescript-eslint/eslint-plugin@8.68.0(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2)': + '@typescript-eslint/eslint-plugin@8.68.0(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)': dependencies: '@eslint-community/regexpp': 4.12.2 - '@typescript-eslint/parser': 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) + '@typescript-eslint/parser': 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) '@typescript-eslint/scope-manager': 8.68.0 - '@typescript-eslint/type-utils': 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) - '@typescript-eslint/utils': 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) + '@typescript-eslint/type-utils': 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) + '@typescript-eslint/utils': 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) '@typescript-eslint/visitor-keys': 8.68.0 eslint: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) ignore: 7.0.6 natural-compare: 1.4.0 - ts-api-utils: 2.5.0(typescript@7.0.2) - typescript: 7.0.2 + ts-api-utils: 2.5.0(@typescript/typescript6@6.0.2) + typescript: '@typescript/typescript6@6.0.2' transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2)': + '@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)': dependencies: '@typescript-eslint/scope-manager': 8.68.0 '@typescript-eslint/types': 8.68.0 - '@typescript-eslint/typescript-estree': 8.68.0(supports-color@7.2.0)(typescript@7.0.2) + '@typescript-eslint/typescript-estree': 8.68.0(@typescript/typescript6@6.0.2)(supports-color@7.2.0) '@typescript-eslint/visitor-keys': 8.68.0 debug: 4.4.3(supports-color@7.2.0) eslint: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) - typescript: 7.0.2 + typescript: '@typescript/typescript6@6.0.2' transitivePeerDependencies: - supports-color - '@typescript-eslint/project-service@8.68.0(supports-color@7.2.0)(typescript@7.0.2)': + '@typescript-eslint/project-service@8.68.0(@typescript/typescript6@6.0.2)(supports-color@7.2.0)': dependencies: - '@typescript-eslint/tsconfig-utils': 8.68.0(typescript@7.0.2) + '@typescript-eslint/tsconfig-utils': 8.68.0(@typescript/typescript6@6.0.2) '@typescript-eslint/types': 8.68.0 debug: 4.4.3(supports-color@7.2.0) - typescript: 7.0.2 + typescript: '@typescript/typescript6@6.0.2' transitivePeerDependencies: - supports-color @@ -3601,47 +4058,47 @@ snapshots: '@typescript-eslint/types': 8.68.0 '@typescript-eslint/visitor-keys': 8.68.0 - '@typescript-eslint/tsconfig-utils@8.68.0(typescript@7.0.2)': + '@typescript-eslint/tsconfig-utils@8.68.0(@typescript/typescript6@6.0.2)': dependencies: - typescript: 7.0.2 + typescript: '@typescript/typescript6@6.0.2' - '@typescript-eslint/type-utils@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2)': + '@typescript-eslint/type-utils@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)': dependencies: '@typescript-eslint/types': 8.68.0 - '@typescript-eslint/typescript-estree': 8.68.0(supports-color@7.2.0)(typescript@7.0.2) - '@typescript-eslint/utils': 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) + '@typescript-eslint/typescript-estree': 8.68.0(@typescript/typescript6@6.0.2)(supports-color@7.2.0) + '@typescript-eslint/utils': 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) debug: 4.4.3(supports-color@7.2.0) eslint: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) - ts-api-utils: 2.5.0(typescript@7.0.2) - typescript: 7.0.2 + ts-api-utils: 2.5.0(@typescript/typescript6@6.0.2) + typescript: '@typescript/typescript6@6.0.2' transitivePeerDependencies: - supports-color '@typescript-eslint/types@8.68.0': {} - '@typescript-eslint/typescript-estree@8.68.0(supports-color@7.2.0)(typescript@7.0.2)': + '@typescript-eslint/typescript-estree@8.68.0(@typescript/typescript6@6.0.2)(supports-color@7.2.0)': dependencies: - '@typescript-eslint/project-service': 8.68.0(supports-color@7.2.0)(typescript@7.0.2) - '@typescript-eslint/tsconfig-utils': 8.68.0(typescript@7.0.2) + '@typescript-eslint/project-service': 8.68.0(@typescript/typescript6@6.0.2)(supports-color@7.2.0) + '@typescript-eslint/tsconfig-utils': 8.68.0(@typescript/typescript6@6.0.2) '@typescript-eslint/types': 8.68.0 '@typescript-eslint/visitor-keys': 8.68.0 debug: 4.4.3(supports-color@7.2.0) minimatch: 10.2.6 semver: 7.8.5 tinyglobby: 0.2.17 - ts-api-utils: 2.5.0(typescript@7.0.2) - typescript: 7.0.2 + ts-api-utils: 2.5.0(@typescript/typescript6@6.0.2) + typescript: '@typescript/typescript6@6.0.2' transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2)': + '@typescript-eslint/utils@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)': dependencies: '@eslint-community/eslint-utils': 4.10.1(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0)) '@typescript-eslint/scope-manager': 8.68.0 '@typescript-eslint/types': 8.68.0 - '@typescript-eslint/typescript-estree': 8.68.0(supports-color@7.2.0)(typescript@7.0.2) + '@typescript-eslint/typescript-estree': 8.68.0(@typescript/typescript6@6.0.2)(supports-color@7.2.0) eslint: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) - typescript: 7.0.2 + typescript: '@typescript/typescript6@6.0.2' transitivePeerDependencies: - supports-color @@ -3710,6 +4167,10 @@ snapshots: '@typescript/typescript-win32-x64@7.0.2': optional: true + '@typescript/typescript6@6.0.2': + dependencies: + '@typescript/old': typescript@6.0.3 + '@unrs/resolver-binding-android-arm-eabi@1.12.2': optional: true @@ -3827,6 +4288,17 @@ snapshots: next: 16.3.8(@babel/core@7.29.7(supports-color@7.2.0))(@types/node@26.4.0)(react-dom@19.2.8(react@19.2.8))(react@19.2.8) react: 19.2.8 + '@vitest/mocker@5.1.1(vite@8.3.8(@types/node@26.4.0)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.12))': + dependencies: + '@jridgewell/trace-mapping': 0.3.31 + '@vitest/spy': 5.1.1 + estree-walker: 3.0.3 + magic-string: 1.4.5 + optionalDependencies: + vite: 8.3.8(@types/node@26.4.0)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.12) + + '@vitest/spy@5.1.1': {} + acorn-jsx@5.3.2(acorn@8.18.0): dependencies: acorn: 8.18.0 @@ -3909,6 +4381,8 @@ snapshots: get-intrinsic: 1.3.0 is-array-buffer: 3.0.5 + assertion-error@2.0.1: {} + ast-types-flow@0.0.8: {} async-function@1.0.0: {} @@ -3973,6 +4447,8 @@ snapshots: caniuse-lite@1.0.30001810: {} + chai@6.3.0: {} + client-only@0.0.1: {} concat-map@0.0.1: {} @@ -4153,6 +4629,8 @@ snapshots: iterator.prototype: 1.1.5 math-intrinsics: 1.1.0 + es-module-lexer@2.3.2: {} + es-object-atoms@1.1.2: dependencies: es-errors: 1.3.0 @@ -4264,20 +4742,20 @@ snapshots: escape-string-regexp@4.0.0: {} - eslint-config-next@16.3.8(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2): + eslint-config-next@16.3.8(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0): dependencies: '@next/eslint-plugin-next': 16.3.8(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0)) eslint: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) eslint-import-resolver-node: 0.3.10(supports-color@7.2.0) eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) eslint-plugin-jsx-a11y: 6.10.2(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0)) eslint-plugin-react: 7.37.5(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0)) eslint-plugin-react-hooks: 7.1.1(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) globals: 16.4.0 - typescript-eslint: 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) + typescript-eslint: 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) optionalDependencies: - typescript: 7.0.2 + typescript: '@typescript/typescript6@6.0.2' transitivePeerDependencies: - '@typescript-eslint/parser' - eslint-import-resolver-webpack @@ -4303,22 +4781,22 @@ snapshots: tinyglobby: 0.2.17 unrs-resolver: 1.12.2 optionalDependencies: - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) transitivePeerDependencies: - supports-color - eslint-module-utils@2.14.0(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint-import-resolver-node@0.3.10(supports-color@7.2.0))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0): + eslint-module-utils@2.14.0(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(eslint-import-resolver-node@0.3.10(supports-color@7.2.0))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0): dependencies: debug: 3.2.7(supports-color@7.2.0) optionalDependencies: - '@typescript-eslint/parser': 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) + '@typescript-eslint/parser': 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) eslint: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) eslint-import-resolver-node: 0.3.10(supports-color@7.2.0) eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) transitivePeerDependencies: - supports-color - eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0): + eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.9 @@ -4329,7 +4807,7 @@ snapshots: doctrine: 2.1.0 eslint: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) eslint-import-resolver-node: 0.3.10(supports-color@7.2.0) - eslint-module-utils: 2.14.0(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint-import-resolver-node@0.3.10(supports-color@7.2.0))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) + eslint-module-utils: 2.14.0(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(eslint-import-resolver-node@0.3.10(supports-color@7.2.0))(eslint-import-resolver-typescript@3.10.1)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) hasown: 2.0.4 is-core-module: 2.16.2 is-glob: 4.0.3 @@ -4341,7 +4819,7 @@ snapshots: string.prototype.trimend: 1.0.10 tsconfig-paths: 3.15.0 optionalDependencies: - '@typescript-eslint/parser': 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) + '@typescript-eslint/parser': 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) transitivePeerDependencies: - eslint-import-resolver-typescript - eslint-import-resolver-webpack @@ -4463,6 +4941,10 @@ snapshots: estraverse@5.3.0: {} + estree-walker@3.0.3: + dependencies: + '@types/estree': 1.0.9 + esutils@2.0.3: {} execa@5.1.1: @@ -4477,6 +4959,8 @@ snapshots: signal-exit: 3.0.7 strip-final-newline: 2.0.0 + expect-type@1.4.0: {} + fast-deep-equal@3.1.3: {} fast-glob@3.3.1: @@ -4818,36 +5302,69 @@ snapshots: lightningcss-android-arm64@1.32.0: optional: true + lightningcss-android-arm64@1.33.0: + optional: true + lightningcss-darwin-arm64@1.32.0: optional: true + lightningcss-darwin-arm64@1.33.0: + optional: true + lightningcss-darwin-x64@1.32.0: optional: true + lightningcss-darwin-x64@1.33.0: + optional: true + lightningcss-freebsd-x64@1.32.0: optional: true + lightningcss-freebsd-x64@1.33.0: + optional: true + lightningcss-linux-arm-gnueabihf@1.32.0: optional: true + lightningcss-linux-arm-gnueabihf@1.33.0: + optional: true + lightningcss-linux-arm64-gnu@1.32.0: optional: true + lightningcss-linux-arm64-gnu@1.33.0: + optional: true + lightningcss-linux-arm64-musl@1.32.0: optional: true + lightningcss-linux-arm64-musl@1.33.0: + optional: true + lightningcss-linux-x64-gnu@1.32.0: optional: true + lightningcss-linux-x64-gnu@1.33.0: + optional: true + lightningcss-linux-x64-musl@1.32.0: optional: true + lightningcss-linux-x64-musl@1.33.0: + optional: true + lightningcss-win32-arm64-msvc@1.32.0: optional: true + lightningcss-win32-arm64-msvc@1.33.0: + optional: true + lightningcss-win32-x64-msvc@1.32.0: optional: true + lightningcss-win32-x64-msvc@1.33.0: + optional: true + lightningcss@1.32.0: dependencies: detect-libc: 2.1.2 @@ -4864,6 +5381,22 @@ snapshots: lightningcss-win32-arm64-msvc: 1.32.0 lightningcss-win32-x64-msvc: 1.32.0 + lightningcss@1.33.0: + dependencies: + detect-libc: 2.1.2 + optionalDependencies: + lightningcss-android-arm64: 1.33.0 + lightningcss-darwin-arm64: 1.33.0 + lightningcss-darwin-x64: 1.33.0 + lightningcss-freebsd-x64: 1.33.0 + lightningcss-linux-arm-gnueabihf: 1.33.0 + lightningcss-linux-arm64-gnu: 1.33.0 + lightningcss-linux-arm64-musl: 1.33.0 + lightningcss-linux-x64-gnu: 1.33.0 + lightningcss-linux-x64-musl: 1.33.0 + lightningcss-win32-arm64-msvc: 1.33.0 + lightningcss-win32-x64-msvc: 1.33.0 + locate-path@6.0.0: dependencies: p-locate: 5.0.0 @@ -4884,6 +5417,10 @@ snapshots: dependencies: '@jridgewell/sourcemap-codec': 1.6.0 + magic-string@1.4.5: + dependencies: + '@jridgewell/sourcemap-codec': 1.6.0 + math-intrinsics@1.1.0: {} merge-stream@2.0.0: {} @@ -4911,6 +5448,8 @@ snapshots: nanoid@3.3.18: {} + nanoid@3.3.20: {} + nanoid@6.0.1: {} napi-postinstall@0.3.4: {} @@ -4997,6 +5536,8 @@ snapshots: define-properties: 1.2.1 es-object-atoms: 1.1.2 + obug@3.0.0: {} + onetime@5.1.2: dependencies: mimic-fn: 2.1.0 @@ -5053,6 +5594,12 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.2 + postcss@8.5.33: + dependencies: + nanoid: 3.3.20 + picocolors: 1.1.1 + source-map-js: 1.2.2 + postgres@3.4.9: {} prelude-ls@1.2.1: {} @@ -5111,6 +5658,28 @@ snapshots: reusify@1.1.0: {} + rolldown@1.2.19: + dependencies: + '@oxc-project/types': 0.156.0 + '@rolldown/pluginutils': 1.1.1 + optionalDependencies: + '@rolldown/binding-android-arm-eabi': 1.2.19 + '@rolldown/binding-android-arm64': 1.2.19 + '@rolldown/binding-darwin-arm64': 1.2.19 + '@rolldown/binding-darwin-x64': 1.2.19 + '@rolldown/binding-freebsd-x64': 1.2.19 + '@rolldown/binding-linux-arm-gnueabihf': 1.2.19 + '@rolldown/binding-linux-arm64-gnu': 1.2.19 + '@rolldown/binding-linux-arm64-musl': 1.2.19 + '@rolldown/binding-linux-ppc64-gnu': 1.2.19 + '@rolldown/binding-linux-s390x-gnu': 1.2.19 + '@rolldown/binding-linux-x64-gnu': 1.2.19 + '@rolldown/binding-linux-x64-musl': 1.2.19 + '@rolldown/binding-openharmony-arm64': 1.2.19 + '@rolldown/binding-wasm32-wasi': 1.2.19 + '@rolldown/binding-win32-arm64-msvc': 1.2.19 + '@rolldown/binding-win32-x64-msvc': 1.2.19 + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 @@ -5243,6 +5812,8 @@ snapshots: stable-hash@0.0.5: {} + std-env@4.3.0: {} + stop-iteration-iterator@1.1.0: dependencies: es-errors: 1.3.0 @@ -5323,6 +5894,10 @@ snapshots: throttleit@2.1.0: {} + tinybench@6.2.4: {} + + tinyexec@1.3.1: {} + tinyglobby@0.2.17: dependencies: fdir: 6.5.0(picomatch@4.0.7) @@ -5332,9 +5907,9 @@ snapshots: dependencies: is-number: 7.0.0 - ts-api-utils@2.5.0(typescript@7.0.2): + ts-api-utils@2.5.0(@typescript/typescript6@6.0.2): dependencies: - typescript: 7.0.2 + typescript: '@typescript/typescript6@6.0.2' tsconfig-paths@3.15.0: dependencies: @@ -5388,17 +5963,19 @@ snapshots: possible-typed-array-names: 1.1.0 reflect.getprototypeof: 1.0.10 - typescript-eslint@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2): + typescript-eslint@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0): dependencies: - '@typescript-eslint/eslint-plugin': 8.68.0(@typescript-eslint/parser@8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2))(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) - '@typescript-eslint/parser': 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) - '@typescript-eslint/typescript-estree': 8.68.0(supports-color@7.2.0)(typescript@7.0.2) - '@typescript-eslint/utils': 8.68.0(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0)(typescript@7.0.2) + '@typescript-eslint/eslint-plugin': 8.68.0(@typescript-eslint/parser@8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0))(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) + '@typescript-eslint/parser': 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) + '@typescript-eslint/typescript-estree': 8.68.0(@typescript/typescript6@6.0.2)(supports-color@7.2.0) + '@typescript-eslint/utils': 8.68.0(@typescript/typescript6@6.0.2)(eslint@10.9.1(jiti@2.7.0)(supports-color@7.2.0))(supports-color@7.2.0) eslint: 10.9.1(jiti@2.7.0)(supports-color@7.2.0) - typescript: 7.0.2 + typescript: '@typescript/typescript6@6.0.2' transitivePeerDependencies: - supports-color + typescript@6.0.3: {} + typescript@7.0.2: optionalDependencies: '@typescript/typescript-aix-ppc64': 7.0.2 @@ -5472,6 +6049,41 @@ snapshots: dependencies: punycode: 2.3.1 + vite@8.3.8(@types/node@26.4.0)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.12): + dependencies: + lightningcss: 1.33.0 + picomatch: 4.0.7 + postcss: 8.5.33 + rolldown: 1.2.19 + tinyglobby: 0.2.17 + optionalDependencies: + '@types/node': 26.4.0 + esbuild: 0.28.2 + fsevents: 2.3.3 + jiti: 2.7.0 + tsx: 4.23.12 + + vitest@5.1.1(@types/node@26.4.0)(vite@8.3.8(@types/node@26.4.0)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.12)): + dependencies: + '@types/chai': 5.2.3 + '@vitest/mocker': 5.1.1(vite@8.3.8(@types/node@26.4.0)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.12)) + chai: 6.3.0 + es-module-lexer: 2.3.2 + expect-type: 1.4.0 + magic-string: 1.4.5 + obug: 3.0.0 + picomatch: 4.0.7 + std-env: 4.3.0 + tinybench: 6.2.4 + tinyexec: 1.3.1 + tinyglobby: 0.2.17 + vite: 8.3.8(@types/node@26.4.0)(esbuild@0.28.2)(jiti@2.7.0)(tsx@4.23.12) + why-is-node-running: 3.2.1 + optionalDependencies: + '@types/node': 26.4.0 + transitivePeerDependencies: + - msw + which-boxed-primitive@1.1.1: dependencies: is-bigint: 1.1.0 @@ -5517,6 +6129,8 @@ snapshots: dependencies: isexe: 2.0.0 + why-is-node-running@3.2.1: {} + word-wrap@1.2.5: {} xdg-app-paths@5.5.1: diff --git a/src/app/[code]/page.tsx b/src/app/[code]/page.tsx index f7a3dd6..ab41cf4 100644 --- a/src/app/[code]/page.tsx +++ b/src/app/[code]/page.tsx @@ -1,13 +1,9 @@ import { notFound } from "next/navigation"; import Link from "next/link"; import type { Metadata } from "next"; -import { after } from "next/server"; import { ArrowLeft } from "lucide-react"; -import { - getPasteGateByCode, - deletePaste, - deleteAttachmentsBlobs, -} from "@/lib/paste-service"; +import { getPasteGateByCode } from "@/lib/paste-service"; +import { deleteAfterResponse, isExpired } from "@/lib/paste-view"; import { isValidCode } from "@/lib/ids"; import PasswordGate from "@/components/password-gate"; import PasteReveal from "@/components/paste-reveal"; @@ -55,11 +51,8 @@ export default async function PastePage({ const paste = isValidCode(code) ? await getPasteGateByCode(code) : null; if (!paste) notFound(); - if (paste.expiresAt && paste.expiresAt.getTime() < Date.now()) { - after(async () => { - await deleteAttachmentsBlobs(code); - await deletePaste(code); - }); + if (isExpired(paste)) { + deleteAfterResponse(code); notFound(); } diff --git a/src/app/api/pastes/[code]/delete/route.ts b/src/app/api/pastes/[code]/delete/route.ts index 0d6142a..a51cae2 100644 --- a/src/app/api/pastes/[code]/delete/route.ts +++ b/src/app/api/pastes/[code]/delete/route.ts @@ -3,8 +3,7 @@ import { timingSafeEqual } from "node:crypto"; import { z } from "zod"; import { getDeleteTokenHash, - deletePaste, - deleteAttachmentsBlobs, + deletePasteWithBlobs, } from "@/lib/paste-service"; import { hashDeleteToken } from "@/lib/crypto"; import { isValidCode } from "@/lib/ids"; @@ -57,11 +56,7 @@ export async function POST( return NextResponse.json({ error: "Invalid delete link" }, { status: 403 }); } - // Blobs first: their paths live in the attachment rows the paste delete - // cascades away. Anything a failed blob delete leaves behind is swept by the - // daily orphan cleanup. - await deleteAttachmentsBlobs(code); - await deletePaste(code); + await deletePasteWithBlobs(code); return NextResponse.json({ ok: true }); } diff --git a/src/app/api/pastes/[code]/files/[id]/route.ts b/src/app/api/pastes/[code]/files/[id]/route.ts index 1a4b9e5..eda3b4f 100644 --- a/src/app/api/pastes/[code]/files/[id]/route.ts +++ b/src/app/api/pastes/[code]/files/[id]/route.ts @@ -5,19 +5,18 @@ import { createDecipheriv, timingSafeEqual } from "node:crypto"; import { createInflate } from "node:zlib"; import { getAttachmentForDownload, - deletePaste, claimPasteForView, - deleteAttachmentsBlobs, } from "@/lib/paste-service"; +import { deleteAfterResponse, unavailableResponse } from "@/lib/paste-view"; import { unwrapKey, openAttachmentMeta } from "@/lib/crypto"; import { isValidCode } from "@/lib/ids"; import { checkReadLimit, - isPasswordLocked, - recordPasswordFailure, + beginPasswordAttempt, + refundPasswordAttempt, PASSWORD_LOCKED_MESSAGE, } from "@/lib/rate-limit"; -import { ATTACHMENT_ID } from "@/lib/validation"; +import { ATTACHMENT_ID, contentKeySchema } from "@/lib/validation"; export const runtime = "nodejs"; export const dynamic = "force-dynamic"; @@ -77,28 +76,19 @@ export async function GET( } const { attachment } = row; - if (row.expiresAt && row.expiresAt.getTime() < Date.now()) { - after(async () => { - await deleteAttachmentsBlobs(code); - await deletePaste(code); - }); - return NextResponse.json({ error: "Expired" }, { status: 404 }); - } - - if (row.burnAfterRead && row.consumed) { - return NextResponse.json({ error: "Gone" }, { status: 410 }); - } + const unavailable = unavailableResponse(code, row); + if (unavailable) return unavailable; let contentKey: Buffer; try { contentKey = unwrapKey(Buffer.from(row.keyWrapped)); if (row.salt) { const providedRaw = req.headers.get("x-paste-key"); - if (!providedRaw) { + if (!providedRaw || !contentKeySchema.safeParse(providedRaw).success) { return NextResponse.json({ error: "Invalid password" }, { status: 401 }); } // Same per-paste lock as /verify, or guesses could be made here instead. - if (await isPasswordLocked(code, req)) { + if (!(await beginPasswordAttempt(code, req))) { return NextResponse.json( { error: PASSWORD_LOCKED_MESSAGE }, { status: 429 } @@ -109,14 +99,35 @@ export async function GET( contentKey.length !== provided.length || !timingSafeEqual(contentKey, provided) ) { - await recordPasswordFailure(code, req); return NextResponse.json({ error: "Invalid password" }, { status: 401 }); } + // Off the response path: the attempt was already let through. + after(() => refundPasswordAttempt(code, req)); } } catch { return NextResponse.json({ error: "Invalid password" }, { status: 401 }); } + let filename: string; + try { + ({ filename } = openAttachmentMeta(contentKey, attachment)); + } catch { + return NextResponse.json({ error: "Decryption failed" }, { status: 500 }); + } + + if (row.burnAfterRead) { + // Burn-after-read pastes cannot have attachments, but if this ever + // happens, atomically consume the paste and delete it after the + // streamed response finishes instead of blocking the download. + const claimed = await claimPasteForView(code); + if (!claimed) { + return NextResponse.json({ error: "Gone" }, { status: 410 }); + } + deleteAfterResponse(code); + } + + // Every check is done before the blob is opened, so no early return can + // leave its stream dangling. const blob = await get(attachment.blobPath, { access: "private" }); if (!blob || !blob.stream) { // Missing from the store (e.g. the creator never finished uploading it): @@ -125,16 +136,20 @@ export async function GET( } const blobStream: ReadableStream = blob.stream; - const decipher = createDecipheriv( - ALGO, - contentKey, - Buffer.from(attachment.iv) - ); - decipher.setAuthTag(Buffer.from(attachment.authTag)); - try { + const decipher = createDecipheriv( + ALGO, + contentKey, + Buffer.from(attachment.iv) + ); + decipher.setAuthTag(Buffer.from(attachment.authTag)); + // pipeline (unlike .pipe) destroys every stage on error, so a failed // auth tag or an oversized file aborts the response instead of hanging. + // GCM only checks the tag at the end, so plaintext is streamed before it + // is authenticated: a tampered file shows up as an aborted download, not + // an error status. (The browser's direct-download path decrypts whole + // files with WebCrypto and never sees unauthenticated bytes.) const source = Readable.fromWeb( blobStream as Parameters[0] ); @@ -145,25 +160,10 @@ export async function GET( ? pipeline(source, decipher, createInflate(), limit, onDone) : pipeline(source, decipher, limit, onDone); - if (row.burnAfterRead) { - // Burn-after-read pastes cannot have attachments, but if this ever - // happens, atomically consume the paste and delete it after the - // streamed response finishes instead of blocking the download. - const claimed = await claimPasteForView(code); - if (!claimed) { - return NextResponse.json({ error: "Gone" }, { status: 410 }); - } - after(async () => { - await deleteAttachmentsBlobs(code); - await deletePaste(code); - }); - } - // The stored MIME type is uploader-supplied, so never serve it from this // origin: the client already knows the real type from the paste metadata. const headers = new Headers(); headers.set("Content-Type", "application/octet-stream"); - const { filename } = openAttachmentMeta(contentKey, attachment); headers.set("Content-Disposition", contentDisposition(filename)); headers.set("Content-Security-Policy", "default-src 'none'; sandbox"); headers.set("Cache-Control", "no-store"); diff --git a/src/app/api/pastes/[code]/reveal/route.ts b/src/app/api/pastes/[code]/reveal/route.ts index 349538c..af22704 100644 --- a/src/app/api/pastes/[code]/reveal/route.ts +++ b/src/app/api/pastes/[code]/reveal/route.ts @@ -1,19 +1,13 @@ -import { NextRequest, NextResponse, after } from "next/server"; -import { - getPasteByCode, - deletePaste, - incrementViews, - claimPasteForView, - getAttachmentsByCode, - deleteAttachmentsBlobs, -} from "@/lib/paste-service"; -import { unwrapKey, decryptPasteText } from "@/lib/crypto"; -import { toAttachmentViews } from "@/lib/attachment-views"; +import { NextRequest, NextResponse } from "next/server"; +import { getPasteByCode } from "@/lib/paste-service"; +import { unwrapKey } from "@/lib/crypto"; +import { revealResponse, unavailableResponse } from "@/lib/paste-view"; import { isValidCode } from "@/lib/ids"; import { checkReadLimit } from "@/lib/rate-limit"; export const runtime = "nodejs"; +/** Reveals a paste without a password (the explicit "View" step). */ export async function POST( req: NextRequest, { params }: { params: Promise<{ code: string }> } @@ -30,29 +24,14 @@ export async function POST( return NextResponse.json({ error: "Not found" }, { status: 404 }); } - if (paste.expiresAt && paste.expiresAt.getTime() < Date.now()) { - after(async () => { - await deleteAttachmentsBlobs(code); - await deletePaste(code); - }); - return NextResponse.json({ error: "Expired" }, { status: 404 }); - } - - if (paste.burnAfterRead && paste.consumed) { - return NextResponse.json({ error: "Gone" }, { status: 410 }); - } + const unavailable = unavailableResponse(code, paste); + if (unavailable) return unavailable; // This endpoint is only for non-password pastes. if (paste.salt) { - return NextResponse.json( - { error: "Password required" }, - { status: 400 } - ); + return NextResponse.json({ error: "Password required" }, { status: 400 }); } - // Fetch attachments in parallel with decryption — the two are independent. - const attachmentsPromise = getAttachmentsByCode(code); - let contentKey: Buffer; try { contentKey = unwrapKey(Buffer.from(paste.keyWrapped)); @@ -61,52 +40,10 @@ export async function POST( return NextResponse.json({ error: "Invalid paste" }, { status: 500 }); } - let plaintext: string; - try { - plaintext = decryptPasteText(contentKey, { - ciphertext: Buffer.from(paste.ciphertext), - iv: Buffer.from(paste.iv), - authTag: Buffer.from(paste.authTag), - compression: paste.compression, - }); - } catch { - return NextResponse.json({ error: "Decryption failed" }, { status: 500 }); - } - - const attachments = await attachmentsPromise; - - const isBurn = paste.burnAfterRead; - if (isBurn) { - // Atomically mark the paste consumed so a concurrent reveal cannot read - // it again; the physical delete is deferred until after the response. - const claimed = await claimPasteForView(code); - if (!claimed) { - return NextResponse.json({ error: "Gone" }, { status: 410 }); - } - } - - after(async () => { - await incrementViews(code); - if (isBurn) { - await deleteAttachmentsBlobs(code); - await deletePaste(code); - } + // Files are decrypted in the browser, which needs the key for that. This + // route returns the plaintext text anyway, so the key reveals nothing more. + return revealResponse(code, paste, contentKey, { + includeKey: true, + decryptError: { error: "Decryption failed", status: 500 }, }); - - return NextResponse.json({ - content: plaintext, - burnAfterRead: isBurn, - expiresAt: paste.expiresAt?.toISOString() ?? null, - views: paste.views + 1, - // Files are decrypted in the browser, which needs the key for that. This - // route returns the plaintext text anyway, so it reveals nothing more. - // (Password pastes have the key client-side already.) - contentKey: - attachments.length > 0 ? contentKey.toString("base64") : undefined, - attachments: await toAttachmentViews( - contentKey, - attachments, - paste.expiresAt - ), - }, { headers: { "Cache-Control": "no-store" } }); } diff --git a/src/app/api/pastes/[code]/verify/route.ts b/src/app/api/pastes/[code]/verify/route.ts index a928a0b..1c96c77 100644 --- a/src/app/api/pastes/[code]/verify/route.ts +++ b/src/app/api/pastes/[code]/verify/route.ts @@ -1,32 +1,23 @@ import { NextRequest, NextResponse, after } from "next/server"; import { timingSafeEqual } from "node:crypto"; import { z } from "zod"; -import { - getPasteByCode, - deletePaste, - incrementViews, - claimPasteForView, - getAttachmentsByCode, - deleteAttachmentsBlobs, -} from "@/lib/paste-service"; -import { unwrapKey, decryptPasteText } from "@/lib/crypto"; -import { toAttachmentViews } from "@/lib/attachment-views"; +import { getPasteByCode } from "@/lib/paste-service"; +import { unwrapKey } from "@/lib/crypto"; +import { revealResponse, unavailableResponse } from "@/lib/paste-view"; import { isValidCode } from "@/lib/ids"; import { checkReadLimit, - isPasswordLocked, - recordPasswordFailure, + beginPasswordAttempt, + refundPasswordAttempt, PASSWORD_LOCKED_MESSAGE, } from "@/lib/rate-limit"; +import { contentKeySchema } from "@/lib/validation"; export const runtime = "nodejs"; -const verifySchema = z.object({ - contentKey: z - .string() - .refine((v) => Buffer.from(v, "base64").length === 32, "invalid content key"), -}); +const verifySchema = z.object({ contentKey: contentKeySchema }); +/** Unlocks a password-protected paste with the browser-derived key. */ export async function POST( req: NextRequest, { params }: { params: Promise<{ code: string }> } @@ -55,19 +46,8 @@ export async function POST( return NextResponse.json({ error: "Not found" }, { status: 404 }); } - // Expired -> clean up in the background + 404 - if (paste.expiresAt && paste.expiresAt.getTime() < Date.now()) { - after(async () => { - await deleteAttachmentsBlobs(code); - await deletePaste(code); - }); - return NextResponse.json({ error: "Expired" }, { status: 404 }); - } - - // Burn-after-read already consumed -> gone - if (paste.burnAfterRead && paste.consumed) { - return NextResponse.json({ error: "Gone" }, { status: 410 }); - } + const unavailable = unavailableResponse(code, paste); + if (unavailable) return unavailable; if (!paste.salt) { return NextResponse.json( @@ -76,12 +56,6 @@ export async function POST( ); } - // Checked before comparing, so a locked paste rejects even the right - // password until the window ends. - if (await isPasswordLocked(code, req)) { - return NextResponse.json({ error: PASSWORD_LOCKED_MESSAGE }, { status: 429 }); - } - const provided = Buffer.from(parsed.data.contentKey, "base64"); let contentKey: Buffer; try { @@ -89,58 +63,23 @@ export async function POST( } catch { return NextResponse.json({ error: "Invalid paste" }, { status: 500 }); } + + // Checked before comparing, so a locked paste rejects even the right + // password until the window ends. + if (!(await beginPasswordAttempt(code, req))) { + return NextResponse.json({ error: PASSWORD_LOCKED_MESSAGE }, { status: 429 }); + } if ( contentKey.length !== provided.length || !timingSafeEqual(contentKey, provided) ) { - await recordPasswordFailure(code, req); - return NextResponse.json({ error: "Invalid password" }, { status: 401 }); - } - - // Fetch attachments in parallel with decryption. - const attachmentsPromise = getAttachmentsByCode(code); - - let plaintext: string; - try { - plaintext = decryptPasteText(contentKey, { - ciphertext: Buffer.from(paste.ciphertext), - iv: Buffer.from(paste.iv), - authTag: Buffer.from(paste.authTag), - compression: paste.compression, - }); - } catch { return NextResponse.json({ error: "Invalid password" }, { status: 401 }); } + // Off the response path: the attempt was already let through. + after(() => refundPasswordAttempt(code, req)); - const attachments = await attachmentsPromise; - - const isBurn = paste.burnAfterRead; - if (isBurn) { - // Atomically mark the paste consumed so a concurrent unlock cannot read - // it again; the physical delete is deferred until after the response. - const claimed = await claimPasteForView(code); - if (!claimed) { - return NextResponse.json({ error: "Gone" }, { status: 410 }); - } - } - - after(async () => { - await incrementViews(code); - if (isBurn) { - await deleteAttachmentsBlobs(code); - await deletePaste(code); - } + return revealResponse(code, paste, contentKey, { + includeKey: false, + decryptError: { error: "Invalid password", status: 401 }, }); - - return NextResponse.json({ - content: plaintext, - burnAfterRead: isBurn, - expiresAt: paste.expiresAt?.toISOString() ?? null, - views: paste.views + 1, - attachments: await toAttachmentViews( - contentKey, - attachments, - paste.expiresAt - ), - }, { headers: { "Cache-Control": "no-store" } }); } diff --git a/src/app/api/pastes/route.ts b/src/app/api/pastes/route.ts index ac88050..9ccc2bb 100644 --- a/src/app/api/pastes/route.ts +++ b/src/app/api/pastes/route.ts @@ -20,6 +20,7 @@ import { import { checkCreateLimit, getUploadSizes, + releaseTextBytes, reserveTextBytes, } from "@/lib/rate-limit"; @@ -166,7 +167,10 @@ export async function POST(req: NextRequest) { }); } catch (e) { console.error("createPaste failed", describeDbError(e)); - await discardUploads(); + await Promise.all([ + discardUploads(), + releaseTextBytes(req, ciphertext.length), + ]); return NextResponse.json({ error: "Failed to create paste" }, { status: 500 }); } @@ -188,6 +192,7 @@ export async function POST(req: NextRequest) { ); } catch (e) { await deletePaste(paste.code); + await releaseTextBytes(req, ciphertext.length); // A unique violation on blob_path means a file already belongs to // another paste; deleting it would break that paste. Leave any genuinely // unreferenced blobs to the orphan sweep. diff --git a/src/components/password-gate.tsx b/src/components/password-gate.tsx index f086e6f..2ddb704 100644 --- a/src/components/password-gate.tsx +++ b/src/components/password-gate.tsx @@ -44,7 +44,7 @@ export default function PasswordGate({ code, salt }: Props) { headers: { "Content-Type": "application/json" }, body: JSON.stringify({ contentKey: key }), }); - const data = await res.json(); + const data = await res.json().catch(() => ({})); if (!res.ok) { setView({ status: "error", message: data.error ?? "Failed to unlock" }); setLoading(false); diff --git a/src/components/paste-editor.tsx b/src/components/paste-editor.tsx index 443ba37..f1f71f7 100644 --- a/src/components/paste-editor.tsx +++ b/src/components/paste-editor.tsx @@ -52,8 +52,10 @@ export default function PasteEditor() { // be attached once and still read the latest values. const filesRef = useRef(files); const loadingRef = useRef(loading); - filesRef.current = files; - loadingRef.current = loading; + useEffect(() => { + filesRef.current = files; + loadingRef.current = loading; + }, [files, loading]); const totalBytes = files.reduce((sum, f) => sum + f.size, 0); diff --git a/src/components/paste-reveal.tsx b/src/components/paste-reveal.tsx index a964c1a..5cd6e8c 100644 --- a/src/components/paste-reveal.tsx +++ b/src/components/paste-reveal.tsx @@ -26,7 +26,7 @@ export default function PasteReveal({ code, burnAfterRead }: Props) { const res = await fetch(`/api/pastes/${code}/reveal`, { method: "POST", }); - const data = await res.json(); + const data = await res.json().catch(() => ({})); if (!res.ok) { setView({ status: "error", message: data.error ?? "Failed to load" }); setLoading(false); diff --git a/src/components/theme-toggle.tsx b/src/components/theme-toggle.tsx index 8347f80..5ab33d6 100644 --- a/src/components/theme-toggle.tsx +++ b/src/components/theme-toggle.tsx @@ -1,7 +1,7 @@ "use client"; import { Monitor, Moon, Sun } from "lucide-react"; -import { useEffect, useState } from "react"; +import { useEffect, useSyncExternalStore } from "react"; type Theme = "system" | "light" | "dark"; @@ -16,13 +16,35 @@ function isTheme(v: string | null): v is Theme { return v === "system" || v === "light" || v === "dark"; } -export default function ThemeToggle() { - const [theme, setTheme] = useState("system"); +const CHANGE_EVENT = "theme-change"; - useEffect(() => { +function readTheme(): Theme { + try { const stored = localStorage.getItem("theme"); - if (isTheme(stored)) setTheme(stored); + return isTheme(stored) ? stored : "system"; + } catch { + return "system"; + } +} +/** Theme changes in this tab and others (for useSyncExternalStore). */ +function subscribeTheme(onChange: () => void): () => void { + const onStorage = (e: StorageEvent) => { + if (e.key === "theme") onChange(); + }; + window.addEventListener(CHANGE_EVENT, onChange); + window.addEventListener("storage", onStorage); + return () => { + window.removeEventListener(CHANGE_EVENT, onChange); + window.removeEventListener("storage", onStorage); + }; +} + +export default function ThemeToggle() { + // "system" on the server and during hydration, then the stored choice. + const theme = useSyncExternalStore(subscribeTheme, readTheme, () => "system" as Theme); + + useEffect(() => { const mq = window.matchMedia("(prefers-color-scheme: dark)"); const apply = () => { const stored = localStorage.getItem("theme"); @@ -37,8 +59,12 @@ export default function ThemeToggle() { function cycle() { const next = ORDER[(ORDER.indexOf(theme) + 1) % ORDER.length]; - setTheme(next); - localStorage.setItem("theme", next); + try { + localStorage.setItem("theme", next); + } catch { + // Storage disabled: the theme still applies for this page. + } + window.dispatchEvent(new Event(CHANGE_EVENT)); const dark = next === "dark" || (next === "system" && diff --git a/src/instrumentation.ts b/src/instrumentation.ts new file mode 100644 index 0000000..b2d1ebc --- /dev/null +++ b/src/instrumentation.ts @@ -0,0 +1,6 @@ +export async function register() { + // The checks read Node's process.env; the proxy's edge runtime needs none. + if (process.env.NEXT_RUNTIME !== "nodejs") return; + const { assertServerEnv } = await import("./lib/env"); + assertServerEnv(); +} diff --git a/src/lib/create-paste.ts b/src/lib/create-paste.ts index ee5aa88..7d84dd9 100644 --- a/src/lib/create-paste.ts +++ b/src/lib/create-paste.ts @@ -136,7 +136,7 @@ export async function createPaste( files: fileMeta, }), }); - const data = await res.json(); + const data = await res.json().catch(() => ({})); if (!res.ok) return { ok: false, error: data.error ?? "Failed to create paste" }; saveDeleteToken(data.code, data.deleteUrl.split("#delete=")[1], data.expiresAt); diff --git a/src/lib/crypto.test.ts b/src/lib/crypto.test.ts new file mode 100644 index 0000000..ae6a218 --- /dev/null +++ b/src/lib/crypto.test.ts @@ -0,0 +1,119 @@ +import { describe, expect, it } from "vitest"; +import { Buffer } from "node:buffer"; +import { + decryptContent, + decryptPasteText, + encryptContent, + encryptPasteText, + generateContentKey, + generateDeleteToken, + hashDeleteToken, + openAttachmentMeta, + sealAttachmentMeta, + unwrapKey, + wrapKey, +} from "./crypto"; +import { + base64ToBytes, + bytesToBase64, + decryptFile, + deriveKeyFromPassword, + prepareFileForUpload, +} from "./client-crypto"; + +describe("server crypto", () => { + it("wraps and unwraps a content key", () => { + const key = generateContentKey(); + const wrapped = wrapKey(key); + expect(wrapped.equals(key)).toBe(false); + expect(unwrapKey(wrapped).equals(key)).toBe(true); + }); + + it("rejects a tampered wrapped key", () => { + const wrapped = wrapKey(generateContentKey()); + wrapped[wrapped.length - 1] ^= 1; + expect(() => unwrapKey(wrapped)).toThrow(); + }); + + it("round-trips paste text, compressing when it helps", () => { + const key = generateContentKey(); + const text = "hello ".repeat(1000); + const enc = encryptPasteText(key, text); + expect(enc.compression).toBe("deflate"); + expect(enc.ciphertext.length).toBeLessThan(text.length); + expect(decryptPasteText(key, enc)).toBe(text); + }); + + it("stores short incompressible text as-is", () => { + const key = generateContentKey(); + const enc = encryptPasteText(key, "a"); + expect(enc.compression).toBe("none"); + expect(decryptPasteText(key, enc)).toBe("a"); + }); + + it("fails to decrypt with the wrong key or a bad tag", () => { + const key = generateContentKey(); + const enc = encryptPasteText(key, "secret"); + expect(() => decryptPasteText(generateContentKey(), enc)).toThrow(); + const badTag = Buffer.from(enc.authTag); + badTag[0] ^= 1; + expect(() => decryptPasteText(key, { ...enc, authTag: badTag })).toThrow(); + }); + + it("seals attachment metadata", () => { + const key = generateContentKey(); + const meta = { filename: "résumé.pdf", mime: "application/pdf" }; + const sealed = sealAttachmentMeta(key, meta); + expect(sealed.includes(Buffer.from("pdf"))).toBe(false); + expect(openAttachmentMeta(key, { meta: sealed })).toEqual(meta); + }); + + it("hashes delete tokens deterministically", () => { + const { token, hash } = generateDeleteToken(); + expect(token).toMatch(/^[A-Za-z0-9_-]{43}$/); + expect(hashDeleteToken(token).equals(hash)).toBe(true); + }); +}); + +describe("browser <-> server interop", () => { + it("server decrypts a file the browser encrypted", async () => { + const key = crypto.getRandomValues(new Uint8Array(32)); + const content = new TextEncoder().encode("file body ".repeat(500)); + const file = new File([content], "a.txt", { type: "text/plain" }); + const { bytes, meta } = await prepareFileForUpload(key, file); + expect(meta.compression).toBe("deflate"); + + const plain = decryptContent(Buffer.from(key), { + ciphertext: Buffer.from(bytes), + iv: Buffer.from(base64ToBytes(meta.ivB64)), + authTag: Buffer.from(base64ToBytes(meta.authTagB64)), + }); + const { inflateSync } = await import("node:zlib"); + expect(Buffer.from(inflateSync(plain)).equals(Buffer.from(content))).toBe(true); + }); + + it("browser decrypts what the server encrypted", async () => { + const key = generateContentKey(); + const data = Buffer.from("downloaded bytes"); + const enc = encryptContent(key, data); + // decryptFile expects TAG_LEN spare bytes after the ciphertext. + const sealed = new Uint8Array(enc.ciphertext.length + 16); + sealed.set(enc.ciphertext); + const out = await decryptFile(new Uint8Array(key), sealed, { + ivB64: enc.iv.toString("base64"), + authTagB64: enc.authTag.toString("base64"), + compression: "none", + size: data.length, + }); + expect(Buffer.from(out).equals(data)).toBe(true); + }); + + it("derives the same key from the same password and salt", async () => { + const a = await deriveKeyFromPassword("correct horse"); + const b = await deriveKeyFromPassword("correct horse", a.salt); + const c = await deriveKeyFromPassword("wrong horse", a.salt); + expect(bytesToBase64(a.key)).toBe(bytesToBase64(b.key)); + expect(bytesToBase64(a.key)).not.toBe(bytesToBase64(c.key)); + expect(bytesToBase64(a.key)).toHaveLength(44); + }); +}); diff --git a/src/lib/env.test.ts b/src/lib/env.test.ts new file mode 100644 index 0000000..61ea22e --- /dev/null +++ b/src/lib/env.test.ts @@ -0,0 +1,44 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { assertServerEnv, checkEnv } from "./env"; + +const good = { + POSTGRES_URL: "postgres://x", + PASTE_MASTER_KEY: "a".repeat(64), + APP_URL: "https://example.com", + CRON_SECRET: "s", + BLOB_READ_WRITE_TOKEN: "t", +}; + +afterEach(() => vi.restoreAllMocks()); + +describe("checkEnv", () => { + it("passes a complete environment", () => { + expect(checkEnv(good)).toEqual({ errors: [], warnings: [] }); + }); + + it("reports missing required and recommended variables", () => { + const { errors, warnings } = checkEnv({}); + expect(errors).toHaveLength(2); + expect(warnings).toHaveLength(3); + }); + + it("warns (not errors) on a short master key", () => { + const { errors, warnings } = checkEnv({ ...good, PASTE_MASTER_KEY: "short" }); + expect(errors).toEqual([]); + expect(warnings[0]).toMatch(/PASTE_MASTER_KEY/); + }); +}); + +describe("assertServerEnv", () => { + it("throws in production when required variables are missing", () => { + vi.spyOn(console, "warn").mockImplementation(() => {}); + expect(() => assertServerEnv({ NODE_ENV: "production" })).toThrow(/POSTGRES_URL/); + }); + + it("only logs outside production", () => { + vi.spyOn(console, "warn").mockImplementation(() => {}); + const error = vi.spyOn(console, "error").mockImplementation(() => {}); + expect(() => assertServerEnv({ NODE_ENV: "development" })).not.toThrow(); + expect(error).toHaveBeenCalledOnce(); + }); +}); diff --git a/src/lib/env.ts b/src/lib/env.ts new file mode 100644 index 0000000..a5ea73d --- /dev/null +++ b/src/lib/env.ts @@ -0,0 +1,49 @@ +/** + * Startup check of the server's environment (run from instrumentation.ts). + * Without it a missing POSTGRES_URL makes every paste a silent 404, and a + * missing PASTE_MASTER_KEY only fails on the first create or read. + */ + +type Env = Record; + +/** The app can't store or read pastes without these. */ +const REQUIRED = ["POSTGRES_URL", "PASTE_MASTER_KEY"] as const; + +/** Features degrade (or links break) without these, so they only warn. */ +const RECOMMENDED: Record = { + APP_URL: "share links will be relative", + CRON_SECRET: "the cleanup cron endpoint rejects every call", + BLOB_READ_WRITE_TOKEN: "file attachments are disabled", +}; + +/** `openssl rand -hex 32` gives 64; anything shorter than this is suspect. */ +const MIN_MASTER_KEY_LENGTH = 32; + +export function checkEnv(env: Env): { errors: string[]; warnings: string[] } { + const errors = REQUIRED.filter((k) => !env[k]).map((k) => `${k} is not set`); + const warnings = Object.entries(RECOMMENDED) + .filter(([k]) => !env[k]) + .map(([k, effect]) => `${k} is not set: ${effect}`); + const key = env.PASTE_MASTER_KEY; + if (key && key.length < MIN_MASTER_KEY_LENGTH) { + // Only a warning: changing the key would make every stored paste + // unreadable, so an existing short key must keep working. + warnings.push( + `PASTE_MASTER_KEY is shorter than ${MIN_MASTER_KEY_LENGTH} characters; use a long random value for new deployments` + ); + } + return { errors, warnings }; +} + +/** + * Logs problems with the environment; in production, throws on missing + * required variables so a misconfigured deployment fails loudly. + */ +export function assertServerEnv(env: Env = process.env): void { + const { errors, warnings } = checkEnv(env); + for (const w of warnings) console.warn(`[env] ${w}`); + if (errors.length === 0) return; + const message = `[env] ${errors.join("; ")}`; + if (env.NODE_ENV === "production") throw new Error(message); + console.error(message); +} diff --git a/src/lib/expiry.ts b/src/lib/expiry.ts index b53122b..fb6ab0e 100644 --- a/src/lib/expiry.ts +++ b/src/lib/expiry.ts @@ -1,16 +1,21 @@ -// Expiry choices, shared by the editor (labels) and the server's validation -// (values). Kept free of imports so it adds nothing to the client bundle. +// Expiry choices, shared by the editor (labels) and the server (validation +// and expiry dates). Kept free of imports so it adds nothing to the client +// bundle. + +const MINUTE = 60 * 1000; +const HOUR = 60 * MINUTE; +const DAY = 24 * HOUR; export const EXPIRY_OPTIONS = [ - { value: "5min", label: "5 minutes" }, - { value: "10min", label: "10 minutes" }, - { value: "30min", label: "30 minutes" }, - { value: "1h", label: "1 hour" }, - { value: "3h", label: "3 hours" }, - { value: "6h", label: "6 hours" }, - { value: "12h", label: "12 hours" }, - { value: "1d", label: "1 day" }, - { value: "3d", label: "3 days" }, + { value: "5min", label: "5 minutes", ms: 5 * MINUTE }, + { value: "10min", label: "10 minutes", ms: 10 * MINUTE }, + { value: "30min", label: "30 minutes", ms: 30 * MINUTE }, + { value: "1h", label: "1 hour", ms: HOUR }, + { value: "3h", label: "3 hours", ms: 3 * HOUR }, + { value: "6h", label: "6 hours", ms: 6 * HOUR }, + { value: "12h", label: "12 hours", ms: 12 * HOUR }, + { value: "1d", label: "1 day", ms: DAY }, + { value: "3d", label: "3 days", ms: 3 * DAY }, ] as const; type ExpiryValue = (typeof EXPIRY_OPTIONS)[number]["value"]; @@ -25,3 +30,8 @@ export const EXPIRY_VALUES = EXPIRY_OPTIONS.map((o) => o.value) as [ export function expiryLabel(value: string): string { return EXPIRY_OPTIONS.find((o) => o.value === value)?.label ?? value; } + +/** Lifetime of an expiry value in milliseconds, or null if unknown. */ +export function expiryMs(value: string): number | null { + return EXPIRY_OPTIONS.find((o) => o.value === value)?.ms ?? null; +} diff --git a/src/lib/paste-service.ts b/src/lib/paste-service.ts index 0143869..e3dceb2 100644 --- a/src/lib/paste-service.ts +++ b/src/lib/paste-service.ts @@ -2,18 +2,7 @@ import { eq, sql, inArray, and } from "drizzle-orm"; import { db, schema } from "@/db"; import type { Paste, NewPaste, Attachment, NewAttachment } from "@/db/schema"; import { shortId } from "./ids"; - -const EXPIRY_MS: Record = { - "5min": 5 * 60 * 1000, - "10min": 10 * 60 * 1000, - "30min": 30 * 60 * 1000, - "1h": 60 * 60 * 1000, - "3h": 3 * 60 * 60 * 1000, - "6h": 6 * 60 * 60 * 1000, - "12h": 12 * 60 * 60 * 1000, - "1d": 24 * 60 * 60 * 1000, - "3d": 3 * 24 * 60 * 60 * 1000, -}; +import { expiryMs } from "./expiry"; /** * Postgres error code (e.g. "23505") from a query error. Drizzle wraps driver @@ -47,7 +36,7 @@ export type CreatePasteArgs = { }; export function getExpiryDate(expiresIn: string): Date | null { - const ms = EXPIRY_MS[expiresIn]; + const ms = expiryMs(expiresIn); return ms ? new Date(Date.now() + ms) : null; } @@ -347,3 +336,14 @@ export async function deleteAttachmentsBlobs(code: string): Promise { const attachments = await getAttachmentsByCode(code); return deleteBlobs(attachments.map((a) => a.blobPath)); } + +/** + * Deletes a paste with its attachment blobs. Blobs go first, since their + * paths live in the attachment rows the paste delete cascades away; anything + * a failed blob delete leaves behind is caught by the daily orphan sweep. + * Returns true if the paste row was removed. + */ +export async function deletePasteWithBlobs(code: string): Promise { + await deleteAttachmentsBlobs(code); + return deletePaste(code); +} diff --git a/src/lib/paste-view.ts b/src/lib/paste-view.ts new file mode 100644 index 0000000..4b7354f --- /dev/null +++ b/src/lib/paste-view.ts @@ -0,0 +1,110 @@ +import { NextResponse, after } from "next/server"; +import type { Paste } from "@/db/schema"; +import { + claimPasteForView, + deletePasteWithBlobs, + getAttachmentsByCode, + incrementViews, +} from "./paste-service"; +import { decryptPasteText } from "./crypto"; +import { toAttachmentViews } from "./attachment-views"; + +/** True once a paste's expiry time has passed. */ +export function isExpired(paste: { expiresAt: Date | null }): boolean { + return !!paste.expiresAt && paste.expiresAt.getTime() < Date.now(); +} + +/** Deletes a paste and its blobs after the response is sent. */ +export function deleteAfterResponse(code: string): void { + after(() => deletePasteWithBlobs(code)); +} + +/** + * The response for a paste that can no longer be read, or null if it can: + * 404 when expired (and deletes it after responding, since cron runs only + * daily), 410 when a burn-after-read paste was already viewed. + */ +export function unavailableResponse( + code: string, + paste: Pick +): NextResponse | null { + if (isExpired(paste)) { + deleteAfterResponse(code); + return NextResponse.json({ error: "Expired" }, { status: 404 }); + } + if (paste.burnAfterRead && paste.consumed) { + return NextResponse.json({ error: "Gone" }, { status: 410 }); + } + return null; +} + +/** + * Decrypts a paste for a viewer who is allowed to see it, and builds the + * reveal/verify response: the text, the attachment list, and for burn-after- + * read pastes the atomic claim plus deletion after the response. + */ +export async function revealResponse( + code: string, + paste: Paste, + contentKey: Buffer, + options: { + /** + * Send the content key, so the browser can decrypt the files. Only for + * non-password pastes: password pastes have the key client-side already. + */ + includeKey: boolean; + /** Response when the text fails to decrypt. */ + decryptError: { error: string; status: number }; + } +): Promise { + // Fetch attachments in parallel with decryption: the two are independent. + const attachmentsPromise = getAttachmentsByCode(code); + + let plaintext: string; + try { + plaintext = decryptPasteText(contentKey, { + ciphertext: Buffer.from(paste.ciphertext), + iv: Buffer.from(paste.iv), + authTag: Buffer.from(paste.authTag), + compression: paste.compression, + }); + } catch { + attachmentsPromise.catch(() => {}); + const { error, status } = options.decryptError; + return NextResponse.json({ error }, { status }); + } + + const attachments = await attachmentsPromise; + + const isBurn = paste.burnAfterRead; + if (isBurn) { + // Atomically mark the paste consumed so a concurrent request cannot read + // it again; the physical delete is deferred until after the response. + if (!(await claimPasteForView(code))) { + return NextResponse.json({ error: "Gone" }, { status: 410 }); + } + deleteAfterResponse(code); + } else { + // A burned paste is deleted, so counting its view would be a wasted write. + after(() => incrementViews(code)); + } + + return NextResponse.json( + { + content: plaintext, + burnAfterRead: isBurn, + expiresAt: paste.expiresAt?.toISOString() ?? null, + views: paste.views + 1, + contentKey: + options.includeKey && attachments.length > 0 + ? contentKey.toString("base64") + : undefined, + attachments: await toAttachmentViews( + contentKey, + attachments, + paste.expiresAt + ), + }, + { headers: { "Cache-Control": "no-store" } } + ); +} diff --git a/src/lib/rate-limit.ts b/src/lib/rate-limit.ts index 6f6a91d..ee2189e 100644 --- a/src/lib/rate-limit.ts +++ b/src/lib/rate-limit.ts @@ -170,14 +170,14 @@ export async function checkUploadLimit( /** * Failed password attempts allowed per paste from one IP before the paste - * locks for that IP for the rest of the window. Someone guessing can't lock - * out the real recipient, who is on a different IP. + * locks for that IP for the rest of the window. */ const MAX_PASSWORD_FAILURES_PER_IP = 10; /** * Failed attempts allowed per paste across all IPs before it locks for * everyone. Bounds online guessing when an attacker spreads guesses across - * many IPs. + * many IPs, at the cost that guessing from several IPs can also lock out the + * real recipient until the window ends. */ const MAX_PASSWORD_FAILURES = 50; const PASSWORD_WINDOW_SECONDS = 60 * 60; @@ -190,41 +190,67 @@ function passwordFailureKeys(code: string, req: NextRequest): [string, string] { } /** - * True if the paste has had too many failed password attempts in the current - * window, from this IP or from all IPs together. Always false when Redis isn't - * configured. + * Checks the lock and, if open, counts the attempt, atomically. + * + * KEYS: IP counter, global counter + * ARGV: IP max, global max, window seconds + * Returns 1 if the attempt may proceed (and was counted), 0 if locked. + */ +export const PASSWORD_ATTEMPT_SCRIPT = ` +local ip = tonumber(redis.call('GET', KEYS[1]) or '0') +local all = tonumber(redis.call('GET', KEYS[2]) or '0') +if ip >= tonumber(ARGV[1]) or all >= tonumber(ARGV[2]) then + return 0 +end +for _, key in ipairs(KEYS) do + if redis.call('INCR', key) == 1 then redis.call('EXPIRE', key, ARGV[3]) end +end +return 1 +`; + +/** Undoes one attempt counted by PASSWORD_ATTEMPT_SCRIPT. */ +export const PASSWORD_REFUND_SCRIPT = ` +for _, key in ipairs(KEYS) do + if tonumber(redis.call('GET', key) or '0') > 0 then redis.call('DECR', key) end +end +return 1 +`; + +/** + * Starts a password attempt: false if the paste is locked for this IP (too + * many failures from it, or from all IPs together, in the current window). + * Otherwise the attempt is counted as a failure up front, so a burst of + * concurrent guesses can't all slip past the lock before any is recorded; + * call refundPasswordAttempt() when the password turns out to be right. + * Always true when Redis isn't configured. */ -export async function isPasswordLocked( +export async function beginPasswordAttempt( code: string, req: NextRequest ): Promise { const r = getRedis(); - if (!r) return false; - const [fromIp, total] = await r.mget<(number | null)[]>( - ...passwordFailureKeys(code, req) - ); - return ( - (fromIp ?? 0) >= MAX_PASSWORD_FAILURES_PER_IP || - (total ?? 0) >= MAX_PASSWORD_FAILURES + if (!r) return true; + const res = await r.eval( + PASSWORD_ATTEMPT_SCRIPT, + passwordFailureKeys(code, req), + [MAX_PASSWORD_FAILURES_PER_IP, MAX_PASSWORD_FAILURES, PASSWORD_WINDOW_SECONDS] ); + return res === 1; } /** - * Counts a failed password attempt against the paste, for this IP and in - * total. Each window starts at its first failure. + * Uncounts an attempt begun with beginPasswordAttempt() whose password was + * right. Best effort: a failure only leaves one extra failure counted. */ -export async function recordPasswordFailure( +export async function refundPasswordAttempt( code: string, req: NextRequest ): Promise { const r = getRedis(); if (!r) return; - // One round trip: INCR each key, starting its expiry on the first failure. - await r.eval( - "for _, key in ipairs(KEYS) do if redis.call('INCR', key) == 1 then redis.call('EXPIRE', key, ARGV[1]) end end return 1", - passwordFailureKeys(code, req), - [PASSWORD_WINDOW_SECONDS] - ); + await r + .eval(PASSWORD_REFUND_SCRIPT, passwordFailureKeys(code, req), []) + .catch(() => {}); } /** @@ -353,6 +379,27 @@ export async function reserveTextBytes( return res === 1; } +/** + * Returns bytes reserved by reserveTextBytes() when the paste wasn't stored + * after all, so a failed create doesn't count against the quota. Best effort: + * a failure here only leaves the quota slightly over-counted. + */ +export async function releaseTextBytes( + req: NextRequest, + bytes: number +): Promise { + const r = getRedis(); + if (!r || bytes <= 0) return; + const day = utcDay(); + await r + .eval( + "for _, key in ipairs(KEYS) do if redis.call('EXISTS', key) == 1 then redis.call('DECRBY', key, ARGV[1]) end end return 1", + [`tq:${clientId(req)}:${day}`, `tq:all:${day}`], + [bytes] + ) + .catch(() => {}); +} + /** * Declared sizes for the given token pathnames, in one Redis round trip; * null entries were never recorded or have expired. Returns null when Redis diff --git a/src/lib/utils.test.ts b/src/lib/utils.test.ts new file mode 100644 index 0000000..da781fd --- /dev/null +++ b/src/lib/utils.test.ts @@ -0,0 +1,97 @@ +import { describe, expect, it } from "vitest"; +import { generatePassphrase, isWeakPassword } from "./passphrase"; +import { isValidCode, shortId } from "./ids"; +import { mapWithByteBudget, mapWithConcurrency } from "./map-concurrency"; + +describe("passphrase", () => { + it("generates 4 groups of 4 unambiguous characters", () => { + for (let i = 0; i < 50; i++) { + const p = generatePassphrase(); + expect(p).toMatch(/^[2-9A-HJ-NP-Za-km-z]{4}(-[2-9A-HJ-NP-Za-km-z]{4}){3}$/); + expect(isWeakPassword(p)).toBe(false); + } + }); + + it("flags weak passwords", () => { + expect(isWeakPassword("short1A")).toBe(true); + expect(isWeakPassword("123456789012")).toBe(true); + expect(isWeakPassword("aaaaaaaaaaaaaaaaaaaa")).toBe(true); + expect(isWeakPassword("correcthorsebatterystaple")).toBe(false); + expect(isWeakPassword("Tr0ub4dor&3x")).toBe(false); + }); +}); + +describe("ids", () => { + it("generates valid 6-character codes", () => { + for (let i = 0; i < 100; i++) expect(isValidCode(shortId())).toBe(true); + expect(isValidCode("abc")).toBe(false); + expect(isValidCode("abc-12")).toBe(false); + }); +}); + +const tick = () => new Promise((r) => setTimeout(r, 1)); + +describe("mapWithConcurrency", () => { + it("keeps order and respects the limit", async () => { + let active = 0; + let peak = 0; + const out = await mapWithConcurrency([1, 2, 3, 4, 5], 2, async (n) => { + peak = Math.max(peak, ++active); + await tick(); + active--; + return n * 2; + }); + expect(out).toEqual([2, 4, 6, 8, 10]); + expect(peak).toBe(2); + }); +}); + +describe("mapWithByteBudget", () => { + it("caps bytes in flight but always runs one oversized item", async () => { + let activeBytes = 0; + let peakBytes = 0; + const sizes = [60, 60, 200, 10, 10, 10]; + const out = await mapWithByteBudget( + sizes, + 100, + (s) => s, + async (s, i) => { + activeBytes += s; + peakBytes = Math.max(peakBytes, activeBytes); + await tick(); + activeBytes -= s; + return i; + }, + ); + expect(out).toEqual([0, 1, 2, 3, 4, 5]); + // Only the 200-byte item, running alone, may exceed the budget. + expect(peakBytes).toBe(200); + }); + + it("rejects on the first failure and starts nothing after it", async () => { + const started: number[] = []; + await expect( + mapWithByteBudget([1, 2, 3, 4], 1, () => 1, async (n) => { + started.push(n); + await tick(); + if (n === 2) throw new Error("boom"); + return n; + }), + ).rejects.toThrow("boom"); + await tick(); + expect(started).toEqual([1, 2]); + }); + + it("resolves an empty list", async () => { + expect(await mapWithByteBudget([], 1, () => 1, async () => 1)).toEqual([]); + }); +}); + +describe("expiry", () => { + it("has a duration for every option, longest 3 days", async () => { + const { EXPIRY_OPTIONS, expiryMs } = await import("./expiry"); + for (const o of EXPIRY_OPTIONS) expect(expiryMs(o.value)).toBeGreaterThan(0); + expect(expiryMs("3d")).toBe(3 * 24 * 60 * 60 * 1000); + expect(expiryMs("1y")).toBeNull(); + }); +}); diff --git a/src/lib/validation.test.ts b/src/lib/validation.test.ts new file mode 100644 index 0000000..516e5b3 --- /dev/null +++ b/src/lib/validation.test.ts @@ -0,0 +1,85 @@ +import { describe, expect, it } from "vitest"; +import { randomBytes, randomUUID } from "node:crypto"; +import { contentKeySchema, createPasteSchema } from "./validation"; + +const b64 = (n: number) => randomBytes(n).toString("base64"); + +function file(overrides: Record = {}) { + return { + pathname: `files/${randomUUID()}`, + filename: "a.txt", + mime: "text/plain", + size: 10, + iv: b64(12), + authTag: b64(16), + ...overrides, + }; +} + +describe("contentKeySchema", () => { + it("accepts exactly 32 bytes of padded base64", () => { + expect(contentKeySchema.safeParse(b64(32)).success).toBe(true); + }); + + it.each([ + ["too short", b64(31)], + ["too long", b64(33)], + ["junk that still decodes to 32 bytes", `${b64(32)}!!!!`], + ["invalid characters", `${b64(32).slice(0, 40)}$$$=`], + ["unpadded", b64(32).replace(/=+$/, "")], + ])("rejects %s", (_label, value) => { + expect(contentKeySchema.safeParse(value).success).toBe(false); + }); +}); + +describe("createPasteSchema", () => { + it("applies defaults", () => { + const parsed = createPasteSchema.parse({ content: "hi" }); + expect(parsed).toMatchObject({ + burnAfterRead: false, + expiresIn: "1h", + files: [], + }); + }); + + it("requires text or a file", () => { + expect(createPasteSchema.safeParse({ content: " " }).success).toBe(false); + expect(createPasteSchema.safeParse({ files: [file()] }).success).toBe(true); + }); + + it("rejects unknown expiry values", () => { + const r = createPasteSchema.safeParse({ content: "x", expiresIn: "1y" }); + expect(r.success).toBe(false); + }); + + it("rejects content over 1 MB", () => { + const r = createPasteSchema.safeParse({ content: "x".repeat(1_000_001) }); + expect(r.success).toBe(false); + }); + + it("validates file entries", () => { + const bad = [ + file({ pathname: "files/../etc" }), + file({ filename: "a/b" }), + file({ iv: b64(16) }), + file({ authTag: `${b64(16)}AAAA` }), + file({ size: 0 }), + ]; + for (const f of bad) { + expect(createPasteSchema.safeParse({ files: [f] }).success).toBe(false); + } + }); + + it("caps file count and total size", () => { + const many = Array.from({ length: 21 }, () => file()); + expect(createPasteSchema.safeParse({ files: many }).success).toBe(false); + const big = Array.from({ length: 3 }, () => file({ size: 40 * 1024 * 1024 })); + expect(createPasteSchema.safeParse({ files: big }).success).toBe(false); + }); + + it("validates salt length", () => { + const base = { content: "x", contentKey: b64(32) }; + expect(createPasteSchema.safeParse({ ...base, salt: b64(16) }).success).toBe(true); + expect(createPasteSchema.safeParse({ ...base, salt: b64(8) }).success).toBe(false); + }); +}); diff --git a/src/lib/validation.ts b/src/lib/validation.ts index 05a5117..fb883e1 100644 --- a/src/lib/validation.ts +++ b/src/lib/validation.ts @@ -28,6 +28,25 @@ export const UPLOAD_PATHNAME = new RegExp(`^files/${UUID}$`); export const ATTACHMENT_ID = new RegExp(`^${UUID}$`); +/** Standard padded base64, as the browser's btoa() produces. */ +const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/; + +/** + * Exactly `bytes` bytes as padded base64. Strict because Buffer.from(…, + * "base64") silently skips invalid characters, so a length check on the + * decoded bytes alone would accept arbitrarily long junk. + */ +function base64Bytes(bytes: number, message: string) { + return z + .string() + .length(4 * Math.ceil(bytes / 3), message) + .regex(BASE64, message) + .refine((v) => Buffer.from(v, "base64").length === bytes, message); +} + +/** A 32-byte content key, base64 (create, verify, and `X-Paste-Key`). */ +export const contentKeySchema = base64Bytes(32, "invalid content key"); + const fileEntrySchema = z.object({ pathname: z.string().regex(UPLOAD_PATHNAME, "invalid file path"), filename: z @@ -39,17 +58,8 @@ const fileEntrySchema = z.object({ size: z.number().int().positive().max(MAX_FILE_BYTES), // AES-GCM's 12-byte IV and 16-byte auth tag, base64. Exact, so the stored // columns can't be padded with junk that bypasses the text quota. - iv: z - .string() - .max(24) - .refine((v) => Buffer.from(v, "base64").length === 12, "invalid file IV"), - authTag: z - .string() - .max(32) - .refine( - (v) => Buffer.from(v, "base64").length === 16, - "invalid file auth tag" - ), + iv: base64Bytes(12, "invalid file IV"), + authTag: base64Bytes(16, "invalid file auth tag"), compression: z.enum(["deflate", "none"]).default("deflate"), }); @@ -66,17 +76,11 @@ export const createPasteSchema = z.object({ // Base64 of the 32-byte content key, sent for password-protected pastes and // for pastes with file attachments so the server wraps/reuses the key the // client generated. - contentKey: z - .string() - .refine((v) => Buffer.from(v, "base64").length === 32, "invalid content key") - .optional(), + contentKey: contentKeySchema.optional(), // Base64 of the 16-byte PBKDF2 salt (password-protected pastes). Stored as // metadata so the client can re-derive the key on reveal; the server never // derives itself. - salt: z - .string() - .refine((v) => Buffer.from(v, "base64").length === 16, "invalid salt") - .optional(), + salt: base64Bytes(16, "invalid salt").optional(), files: z .array(fileEntrySchema) .max(MAX_FILES_PER_PASTE, `at most ${MAX_FILES_PER_PASTE} files per paste`) diff --git a/vitest.config.mts b/vitest.config.mts new file mode 100644 index 0000000..9745e76 --- /dev/null +++ b/vitest.config.mts @@ -0,0 +1,13 @@ +import { fileURLToPath } from "node:url"; +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + resolve: { + alias: { "@": fileURLToPath(new URL("./src", import.meta.url)) }, + }, + test: { + environment: "node", + include: ["src/**/*.test.ts"], + env: { PASTE_MASTER_KEY: "test-master-key" }, + }, +});