diff --git a/.env.example b/.env.example index db8bf44..330d6e8 100644 --- a/.env.example +++ b/.env.example @@ -17,6 +17,22 @@ DB_NAME=msk_paste # Generate with: openssl rand -hex 32 IP_HASH_SECRET=change_me_with_openssl_rand_hex_32 +# ─── Spam protection ──────────────────────────────────────────────── +# Cloudflare Turnstile for the create form. REQUIRED in production: without +# both keys the form cannot create pastes there. Create a widget at +# dash.cloudflare.com → Turnstile for paste.msk-scripts.de. For local tests +# Cloudflare's test keys always pass: +# site key 1x00000000000000000000AA, secret 1x0000000000000000000000000000000AA +CAPTCHA_SITE_KEY= +CAPTCHA_SECRET_KEY= + +# Pastes and bytes one address may create through the form per 24 hours +DAILY_PASTES_PER_IP=20 +DAILY_BYTES_PER_IP=5242880 + +# Pastes one API key may create per hour (keys: scripts/api-key.sh) +API_KEY_CREATE_PER_HOUR=120 + # ─── Limits ────────────────────────────────────────────────────────── # IMPORTANT: never put inline `# comments` next to a value — systemd's # EnvironmentFile keeps them as part of the variable, which breaks parsing. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5b8cbab --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,61 @@ +# ============================================================================= +# Build +# ----------------------------------------------------------------------------- +# Type-checks, tests and compiles the app the same way the deploy workflow +# does, but on every pull request. Without it a change that breaks the build +# only shows up after the merge, when deploy.yml runs on main. +# +# No repository secrets are used on purpose. Pull requests from bots run in a +# context where secrets are empty, and a job that needs them fails there every +# time. The dummy values below are enough to compile: every route is rendered +# on demand, so nothing touches the database at build time. +# ============================================================================= + +name: Build + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: + contents: read + +concurrency: + group: build-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v6 + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: '24' + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Type-check + run: npm run type-check + + - name: Test + run: npm test + + - name: Build + env: + NEXT_PUBLIC_BASE_URL: http://localhost:3012 + DB_HOST: build-dummy + DB_USER: build-dummy + DB_PASSWORD: build-dummy + DB_NAME: build-dummy + IP_HASH_SECRET: build-dummy-secret-do-not-use + run: npm run build diff --git a/README.md b/README.md index 6578acd..6ec93fa 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,9 @@ ## 🛡️ Privacy & Security -- **No tracking, no analytics, no third-party scripts** other than Google Fonts. +- **No tracking, no analytics.** The only third-party script is Cloudflare Turnstile on the create page. +- **Spam protection:** Turnstile, a honeypot, a signed form timestamp, daily limits per address and + content checks (encoded files, link spam, repeats). Scripts need an API key. - **IPs are never stored.** Rate limiting uses HMAC-SHA-256(ip, secret). - **Passwords** are stored as bcrypt hashes (cost 12) only. - **Expired pastes are deleted**, not soft-deleted. @@ -82,10 +84,14 @@ Details: [`deployment/README.md`](deployment/README.md). ## 📡 REST API +Reading is open. Creating a paste from a script needs an API key, issued by the operator on the +server (see [API keys](#-api-keys)); without one, `POST /api/pastes` only accepts the site's own form. + ### `POST /api/pastes` ```bash curl -X POST https://paste.msk-scripts.de/api/pastes \ + -H 'Authorization: Bearer mskp_…' \ -H 'Content-Type: application/json' \ -d '{ "content": "console.log(\"hello world\")", @@ -112,7 +118,7 @@ Response: | Method | Path | Purpose | |----------|-------------------------------|--------------------------------------| -| `POST` | `/api/pastes` | Create a paste | +| `POST` | `/api/pastes` | Create a paste (API key required) | | `GET` | `/api/pastes/:id` | Fetch paste metadata + content | | `POST` | `/api/pastes/:id/verify` | Verify password, returns content | | `DELETE` | `/api/pastes/:id?token=…` | Delete a paste with its delete token | @@ -129,6 +135,20 @@ npm run lint # ESLint npm run type-check # TypeScript --noEmit npm run migrate # Apply DB migrations npm run cleanup # Delete expired pastes (run via cron) +npm run api-key -- help # Manage API keys (see below) +``` + +## 🔑 API keys + +Only someone with a shell on the server and read access to the app's `.env` can manage keys. A key is +shown once when it is created; the database keeps only a scrypt hash of it. + +```bash +/opt/msk-paste/scripts/api-key.sh help # all commands +/opt/msk-paste/scripts/api-key.sh list # id, prefix, label, last use, state +/opt/msk-paste/scripts/api-key.sh create "