feat: 2.0.2 — rate limiting for the whole site (#157)
The Worker now runs first for every request except the content-hashed bundles under /assets/ (run_worker_first: ["/*", "!/assets/*"]) and counts it against a per-client limit before serving it: - SITE_LIMITER: pages and public files, 120 requests / 60 s - API_LIMITER: every /api/* request, 60 / 60 s - VERIFY_LIMITER: /api/turnstile/verify on top, 30 / 60 s (unchanged) Over the limit, pages get a plain-text 429 in the four UI languages and the API a JSON 429 (rate_limited); both carry Retry-After: 60. Clients are keyed on their IPv4 address or the /64 of their IPv6 address, never logged. Pages still go through env.ASSETS.fetch(), so _headers, _redirects and the SPA fallback apply as before. A failing limiter lets requests through. Previews get their own counters (namespace_id 4204/4206). Docs: DEPLOYMENT, PRIVACY (wording only, nothing new collected, no re-consent), SECURITY, CONTRIBUTING, READMEs, CLAUDE.md, ROADMAP, CHANGELOG. Version 2.0.2 (versionCode 20002). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6229199137
commit
72cb9a033d
24 files changed
+397
-73
No files matched your search
@@ -8,6 +8,16 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
||||
|
||||
No unreleased changes at this time. Future work tracked in `docs/ROADMAP.md` under "Beyond".
|
||||
|
||||
## [2.0.2] — 2026-10-27
|
||||
|
||||
### Added
|
||||
|
||||
- **Rate limiting for the whole website, not just the human check.** The Worker now runs first for every request except the content-hashed bundles under `/assets/` (`run_worker_first: ["/*", "!/assets/*"]`) and counts it against a per-client limit before serving it: pages and public files 120 requests a minute (`SITE_LIMITER`, about 40 page loads), every `/api/*` request 60 a minute (`API_LIMITER`), and `/api/turnstile/verify` keeps its own 30 a minute on top. Over the limit, pages get a plain-text `429 Too Many Requests` in English, Vietnamese, Japanese and Chinese, and the API gets `{"ok":false,"error":"rate_limited"}`; both carry `Retry-After: 60`. Clients are keyed on their IPv4 address or the /64 network of their IPv6 address, which is never logged. Pages are still served through the assets binding, so the security headers, the old-path redirects and the SPA fallback are unchanged. If the limiter itself fails, requests go through rather than taking the site down. Preview deployments get their own counters.
|
||||
|
||||
### Changed
|
||||
|
||||
- The Privacy Policy describes the rate limit for page requests too. Nothing new is collected, so you are not asked to accept it again.
|
||||
|
||||
## [2.0.1] — 2026-10-22
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -6,14 +6,14 @@ Guidance for Claude (and other AI assistants) working on this repository.
|
||||
|
||||
**JSONPrism** converts one JSON input into 12 formats (JSONL, CSV, TSV, YAML, XML, TOML, .NET RESX, Markdown table, SQL INSERT, BSON, CBOR, MessagePack) and parses six of them (JSONL, CSV, TSV, YAML, TOML, RESX) back. Conversion always runs on the user's device. It ships as:
|
||||
|
||||
- a web app at <https://jsonprism.poli0981.dev>, served by the Cloudflare Worker `jsonprism` (static assets + a tiny `/api/*` Worker), deployed by Cloudflare Workers Builds on every push to `main`;
|
||||
- a web app at <https://jsonprism.poli0981.dev>, served by the Cloudflare Worker `jsonprism` (static assets behind a tiny Worker that rate limits requests and answers `/api/*`), deployed by Cloudflare Workers Builds on every push to `main`;
|
||||
- native apps built with Tauri 2: Windows, macOS, Linux and Android (sideload APK).
|
||||
|
||||
GitHub Pages (`poli0981.github.io/jsonPrism`) now only redirects to the new domain.
|
||||
|
||||
The maintainer is **Kokone** ([@poli0981](https://github.com/poli0981)). Audience: the developer community on the open-source Discord server plus YouTube viewers who watch indie/visual-novel gameplay and occasionally want a quick devtool.
|
||||
|
||||
**Current release**: 2.0.0. See [`docs/ROADMAP.md`](docs/ROADMAP.md) for what is next.
|
||||
**Current release**: 2.0.2. See [`docs/ROADMAP.md`](docs/ROADMAP.md) for what is next.
|
||||
|
||||
## Stack — exact versions matter
|
||||
|
||||
@@ -33,7 +33,7 @@ Do not propose downgrading or "modernizing" to deprecated patterns.
|
||||
|
||||
## Web platform (Cloudflare)
|
||||
|
||||
- `wrangler.jsonc`: static assets from `dist/` with SPA fallback; only `/api/*` runs the Worker (`run_worker_first`). Bindings: `ASSETS`, `VERIFY_LIMITER` (rate limit), var `ALLOWED_HOSTNAMES`, secret `TURNSTILE_SECRET` (dashboard; locally `.dev.vars`, copied from `.dev.vars.example`).
|
||||
- `wrangler.jsonc`: static assets from `dist/` with SPA fallback. Every request except the hashed `/assets/*` bundles runs the Worker first (`run_worker_first`): it rate limits per client (`worker/rate-limit.ts`), then passes pages to `env.ASSETS.fetch()` (which still applies `_headers`, `_redirects` and the SPA fallback) or answers `/api/*`. Bindings: `ASSETS`, `SITE_LIMITER` / `API_LIMITER` / `VERIFY_LIMITER` (rate limits; each needs a preview twin with its own `namespace_id` under `previews`), var `ALLOWED_HOSTNAMES`, secret `TURNSTILE_SECRET` (dashboard; locally `.dev.vars`, copied from `.dev.vars.example`).
|
||||
- `worker/index.ts` may only have a **default export** — workerd treats every named export of the entry module as an entrypoint and refuses to start. Put shared code in other modules (`worker/verify.ts`, `worker/turnstile.ts`, `worker/http.ts`).
|
||||
- Worker logs are structured (`logEvent`) and must never contain IPs, tokens or user content.
|
||||
- `public/_headers` holds the CSP and security headers; `public/_redirects` maps the old `/jsonPrism/*` paths. Adding any third-party script, style, font or connection means updating the CSP there (and the Tauri CSP in `tauri.conf.json` if it applies to the apps).
|
||||
|
||||
+8
-4
@@ -117,16 +117,20 @@ Cloudflare's runtime and is not bound by this rule.
|
||||
## Cloudflare Worker (web build)
|
||||
|
||||
The website is served by a Cloudflare Worker configured in
|
||||
[`wrangler.jsonc`](wrangler.jsonc). Only `/api/*` runs Worker code;
|
||||
everything else is static files from `dist/`. The code lives in
|
||||
[`wrangler.jsonc`](wrangler.jsonc). Every request except the hashed bundles
|
||||
under `/assets/` runs the Worker first: it applies a per-client rate limit,
|
||||
then serves pages from `dist/` through the `ASSETS` binding or answers
|
||||
`/api/*`. The code lives in
|
||||
[`worker/`](worker/):
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `worker/index.ts` | Router. The entry module must only have a **default export**: workerd treats named exports as entrypoints. |
|
||||
| `worker/index.ts` | Router: rate limit, then the `ASSETS` binding for pages or the API handlers. The entry module must only have a **default export**: workerd treats named exports as entrypoints. |
|
||||
| `worker/rate-limit.ts` | Per-client limits (`SITE_LIMITER`, `API_LIMITER`), IPv4 / IPv6-/64 keys, 429 responses |
|
||||
| `worker/env.ts` | The bindings and variables the Worker reads |
|
||||
| `worker/verify.ts` | `POST /api/turnstile/verify`: same-origin check, JSON only, body size cap, rate limit |
|
||||
| `worker/turnstile.ts` | Cloudflare siteverify call: timeout, one retry, hostname / action / age checks |
|
||||
| `worker/http.ts` | JSON responses with strict headers, structured logs |
|
||||
| `worker/http.ts` | JSON and plain-text responses with strict headers, structured logs |
|
||||
|
||||
Worker logs must never contain IP addresses, tokens or user content.
|
||||
|
||||
|
||||
+8
-7
@@ -35,13 +35,14 @@ Privacy questions and requests: **privacy@poli0981.dev**.
|
||||
Cloudflare, Inc. serves the website and processes the data every web
|
||||
request carries (IP address, user agent, requested URL, time, TLS details)
|
||||
to deliver pages and protect the service against abuse. JSONPrism's own
|
||||
server code handles only the human-check API (`/api/turnstile/verify`)
|
||||
and a health check. For that API it records structured events — outcome,
|
||||
HTTP status, the Cloudflare data centre code, duration and Turnstile error
|
||||
codes — in Cloudflare Workers Logs, kept for 7 days. These events never
|
||||
contain IP addresses, Turnstile tokens or anything you convert. The API is
|
||||
rate limited per client by Cloudflare; the client key is not stored by
|
||||
JSONPrism.
|
||||
server code answers only the human-check API (`/api/turnstile/verify`) and
|
||||
a health check, and counts page and API requests against a per-client rate
|
||||
limit before serving them. It records structured events — outcome, HTTP
|
||||
status, the Cloudflare data centre code, duration, Turnstile error codes
|
||||
and refused over-limit requests — in Cloudflare Workers Logs, kept for 7
|
||||
days. These events never contain IP addresses, Turnstile tokens or anything
|
||||
you convert. The rate-limit counters are kept by Cloudflare, keyed on your
|
||||
IP address (for IPv6, its /64 network); JSONPrism does not store the key.
|
||||
|
||||
### Human check (website)
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ Details: [`PRIVACY.md`](PRIVACY.md).
|
||||
- **i18next** for translations, **Zustand** for state, **React Router 8** for routing, **Sonner** for toasts
|
||||
- **Vitest** + Testing Library for tests
|
||||
- **Node.js 26** for the toolchain
|
||||
- **Cloudflare Workers** hosts the web app (static assets plus a small Worker for `/api/*`)
|
||||
- **Cloudflare Workers** hosts the web app (static assets behind a small Worker that rate limits requests and serves `/api/*`)
|
||||
- **Tauri 2.12** for the desktop (Windows, macOS, Linux) and Android apps
|
||||
|
||||
## Quick start
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ Chi tiết: [`PRIVACY.md`](PRIVACY.md).
|
||||
- **i18next** cho dịch thuật, **Zustand** cho state, **React Router 8** cho routing, **Sonner** cho toast
|
||||
- **Vitest** + Testing Library cho test
|
||||
- **Node.js 26** cho toolchain
|
||||
- **Cloudflare Workers** host bản web (static assets kèm một Worker nhỏ cho `/api/*`)
|
||||
- **Cloudflare Workers** host bản web (static assets phía sau một Worker nhỏ giới hạn tần suất request và phục vụ `/api/*`)
|
||||
- **Tauri 2.12** cho app desktop (Windows, macOS, Linux) và Android
|
||||
|
||||
## Bắt đầu nhanh
|
||||
|
||||
+3
-2
@@ -50,8 +50,9 @@ website's edge configuration.
|
||||
In scope:
|
||||
|
||||
- `src/` — the React app, converters and batch processor.
|
||||
- `worker/` — the Cloudflare Worker (`/api/turnstile/verify`,
|
||||
`/api/health`): origin checks, rate limiting, request validation.
|
||||
- `worker/` — the Cloudflare Worker (per-client rate limits for the whole
|
||||
site, `/api/turnstile/verify`, `/api/health`): rate limiting, origin
|
||||
checks, request validation.
|
||||
- Website edge configuration: `public/_headers` (CSP and security
|
||||
headers), `public/_redirects`, `wrangler.jsonc`.
|
||||
- `src-tauri/` — the Rust shell, capabilities, file-system scope and CSP.
|
||||
|
||||
+54
-15
@@ -19,16 +19,23 @@ in [dev_env.md](dev_env.md), Tauri details in [TAURI-NOTES.md](TAURI-NOTES.md).
|
||||
|
||||
```
|
||||
browser ──► jsonprism.poli0981.dev (Cloudflare Worker "jsonprism")
|
||||
├─ /api/* → worker/index.ts ──► Turnstile siteverify
|
||||
└─ everything → static assets from dist/
|
||||
else (_headers, _redirects, SPA fallback to index.html)
|
||||
├─ /assets/* → static assets from dist/ (hashed bundles, no Worker)
|
||||
└─ everything → worker/index.ts: per-client rate limit, then
|
||||
else ├─ /api/* → answered here ──► Turnstile siteverify
|
||||
└─ pages → ASSETS binding: dist/ with _headers,
|
||||
_redirects, SPA fallback to index.html
|
||||
```
|
||||
|
||||
- One Cloudflare Worker, **`jsonprism`** (Workers Paid plan), configured in
|
||||
`wrangler.jsonc`.
|
||||
- **Static assets**: the Vite build in `dist/`, served by Workers Static Assets
|
||||
with `not_found_handling: "single-page-application"`.
|
||||
- **Worker code** runs only for `/api/*` (`run_worker_first: ["/api/*"]`).
|
||||
- **Worker code** runs first for every request except `/assets/*`
|
||||
(`run_worker_first: ["/*", "!/assets/*"]`). It counts the request against a
|
||||
per-client [rate limit](#rate-limiting), hands pages and public files to the
|
||||
`ASSETS` binding — which still applies `_headers`, `_redirects` and the SPA
|
||||
fallback — and answers `/api/*` itself. `/assets/*` holds the content-hashed
|
||||
bundles, most of each page load, and stays on the Worker-free path.
|
||||
Conversion never happens on the server.
|
||||
|
||||
| Route | Code | Response |
|
||||
@@ -39,8 +46,9 @@ browser ──► jsonprism.poli0981.dev (Cloudflare Worker "jsonprism")
|
||||
|
||||
- `worker/index.ts` may only have a default export: workerd treats every named
|
||||
export of the entry module as an entrypoint. Put helpers in other modules.
|
||||
- API responses set their own headers (`worker/http.ts`: `no-store`,
|
||||
`nosniff`, `default-src 'none'`); assets get theirs from `public/_headers`.
|
||||
- Responses the Worker builds itself (API answers, 429s) set their own headers
|
||||
(`worker/http.ts`: `no-store`, `nosniff`, `default-src 'none'`); pages and
|
||||
assets get theirs from `public/_headers`.
|
||||
- The Worker has its own `tsconfig.worker.json`; its runtime and binding types
|
||||
come from `npm run cf:types` (`wrangler types` → gitignored
|
||||
`worker-configuration.d.ts`).
|
||||
@@ -78,8 +86,8 @@ after the branch (`<branch>-jsonprism.<subdomain>.workers.dev` when workers.dev
|
||||
is enabled) and reports it on the pull request.
|
||||
|
||||
- Previews inherit no production vars or bindings. `wrangler.jsonc` → `previews`
|
||||
declares them again: a separate rate-limit counter (`namespace_id` 4202) and
|
||||
an empty `ALLOWED_HOSTNAMES`. Any binding added at the top level needs a
|
||||
declares them again: separate rate-limit counters (`namespace_id` 4202, 4204,
|
||||
4206) and an empty `ALLOWED_HOSTNAMES`. Any binding added at the top level needs a
|
||||
preview-safe twin there, or `wrangler preview` fails with "missing a
|
||||
`previews` block".
|
||||
- Previews get no `TURNSTILE_SECRET` (set one with
|
||||
@@ -117,7 +125,7 @@ is enabled) and reports it on the pull request.
|
||||
| --- | --- | --- |
|
||||
| `TURNSTILE_SECRET` | Secret | Worker → **Settings → Variables and Secrets**, or `npx wrangler secret put TURNSTILE_SECRET`. Never in the repo. |
|
||||
| `ALLOWED_HOSTNAMES` | Variable | `wrangler.jsonc` → `vars`: comma-separated hostnames a Turnstile token may be issued on. |
|
||||
| `VERIFY_LIMITER` | Binding | `wrangler.jsonc` → `ratelimits` — see [Rate limiting](#rate-limiting). |
|
||||
| `SITE_LIMITER`, `API_LIMITER`, `VERIFY_LIMITER` | Bindings | `wrangler.jsonc` → `ratelimits` — see [Rate limiting](#rate-limiting). |
|
||||
|
||||
- Plain variables added in the dashboard are replaced by `wrangler.jsonc` `vars`
|
||||
on every deploy (`keep_vars` is off); secrets are kept. The sitekey needs no
|
||||
@@ -216,13 +224,41 @@ Vite copies `public/` into `dist/`; Workers Static Assets applies `_headers` and
|
||||
|
||||
## Rate limiting
|
||||
|
||||
- Binding `VERIFY_LIMITER` (`ratelimits` in `wrangler.jsonc`, `namespace_id`
|
||||
`4201`): 30 requests per 60 s per client, keyed on `CF-Connecting-IP`. The IP
|
||||
is only the key; it is never logged.
|
||||
- Over the limit → 429 `rate_limited` with `Retry-After: 60`. The app treats
|
||||
that as "check unavailable" and lets the user continue.
|
||||
- To change it, edit `simple.limit` / `simple.period` and deploy. Keep
|
||||
Three [Rate Limiting bindings](https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/)
|
||||
(`ratelimits` in `wrangler.jsonc`), applied in `worker/rate-limit.ts`:
|
||||
|
||||
| Binding | Counts | Limit | `namespace_id` (production / preview) |
|
||||
| --- | --- | --- | --- |
|
||||
| `SITE_LIMITER` | pages and public files: everything outside `/api/` and `/assets/` | 120 requests / 60 s | 4205 / 4206 |
|
||||
| `API_LIMITER` | every `/api/*` request | 60 requests / 60 s | 4203 / 4204 |
|
||||
| `VERIFY_LIMITER` | `/api/turnstile/verify`, on top of `API_LIMITER` | 30 requests / 60 s | 4201 / 4202 |
|
||||
|
||||
- The key is the client's IPv4 address, or the /64 network of an IPv6 address
|
||||
(one subscriber usually holds a whole /64), from `CF-Connecting-IP`. It is
|
||||
only the key; it is never logged.
|
||||
- A page load makes about three counted requests (`index.html`,
|
||||
`theme-init.js`, `favicon.svg`); the hashed bundles under `/assets/` are not
|
||||
counted. 120 per minute is about 40 page loads a minute from one address.
|
||||
- Over the limit: pages get a plain-text 429 in the four UI languages, the API
|
||||
gets a JSON 429 `{"ok":false,"error":"rate_limited"}`; both carry
|
||||
`Retry-After: 60` and `Cache-Control: no-store`. The app treats a 429 from
|
||||
the verify endpoint as "check unavailable" and lets the user continue.
|
||||
- Counters live per Cloudflare data centre and update asynchronously, so a
|
||||
burst can overshoot slightly before the 429s start. If the limiter itself
|
||||
fails the request goes through (`ratelimit.error` in the logs): a broken
|
||||
counter must not take the site down.
|
||||
- Every request that reaches the Worker is billed as a Worker request,
|
||||
refused ones included. The limits keep floods off the API and slow scrapers;
|
||||
volumetric attacks are Cloudflare's DDoS protection's job, in front of the
|
||||
Worker. For a zone-level limit that also covers `/assets/*` and runs before
|
||||
the Worker, add a WAF rate limiting rule for the hostname in the dashboard
|
||||
(**Security → WAF → Rate limiting rules**).
|
||||
- To change a limit, edit `simple.limit` / `simple.period` (10 or 60 s) for
|
||||
production and its twin under `previews`, then deploy. Keep every
|
||||
`namespace_id` unique within the Cloudflare account.
|
||||
- To see it work locally, run `npm run preview:cf` and then
|
||||
`for i in $(seq 70); do curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8787/api/health; done | sort | uniq -c`
|
||||
— 60 × 200, then 429s for the rest of the minute.
|
||||
|
||||
## Workers Logs
|
||||
|
||||
@@ -235,6 +271,9 @@ Vite copies `public/` into `dist/`; Workers Static Assets applies `_headers` and
|
||||
Outcomes: `verified`, `rejected`, `bad-origin`, `bad-method`,
|
||||
`bad-content-type`, `too-large`, `rate-limited`, `bad-json`, `bad-token`,
|
||||
`misconfigured`, `unavailable`.
|
||||
- Rate limiting writes `{"event":"ratelimit.exceeded","scope":"site"|"api","colo":…}`
|
||||
for each refused request, and `ratelimit.error` with a `detail` if the
|
||||
limiter binding fails.
|
||||
- Never log IPs, tokens or user content (`logEvent()` in `worker/http.ts`).
|
||||
Source maps are not uploaded (`upload_source_maps: false`).
|
||||
|
||||
|
||||
+2
-1
@@ -4,7 +4,7 @@ This document is the **single source of truth** for what's done, what's next, an
|
||||
|
||||
Update it as work lands — keep the project status honest.
|
||||
|
||||
**Current release: v2.0.0 (2026-10-22).** The web app runs at https://jsonprism.poli0981.dev (Cloudflare Workers); desktop and Android builds are on [GitHub Releases](https://github.com/poli0981/jsonPrism/releases).
|
||||
**Current release: v2.0.2 (2026-10-27).** The web app runs at https://jsonprism.poli0981.dev (Cloudflare Workers); desktop and Android builds are on [GitHub Releases](https://github.com/poli0981/jsonPrism/releases).
|
||||
|
||||
---
|
||||
|
||||
@@ -302,6 +302,7 @@ A platform release: a new home for the web app, a human check and analytics conf
|
||||
- [x] Web app served by the Cloudflare Worker `jsonprism` (Workers Static Assets, SPA fallback) at **https://jsonprism.poli0981.dev**; config in `wrangler.jsonc`, operations in [`docs/DEPLOYMENT.md`](DEPLOYMENT.md)
|
||||
- [x] Cloudflare Workers Builds deploys every push to `main`; the GitHub Pages deploy workflow and `public/404.html` are gone
|
||||
- [x] `/api/*` Worker in `worker/`: `POST /api/turnstile/verify` (same-origin only, 4 KB body cap, 30 requests / 60 s rate limit) and `GET /api/health`; structured Workers Logs without IPs, tokens or user content
|
||||
- [x] 2.0.2: per-client rate limits for the whole site — the Worker runs first for everything except the hashed `/assets/*` bundles; pages 120 / 60 s, API 60 / 60 s, verify 30 / 60 s; IPv6 keyed on its /64; 429 with `Retry-After`
|
||||
- [x] Static headers in `public/_headers` (CSP, HSTS, COOP, Permissions-Policy, immutable `/assets/*`), `/jsonPrism/*` → 301 in `public/_redirects`, `robots.txt`, `sitemap.xml`, `.well-known/security.txt`, Open Graph image
|
||||
- [x] GitHub Pages keeps only a path-preserving redirect to the new domain (`pages-redirect.yml`, run by hand)
|
||||
- [x] `production-smoke.yml` waits for each pushed commit to go live, then checks headers, routes, redirects and the API
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ npm run preview:cf # wrangler dev on http://localhost:8787 (builds
|
||||
- `.dev.vars` holds the Worker secret `TURNSTILE_SECRET` for local runs. It is
|
||||
gitignored; never put the production secret in it.
|
||||
- `npm run preview:cf` serves `dist/` the way production does (`_headers`,
|
||||
`_redirects`, SPA fallback) together with the `/api/*` Worker. On localhost
|
||||
`_redirects`, SPA fallback) behind the Worker (rate limits, `/api/*`). On localhost
|
||||
the app uses Cloudflare's test sitekey, so the Consent Gate's Turnstile check
|
||||
passes on its own.
|
||||
- `npm run cf:types` — regenerates `worker-configuration.d.ts` (gitignored)
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "jsonprism",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "jsonprism",
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@codemirror/lang-json": "^6.0.2",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "jsonprism",
|
||||
"private": true,
|
||||
"version": "2.0.1",
|
||||
"version": "2.0.2",
|
||||
"type": "module",
|
||||
"description": "Disperse JSON into 12 formats (six convert back) — JSONL, CSV, TSV, YAML, XML, TOML, RESX, Markdown, SQL, BSON, CBOR, MessagePack. Conversion runs locally in your browser or desktop app.",
|
||||
"author": "poli0981 <code@poli0981.dev> (https://github.com/poli0981)",
|
||||
|
||||
Generated
+1
-1
@@ -1876,7 +1876,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jsonprism"
|
||||
version = "2.0.1"
|
||||
version = "2.0.2"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jsonprism"
|
||||
version = "2.0.1"
|
||||
version = "2.0.2"
|
||||
description = "Disperse JSON into many formats."
|
||||
authors = ["poli0981 <code@poli0981.dev>"]
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
By installing and using JSONPrism, you agree to the terms below.\par
|
||||
\par
|
||||
JSONPrism is free, open-source software licensed under the Apache License 2.0:\par
|
||||
https://github.com/poli0981/jsonPrism/blob/v2.0.1/LICENSE\par
|
||||
https://github.com/poli0981/jsonPrism/blob/v2.0.2/LICENSE\par
|
||||
\par
|
||||
Your use is also governed by the following documents (version 2.0, effective 2026-10-22):\par
|
||||
\bullet\tab Terms of Service (EULA): https://github.com/poli0981/jsonPrism/blob/v2.0.1/TERMS.md\par
|
||||
\bullet\tab Privacy Policy: https://github.com/poli0981/jsonPrism/blob/v2.0.1/PRIVACY.md\par
|
||||
\bullet\tab Disclaimer: https://github.com/poli0981/jsonPrism/blob/v2.0.1/DISCLAIMER.md\par
|
||||
\bullet\tab Terms of Service (EULA): https://github.com/poli0981/jsonPrism/blob/v2.0.2/TERMS.md\par
|
||||
\bullet\tab Privacy Policy: https://github.com/poli0981/jsonPrism/blob/v2.0.2/PRIVACY.md\par
|
||||
\bullet\tab Disclaimer: https://github.com/poli0981/jsonPrism/blob/v2.0.2/DISCLAIMER.md\par
|
||||
\par
|
||||
JSONPrism is provided \ldblquote as is\rdblquote , without warranty of any kind. The desktop app converts everything on your device and makes no network requests of its own.\par
|
||||
\par
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
},
|
||||
"android": {
|
||||
"minSdkVersion": 31,
|
||||
"versionCode": 20001
|
||||
"versionCode": 20002
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import type { WorkerEnv } from '../env';
|
||||
import worker from '../index';
|
||||
import { handleVerify, VERIFIED_TTL_MS, type WorkerEnv } from '../verify';
|
||||
import { handleVerify, VERIFIED_TTL_MS } from '../verify';
|
||||
import { TEST_SECRET } from '../turnstile';
|
||||
|
||||
/** What the runtime hands the Worker: a Request carrying Cloudflare's `cf` properties. */
|
||||
type IncomingRequest = Parameters<typeof worker.fetch>[0];
|
||||
|
||||
const ORIGIN = 'https://jsonprism.poli0981.dev';
|
||||
const URL_VERIFY = `${ORIGIN}/api/turnstile/verify`;
|
||||
|
||||
const assetsFetch = vi.fn(async () => new Response('<!doctype html>'));
|
||||
|
||||
function env(overrides: Partial<WorkerEnv> = {}): WorkerEnv {
|
||||
return {
|
||||
ASSETS: {} as Fetcher,
|
||||
ASSETS: { fetch: assetsFetch } as unknown as Fetcher,
|
||||
ALLOWED_HOSTNAMES: 'jsonprism.poli0981.dev',
|
||||
TURNSTILE_SECRET: 'real-secret',
|
||||
...overrides,
|
||||
@@ -17,7 +23,7 @@ function env(overrides: Partial<WorkerEnv> = {}): WorkerEnv {
|
||||
|
||||
function verifyRequest(
|
||||
init: { body?: string; headers?: Record<string, string>; method?: string } = {},
|
||||
) {
|
||||
): IncomingRequest {
|
||||
return new Request(URL_VERIFY, {
|
||||
method: init.method ?? 'POST',
|
||||
headers: { Origin: ORIGIN, 'Content-Type': 'application/json', ...init.headers },
|
||||
@@ -27,6 +33,13 @@ function verifyRequest(
|
||||
|
||||
const call = (request: Request, e: WorkerEnv = env()) => handleVerify(request, e);
|
||||
|
||||
/** A limiter that allows the first `allowed` calls, like Cloudflare's binding once a client is over. */
|
||||
function limiter(allowed = Infinity) {
|
||||
let calls = 0;
|
||||
const limit = vi.fn(async (_options: RateLimitOptions) => ({ success: ++calls <= allowed }));
|
||||
return { limit } as RateLimit & { limit: typeof limit };
|
||||
}
|
||||
|
||||
let siteverify: ReturnType<typeof vi.fn<typeof fetch>>;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -151,4 +164,80 @@ describe('router', () => {
|
||||
const missing = await worker.fetch(new Request(`${ORIGIN}/api/nope`), env());
|
||||
expect(missing.status).toBe(404);
|
||||
});
|
||||
|
||||
it('hands pages and public files to the ASSETS binding', async () => {
|
||||
const page: IncomingRequest = new Request(`${ORIGIN}/about`);
|
||||
const res = await worker.fetch(page, env());
|
||||
expect(await res.text()).toBe('<!doctype html>');
|
||||
expect(assetsFetch).toHaveBeenCalledWith(page);
|
||||
});
|
||||
});
|
||||
|
||||
describe('rate limiting', () => {
|
||||
const fromClient = (path: string): IncomingRequest =>
|
||||
new Request(`${ORIGIN}${path}`, { headers: { 'CF-Connecting-IP': '203.0.113.9' } });
|
||||
|
||||
it('counts pages against SITE_LIMITER and answers 429 in plain text once over', async () => {
|
||||
const site = limiter(2);
|
||||
const api = limiter();
|
||||
const e = env({ SITE_LIMITER: site, API_LIMITER: api });
|
||||
expect((await worker.fetch(fromClient('/'), e)).status).toBe(200);
|
||||
expect((await worker.fetch(fromClient('/theme-init.js'), e)).status).toBe(200);
|
||||
const res = await worker.fetch(fromClient('/'), e);
|
||||
expect(res.status).toBe(429);
|
||||
expect(res.headers.get('Retry-After')).toBe('60');
|
||||
expect(res.headers.get('Cache-Control')).toBe('no-store');
|
||||
expect(res.headers.get('Content-Type')).toBe('text/plain; charset=utf-8');
|
||||
expect(await res.text()).toContain('Too many requests');
|
||||
expect(assetsFetch).toHaveBeenCalledTimes(2);
|
||||
expect(site.limit).toHaveBeenCalledWith({ key: '203.0.113.9' });
|
||||
expect(api.limit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('counts every /api/* request against API_LIMITER and answers JSON 429', async () => {
|
||||
const site = limiter();
|
||||
const api = limiter(1);
|
||||
const e = env({ SITE_LIMITER: site, API_LIMITER: api });
|
||||
expect((await worker.fetch(fromClient('/api/health'), e)).status).toBe(200);
|
||||
for (const path of ['/api/health', '/api/nope', '/api/turnstile/verify']) {
|
||||
const res = await worker.fetch(fromClient(path), e);
|
||||
expect(res.status).toBe(429);
|
||||
expect(res.headers.get('Retry-After')).toBe('60');
|
||||
expect(await res.json()).toEqual({ ok: false, error: 'rate_limited' });
|
||||
}
|
||||
expect(siteverify).not.toHaveBeenCalled();
|
||||
expect(site.limit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('applies VERIFY_LIMITER on top of API_LIMITER', async () => {
|
||||
const api = limiter();
|
||||
const verify = limiter(0);
|
||||
const res = await worker.fetch(
|
||||
verifyRequest({ headers: { 'CF-Connecting-IP': '203.0.113.9' } }),
|
||||
env({ API_LIMITER: api, VERIFY_LIMITER: verify }),
|
||||
);
|
||||
expect(res.status).toBe(429);
|
||||
expect(api.limit).toHaveBeenCalledOnce();
|
||||
expect(verify.limit).toHaveBeenCalledWith({ key: '203.0.113.9' });
|
||||
});
|
||||
|
||||
it('lets requests through when the limiter itself fails', async () => {
|
||||
const broken = {
|
||||
limit: vi.fn().mockRejectedValue(new Error('backend down')),
|
||||
} as unknown as RateLimit;
|
||||
const res = await worker.fetch(fromClient('/'), env({ SITE_LIMITER: broken }));
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
||||
it('never logs the client address', async () => {
|
||||
const log = vi.mocked(console.log);
|
||||
await worker.fetch(fromClient('/'), env({ SITE_LIMITER: limiter(0) }));
|
||||
await worker.fetch(fromClient('/api/health'), env({ API_LIMITER: limiter(0) }));
|
||||
const lines = log.mock.calls.map((args) => String(args[0]));
|
||||
expect(lines).toHaveLength(2);
|
||||
for (const line of lines) {
|
||||
expect(JSON.parse(line)).toMatchObject({ event: 'ratelimit.exceeded' });
|
||||
expect(line).not.toContain('203.0.113.9');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { clientKey } from '../rate-limit';
|
||||
|
||||
const from = (ip?: string) =>
|
||||
new Request('https://jsonprism.poli0981.dev/', {
|
||||
headers: ip === undefined ? {} : { 'CF-Connecting-IP': ip },
|
||||
});
|
||||
|
||||
describe('clientKey', () => {
|
||||
it('keys IPv4 clients on the full address', () => {
|
||||
expect(clientKey(from('203.0.113.9'))).toBe('203.0.113.9');
|
||||
});
|
||||
|
||||
it('keys IPv6 clients on their /64 network', () => {
|
||||
const a = clientKey(from('2001:db8:85a3:42:1:2:3:4'));
|
||||
expect(a).toBe('2001:db8:85a3:42::/64');
|
||||
expect(clientKey(from('2001:db8:85a3:42:ffff::1'))).toBe(a);
|
||||
expect(clientKey(from('2001:DB8:85A3:0042::9'))).toBe(a);
|
||||
expect(clientKey(from('2001:db8:85a3:43::1'))).not.toBe(a);
|
||||
});
|
||||
|
||||
it('expands :: wherever it appears', () => {
|
||||
expect(clientKey(from('2001:db8::1'))).toBe('2001:db8:0:0::/64');
|
||||
expect(clientKey(from('::1'))).toBe('0:0:0:0::/64');
|
||||
expect(clientKey(from('2001:db8:1:2::'))).toBe('2001:db8:1:2::/64');
|
||||
});
|
||||
|
||||
it('keeps IPv4-mapped IPv6 addresses whole', () => {
|
||||
expect(clientKey(from('::ffff:192.0.2.1'))).toBe('::ffff:192.0.2.1');
|
||||
});
|
||||
|
||||
it('falls back to a shared key without the header', () => {
|
||||
expect(clientKey(from())).toBe('unknown');
|
||||
expect(clientKey(from(''))).toBe('unknown');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/** Bindings and vars the Worker reads (declared in wrangler.jsonc). */
|
||||
export interface WorkerEnv {
|
||||
ASSETS: Fetcher;
|
||||
/** Comma-separated hostnames a token may have been issued on. */
|
||||
ALLOWED_HOSTNAMES: string;
|
||||
/** Secret set in the Cloudflare dashboard (.dev.vars locally). */
|
||||
TURNSTILE_SECRET?: string | undefined;
|
||||
/** Pages and public files: everything outside /api/ and the hashed /assets/ bundles. */
|
||||
SITE_LIMITER?: RateLimit;
|
||||
/** Every /api/* request. */
|
||||
API_LIMITER?: RateLimit;
|
||||
/** /api/turnstile/verify on top of API_LIMITER. */
|
||||
VERIFY_LIMITER?: RateLimit;
|
||||
}
|
||||
+18
-4
@@ -1,7 +1,6 @@
|
||||
/** JSON responses for the API routes, with defensive headers (assets get theirs from public/_headers). */
|
||||
/** Responses the Worker builds itself, with defensive headers (assets get theirs from public/_headers). */
|
||||
|
||||
const API_HEADERS: Record<string, string> = {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
const BASE_HEADERS: Record<string, string> = {
|
||||
'Cache-Control': 'no-store',
|
||||
'X-Content-Type-Options': 'nosniff',
|
||||
'Referrer-Policy': 'no-referrer',
|
||||
@@ -16,7 +15,22 @@ export function json(
|
||||
): Response {
|
||||
return new Response(JSON.stringify(body), {
|
||||
status,
|
||||
headers: { ...API_HEADERS, ...extraHeaders },
|
||||
headers: {
|
||||
...BASE_HEADERS,
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
...extraHeaders,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function text(
|
||||
body: string,
|
||||
status: number,
|
||||
extraHeaders: Record<string, string> = {},
|
||||
): Response {
|
||||
return new Response(body, {
|
||||
status,
|
||||
headers: { ...BASE_HEADERS, 'Content-Type': 'text/plain; charset=utf-8', ...extraHeaders },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+14
-4
@@ -1,18 +1,28 @@
|
||||
/**
|
||||
* JSONPrism edge Worker. Static assets (the SPA) are served by Workers Static
|
||||
* Assets before this code runs; `run_worker_first: ["/api/*"]` routes only the
|
||||
* API here. Conversion never happens server-side.
|
||||
* JSONPrism edge Worker. `run_worker_first` sends every request here except the
|
||||
* hashed bundles under /assets/, which Workers Static Assets serves directly.
|
||||
* Each request is counted against a per-client rate limit first; pages and
|
||||
* public files are then handed to the ASSETS binding (which still applies
|
||||
* public/_headers, public/_redirects and the SPA fallback), and /api/* is
|
||||
* answered here. Conversion never happens server-side.
|
||||
*
|
||||
* Only the default export may live in this module: workerd treats every named
|
||||
* export of the entry module as an entrypoint and refuses to start otherwise.
|
||||
*/
|
||||
|
||||
import type { WorkerEnv } from './env';
|
||||
import { json } from './http';
|
||||
import { handleVerify, type WorkerEnv } from './verify';
|
||||
import { throttle } from './rate-limit';
|
||||
import { handleVerify } from './verify';
|
||||
|
||||
export default {
|
||||
async fetch(request, env): Promise<Response> {
|
||||
const url = new URL(request.url);
|
||||
if (!url.pathname.startsWith('/api/')) {
|
||||
return (await throttle(request, env.SITE_LIMITER, 'site')) ?? env.ASSETS.fetch(request);
|
||||
}
|
||||
const limited = await throttle(request, env.API_LIMITER, 'api');
|
||||
if (limited) return limited;
|
||||
switch (url.pathname) {
|
||||
case '/api/turnstile/verify':
|
||||
return handleVerify(request, env);
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Per-client throttles. Every request except the hashed bundles under /assets/
|
||||
* reaches the Worker (`run_worker_first` in wrangler.jsonc): pages and public
|
||||
* files count against SITE_LIMITER, /api/* against API_LIMITER, and the
|
||||
* human-check endpoint also against its own VERIFY_LIMITER.
|
||||
*
|
||||
* Cloudflare counts per data centre and updates the counters asynchronously,
|
||||
* so a burst can overshoot slightly before the 429s start. The limits stop
|
||||
* floods and scrapers; people never get near them.
|
||||
*/
|
||||
|
||||
import { json, logEvent, text } from './http';
|
||||
|
||||
/** Every limiter uses a 60-second period, so a minute is always enough. */
|
||||
const RETRY_AFTER = '60';
|
||||
|
||||
/** The SPA isn't loaded yet when a page is refused, so the edge answers in all four UI languages. */
|
||||
const SITE_MESSAGE = [
|
||||
'Too many requests. Wait a minute, then try again.',
|
||||
'Quá nhiều yêu cầu. Vui lòng đợi một phút rồi thử lại.',
|
||||
'リクエストが多すぎます。1 分ほど待ってから、もう一度お試しください。',
|
||||
'请求过多。请等待一分钟后再试。',
|
||||
].join('\n');
|
||||
|
||||
type LimitScope = 'site' | 'api';
|
||||
|
||||
/**
|
||||
* The limiter key: the client's IPv4 address, or the /64 network of an IPv6
|
||||
* address — one subscriber usually holds a whole /64 and could otherwise
|
||||
* rotate through it. Only ever a key; never logged.
|
||||
*/
|
||||
export function clientKey(request: Request): string {
|
||||
const ip = request.headers.get('CF-Connecting-IP')?.trim().toLowerCase();
|
||||
if (!ip) return 'unknown';
|
||||
// IPv4, or IPv6 with an embedded IPv4 tail (::ffff:192.0.2.1): keep it whole.
|
||||
if (!ip.includes(':') || ip.includes('.')) return ip;
|
||||
const [head = '', tail] = ip.split('::');
|
||||
const left = head ? head.split(':') : [];
|
||||
const right = tail ? tail.split(':') : [];
|
||||
const groups =
|
||||
tail === undefined
|
||||
? left
|
||||
: [
|
||||
...left,
|
||||
...Array<string>(Math.max(0, 8 - left.length - right.length)).fill('0'),
|
||||
...right,
|
||||
];
|
||||
const prefix = groups.slice(0, 4).map((group) => Number.parseInt(group, 16).toString(16));
|
||||
return `${prefix.join(':')}::/64`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the request. Returns the 429 response when the client is over the
|
||||
* limit, otherwise null. Without the binding (unit tests) or when the limiter
|
||||
* itself fails, the request goes through: a broken counter must not take the
|
||||
* site down.
|
||||
*/
|
||||
export async function throttle(
|
||||
request: Request,
|
||||
limiter: RateLimit | undefined,
|
||||
scope: LimitScope,
|
||||
): Promise<Response | null> {
|
||||
if (!limiter) return null;
|
||||
const colo = (request.cf as { colo?: string } | undefined)?.colo;
|
||||
let success: boolean;
|
||||
try {
|
||||
({ success } = await limiter.limit({ key: clientKey(request) }));
|
||||
} catch (error) {
|
||||
logEvent('ratelimit.error', {
|
||||
scope,
|
||||
colo,
|
||||
detail: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
return null;
|
||||
}
|
||||
if (success) return null;
|
||||
logEvent('ratelimit.exceeded', { scope, colo });
|
||||
const headers = { 'Retry-After': RETRY_AFTER };
|
||||
return scope === 'api'
|
||||
? json({ ok: false, error: 'rate_limited' }, 429, headers)
|
||||
: text(SITE_MESSAGE, 429, headers);
|
||||
}
|
||||
+4
-12
@@ -7,18 +7,11 @@
|
||||
* public static files, so there is no server resource it unlocks.
|
||||
*/
|
||||
|
||||
import type { WorkerEnv } from './env';
|
||||
import { json, logEvent } from './http';
|
||||
import { clientKey } from './rate-limit';
|
||||
import { MAX_TOKEN_LENGTH, TEST_SECRET, verifyTurnstileToken } from './turnstile';
|
||||
|
||||
export interface WorkerEnv {
|
||||
ASSETS: Fetcher;
|
||||
/** Comma-separated hostnames a token may have been issued on. */
|
||||
ALLOWED_HOSTNAMES: string;
|
||||
/** Secret set in the Cloudflare dashboard (.dev.vars locally). */
|
||||
TURNSTILE_SECRET?: string | undefined;
|
||||
VERIFY_LIMITER?: RateLimit;
|
||||
}
|
||||
|
||||
/** Keep in sync with src/lib/turnstile.ts (TURNSTILE_ACTION). */
|
||||
const TURNSTILE_ACTION = 'gate';
|
||||
/** How long the browser may trust a passed check. Keep in sync with src/lib/human-check-storage.ts. */
|
||||
@@ -109,9 +102,8 @@ export async function handleVerify(request: Request, env: WorkerEnv): Promise<Re
|
||||
}
|
||||
|
||||
if (env.VERIFY_LIMITER) {
|
||||
// Generous per-client throttle; shared IPs (NAT, mobile carriers) still fit.
|
||||
const key = request.headers.get('CF-Connecting-IP') ?? 'unknown';
|
||||
const { success } = await env.VERIFY_LIMITER.limit({ key });
|
||||
// Stricter than API_LIMITER, still generous: shared IPs (NAT, mobile carriers) fit.
|
||||
const { success } = await env.VERIFY_LIMITER.limit({ key: clientKey(request) });
|
||||
if (!success) return finish(429, { ok: false, error: 'rate_limited' }, 'rate-limited');
|
||||
}
|
||||
|
||||
|
||||
+36
-5
@@ -3,8 +3,10 @@
|
||||
// Workers Builds (configured in the Cloudflare dashboard) runs
|
||||
// `npx wrangler deploy` on every push to `main`; the "build" section below runs
|
||||
// `npm run build` first. The Worker serves the Vite build from ./dist as static
|
||||
// assets (SPA fallback to index.html) and only runs code for /api/* — today
|
||||
// the Turnstile verification endpoint and a health check.
|
||||
// assets (SPA fallback to index.html). Every request except the hashed bundles
|
||||
// under /assets/ runs the Worker first, which rate limits it per client, then
|
||||
// hands pages to the ASSETS binding or answers /api/* itself (the Turnstile
|
||||
// verification endpoint and a health check).
|
||||
//
|
||||
// Secrets (set in the dashboard, never committed):
|
||||
// TURNSTILE_SECRET — Turnstile widget secret for jsonprism.poli0981.dev
|
||||
@@ -24,15 +26,34 @@
|
||||
"directory": "./dist",
|
||||
"binding": "ASSETS",
|
||||
"not_found_handling": "single-page-application",
|
||||
"run_worker_first": ["/api/*"]
|
||||
// Everything except /assets/* (content-hashed, immutable, the bulk of each
|
||||
// page load) goes through the Worker so it can be rate limited. Requests
|
||||
// that reach the Worker are billed as Worker requests; /assets/* stays free.
|
||||
"run_worker_first": ["/*", "!/assets/*"]
|
||||
},
|
||||
"vars": {
|
||||
// Comma-separated hostnames a Turnstile token may have been issued on.
|
||||
"ALLOWED_HOSTNAMES": "jsonprism.poli0981.dev"
|
||||
},
|
||||
// Per-client throttles (IPv4 address or IPv6 /64), counted per Cloudflare
|
||||
// data centre. Over the limit → 429 with Retry-After: 60. namespace_id must
|
||||
// be unique within the account; previews use the even twins below.
|
||||
"ratelimits": [
|
||||
{
|
||||
// Per-IP throttle for /api/turnstile/verify.
|
||||
// Pages and public files (index.html, theme-init.js, favicon…): about
|
||||
// three per page load, so 40 page loads a minute per client.
|
||||
"name": "SITE_LIMITER",
|
||||
"namespace_id": "4205",
|
||||
"simple": { "limit": 120, "period": 60 }
|
||||
},
|
||||
{
|
||||
// Every /api/* request.
|
||||
"name": "API_LIMITER",
|
||||
"namespace_id": "4203",
|
||||
"simple": { "limit": 60, "period": 60 }
|
||||
},
|
||||
{
|
||||
// /api/turnstile/verify, on top of API_LIMITER.
|
||||
"name": "VERIFY_LIMITER",
|
||||
"namespace_id": "4201",
|
||||
"simple": { "limit": 30, "period": 60 }
|
||||
@@ -40,7 +61,7 @@
|
||||
],
|
||||
// Workers Builds runs `npx wrangler preview` for non-production branches.
|
||||
// Previews inherit no vars or bindings, so they are declared again here:
|
||||
// a separate rate-limit counter, and no hostnames for the human check —
|
||||
// separate rate-limit counters, and no hostnames for the human check —
|
||||
// previews get no TURNSTILE_SECRET either, so the check reports
|
||||
// "unavailable" and lets testers continue. Web Analytics only loads on the
|
||||
// production hostname.
|
||||
@@ -49,6 +70,16 @@
|
||||
"ALLOWED_HOSTNAMES": ""
|
||||
},
|
||||
"ratelimits": [
|
||||
{
|
||||
"name": "SITE_LIMITER",
|
||||
"namespace_id": "4206",
|
||||
"simple": { "limit": 120, "period": 60 }
|
||||
},
|
||||
{
|
||||
"name": "API_LIMITER",
|
||||
"namespace_id": "4204",
|
||||
"simple": { "limit": 60, "period": 60 }
|
||||
},
|
||||
{
|
||||
"name": "VERIFY_LIMITER",
|
||||
"namespace_id": "4202",
|
||||
|
||||
Reference in new issue
Block a user