20 Commits
Author SHA1 Message Date
poli0981andClaude Opus 5.5 0240abfd02 docs: the Worker's rate limits count per server, as measured
Measured on production after v4.5.1 deployed (2026-10-27, SIN): over one
keep-alive connection each budget held exactly - /api/no-such-route
121 x 404 then 429 with Retry-After, no-store and CORS; /api/human-check
19 then 429 - while requests on fresh connections, which Cloudflare
spreads over many servers, were never refused (175 human checks in 70 s
against a budget of 20). A probe Worker in a remote preview confirmed the
binding itself enforces (limit 5: 6 allowed, then refused).

So the layer stops browsers and connection-reusing scripts; a client that
reconnects for every request is the WAF rule's, which counted exactly
(250). The docs, CLAUDE.md, the module comment, wrangler.jsonc and the
unpublished v4.5.1 entry said "per location, approximate"; they now say
what was measured. The section 3b check used xargs (fresh connections) and
would have shown no 429 - it now sends everything over one connection.
No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 07:10:29 +07:00
poli0981andClaude Opus 5.5 e167d7df02 docs(security): a WAF check command that actually trips the rule
The section 3a check ran 300 separate curls through xargs -P 30. Each one
pays a TLS handshake, so from here it managed about 21 requests a second -
300 x 200 in 14 s - and never crossed 250 in 10 s: the rule looked broken
when it was not. One `curl --parallel` with its URL list on stdin reuses
its connections and does: 250 x 200 then 150 x 429, measured against the
live site-wide rule on 2026-10-27.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 07:02:52 +07:00
poli0981andClaude Opus 5.5 d8d395b568 feat(worker): per-surface rate limits behind the WAF rule
The zone's one Free-plan rate-limiting rule (IP, 10 s, block 10 s) stays
the first layer: it refuses a burst before the Worker is invoked and is the
only limit on the prerendered pages. The Worker now adds a second one with
the `ratelimits` bindings in wrangler.jsonc, 60-second windows and one
budget per surface, keyed by IPv4 address or IPv6 /64:

  RL_DATA   /api/data/*                             240/min
  RL_IMG    /img/*                                  600/min
  RL_API    /api/activity, /api/updates/desktop, …  120/min
  RL_HUMAN  /api/human-check                         20/min
  RL_ADMIN  /admin, /admin/*, /api/ingest/*         300/min

Checked after the country block and before every route and the Access
check; over a limit the answer is 429 + Retry-After: 60, no-store, with
CORS only where the route itself sends it (data, api). It fails open
(no binding, no CF-Connecting-IP, a throwing limit()) and logs no refusal.
Verified locally under wrangler dev: each budget refused exactly past its
limit, a second /64 address shared the first one's budget, pages were never
counted.

rate-limit.test.ts holds wrangler.jsonc to the code (binding names, period
60 = Retry-After, account-unique namespace ids) and checks that every
run_worker_first prefix draws on a budget. worker-configuration.d.ts gets
the five Env lines (and the IMG_MINT_PER_TICK value it had missed) without
regenerating the runtime types.

docs/SECURITY_SETUP.md section 3 describes both layers and recommends
widening the WAF rule to the whole zone except /_app/immutable/ at 250 per
10 s, counted from the build (a first visit sends 110-130 requests once
the service worker precaches); CLAUDE.md records the rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 06:57:27 +07:00
poli0981andClaude Opus 5.5 0f600a99aa build(web): migrate to SvelteKit 3 and adapter-static 4
@sveltejs/kit 2.70.3 -> 3.1.0, @sveltejs/adapter-static 3.0.10 -> 4.0.0.
Closes GHSA-27mw-82g8-phjj and GHSA-pfhg-q3qv-9q6r (dismissed in v4.4.1
as not applicable), and drops the cookie override kit 2 needed: npm audit
reports nothing.

- Config: svelte.config.js is refused by kit 3. Its options are now
  sveltekitConfig(tauri) in build/sveltekit-config.ts, passed by
  vite.config.ts as sveltekit(sveltekitConfig(IS_TAURI)), with tests for
  both CSP flavours, paths.relative, the sitemap entry and the prerender
  404 handler. The unused, now-deprecated "@" alias and typescript.config
  hook are gone; tsconfig.json extends $app/tsconfig and owns `include`.
- $lib -> #lib (package.json imports), with .js on module imports.
  tsconfig repeats the mapping in `paths`: svelte-check --tsgo only maps
  .svelte imports through `paths`, and without it every #lib component
  fell back to the *.svelte shim (props unchecked; proven with a planted
  error).
- Param matchers: src/params/legaldoc.ts -> src/params.ts (defineParams).
  vite build imports that file with Node's own import(), so it imports
  #lib/legal.ts and legal.ts imports ./schema.ts by their real names.
- PWA: @vite-pwa/sveltekit never supported kit 3 and wrote the worker when
  the SERVER build closed, which kit 3's environment build does first.
  build/pwa.ts wires vite-plugin-pwa in a buildApp hook after kit's
  prerender and before its adapter, with the same globs and URL mapping.
- goto options renamed (replace, reset: false, refreshAll); the /games
  filter write is a shallow goto; a legacy /#/ path that matches no route
  falls back to location.replace (kit 3's goto rejects it). Hook types
  from @sveltejs/kit/hooks; the client handleError returns nothing to keep
  kit's message.
- runed 0.35 (bits-ui) peers kit ^2: overridden to our kit, as for
  echarts-wordcloud.

Verified against a kit 2 build of the same commit: same 11,037 files bar
hashed chunks, same non-immutable precache URLs, navigateFallback "/",
identical CSP per page (hashes masked), manifest and sitemap byte-equal,
same visible text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 14:35:49 +07:00
poli0981andClaude Opus 5.5 e3bf4e6a8d perf(img): serve the minted AVIF from the R2 custom domain, out of Cloudflare's cache
A Worker always runs BEFORE Cloudflare's cache, so no `s-maxage` on /img/*
could ever spare an invocation: every thumbnail and hero view ran the Worker,
and every view the edge cache had not seen read R2. An R2 custom domain is
cached like any origin. On the web, thumbnails and the detail hero now load
from https://media.free-steam-games.win/img/v2/<w>q<q>/<path>@<t>.avif - the
exact key the cron mints - and a repeat view costs neither a Worker run nor an
R2 read.

- shared/img-keys.ts is now the one definition of the key scheme, shared by
  the cron, the /img route and the page (it moved out of worker/lib/img-store.ts).
- Every such <img> carries {@attach imgFallback(...)} with the /img URL. A key
  that is not minted yet is a 404 on the media host and a browser without AVIF
  cannot decode it; both fire `error`, and /img serves Steam's JPEG. A load
  that failed before hydration is recognised by complete && naturalWidth === 0.
  images.test.ts fails on an image without the fallback, or one built from a
  different value.
- An attachment, not an action: on a prerendered <img>, `use:` makes Svelte
  write onload/onerror="this.__e=event", which the hash CSP refuses - one CSP
  violation per game page. verify-dist.mjs now fails on it anywhere.
- The web CSP lists the media host in img-src; the Tauri one does not, and the
  packaged apps keep using /img/* for everything. verify-dist checks both ways.
- The service worker's /img/ rule matched the media host too (same path
  prefix). Its responses are opaque no-cors loads the rule can never cache, so
  it is same-origin only now; the objects' year of immutable Cache-Control is
  what keeps them.
- /img remembers an R2 miss per data centre for one cron tick (15 min), so the
  fallbacks and the apps stop paying an R2 read for art the backfill has not
  reached.

Measured with the domain not yet connected (so every media load fails): the
hero and all 100 thumbnails on /top-online fell back to /img and rendered,
including lazy images below the fold; none broke.

Merge only once media.free-steam-games.win serves a minted AVIF -
docs/SECURITY_SETUP.md section 5 has the setup and the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 00:20:28 +07:00
poli0981andClaude Opus 5.5 ad75d4ff31 docs: bring the docs in line with what shipped on 2026-10-02
- CHANGELOG [Unreleased]: AVIF art minted into R2, the packed catalogue,
  themed and hideable scrollbars, the prerender 404 noise, uncompressed
  shards, the Tailwind scrollbar-thin collision, the thumbnail probe, the
  data-commit redeploy, and the /cdn-cgi/image billing hole.
- SECURITY_SETUP §5: zone Transformations are OFF (every /cdn-cgi/image/
  request answers 404) and the cron kept minting with them off, so the
  Images binding does not need them.
- DEPLOYMENT: shard compression depends on the `ndjson-shards` Compression
  Rule, a dashboard setting; packed files are deliberately not .jsonl.
- CLAUDE.md: the scrollbar rules (scrollbar-slim, never Tailwind's core
  scrollbar-thin; panel/page markers; the stored key), and Transformations
  must stay off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 17:45:46 +07:00
poli0981andClaude Opus 5.5 8aaa010088 fix(img): refuse to be a source for /cdn-cgi/image/ URL transformations
With zone Transformations enabled, the zone itself is always an allowed
source and Sources cannot exclude it. /img/* proxies any Steam appid, so
/cdn-cgi/image/<any options>/img/d2/<appid>/header.jpg let anyone bill a new
transformation per option set, outside IMG_TRANSFORM_MONTHLY_CAP. Measured
in production: width=77 on app 440 answered 200 (cf-resized: internal=ok),
and wrangler tail showed the resizer fetching the source with
`Via: 1.1 image-resizing-proxy` and the caller's own User-Agent.

handleImg now answers 403 to any request whose Via names image-resizing.
The site never transforms by URL: only the cron does, through the Images
binding, from Steam directly, so nothing legitimate is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 17:23:12 +07:00
poli0981andClaude Opus 5.5 42fb8e6250 fix(img): hero AVIF at q80, quality in every key, mint 40 per tick
The first production batch (10 most-played games, 2026-10-02 09:30Z) came
back at the expected sizes - median 40.0 KB JPEG -> 10.9 KB `d`, 3.4 KB `s` -
but Cloudflare's quality scale runs well below libavif's: `d` at q60 scored
SSIM 0.960 against Steam's JPEG (0.937 on Counter-Strike 2 and PUBG), and a
3x crop showed fine background stripes and texture smoothed away. The hero
is enlarged by the browser to up to 768 CSS px, so that softness shows. `s`
(q55, SSIM 0.952) is shown downscaled and stays.

- `d` goes to q80.
- The R2 key and the edge-cache key now carry width AND quality
  (img/v2/460q80/...): an old encoding can never be served for a new one by
  an edge that cached it, and changing one variant's quality re-mints only
  that variant. The v1 objects (the first 10 sources) are simply not read.
- IMG_MINT_PER_TICK 10 -> 40: the backfill finishes in about a day and a
  half, still well inside IMG_TRANSFORM_MONTHLY_CAP.

Docs: SECURITY_SETUP §5 and CLAUDE.md now say /cdn-cgi/image/ must not work
on this zone. With zone Transformations on, "This zone only" still accepts
/img/* as a source, and /img/* proxies any Steam appid, so anyone could bill
transformations with arbitrary options outside the monthly cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 16:39:18 +07:00
poli0981andClaude Opus 5.5 2f883238aa feat(img): AVIF header art minted by the cron into R2, served read-only
/img/* used to pass Steam's JPEG straight through (median 36 KB; every
header is 460x215). Thumbnails and the detail hero are now AVIF for every
browser that accepts it: measured locally, 6.9 KB for the 460 px hero and
2.7 KB for the 230 px thumbnail of Counter-Strike 2, against a 34.3 KB JPEG.

How it is split:
- worker/lib/img-mint.ts (cron, every 15 min) is the ONLY place a billed
  transformation happens. It builds the source list from shards that hash
  to data/index.json (a lagging raw.githubusercontent shard would otherwise
  freeze a stale list under the new generation), most-played first, encodes
  `s` 230 px q55 and `d` 460 px q60 with the Images binding and writes them
  to R2 `f2p-media` under img/v1/<w>/<path>@<t>.avif. The list is kept in a
  marker object, so a backfill does not re-download the shards every tick.
- worker/routes/img.ts only READS: Cache API -> R2 -> Steam's JPEG. No
  request (unknown appid, forged ?t=, HEAD) can create a transformation or
  an R2 object. The old cf.image WebP branch is gone.
- Budget: Images Paid has no spend cap, so IMG_TRANSFORM_MONTHLY_CAP (20,000,
  at most $7.50 against the agreed $15/month) is enforced by an atomic D1
  counter (locks.ts bumpCounter), counted before each call, fail closed.
  Error 9422 stops every isolate until the month turns.

Variants: s/d are negotiated on Accept with Vary: Accept. An AVIF browser
gets the JPEG only as a provisional answer (one day, no X-Img-Final) and the
service worker now caches only X-Img-Final responses, because CacheFirst
ignores Cache-Control. t and d2 stay JPEG: released apps request them and d2
is og:image. Cache keys are normalised, so stray query strings no longer
fork the edge cache, and the t capsule probe no longer runs on hashed paths
where it was two guaranteed 404s.

Client: thumbnails use s, the hero uses d with fetchpriority="high". The
Steam URL parser moves to shared/steam-image.ts so the client, route and
cron cannot disagree. worker-configuration.d.ts regenerated (runtime types
unchanged). Bucket f2p-media already exists (created 2026-10-02).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 15:58:44 +07:00
poli0981andClaude Opus 5.5 a74a004e19 docs: publish role contact addresses and the maintainer's website
contact@ stays the default. Three role aliases go where a reader of that
document will look for them, and nowhere else:

- security@  SECURITY.md, security.txt, SECURITY_SETUP section 8
- privacy@   the Privacy Policy's "Your rights"
- copyright@ LICENSE-DATA (new "If you hold rights" section) and ToS
             section 6, one address for copyright, DMCA and takedown notices

security.txt now lists GitHub's private vulnerability reporting first and
security@ second, in RFC 9116 preference order; the links page is not a
security channel and is dropped from it. The About page gains a Website card
(https://poli0981.dev/), two columns at sm and three from md so the email
handle never truncates. AUTHORS, Contact, CONTRIBUTING and username.txt carry
the full map.

The copyright text promises a human reading, not an outcome: an override
cannot blank a field and the store refresh rewrites description monthly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 23:31:09 +07:00
poli0981andClaude Opus 5.5 fa8b81fd9b docs: the Turnstile check and the Referer fix, and what they made untrue
Legal (both reopen the consent gate for returning visitors, showing only
the changed lines - edited line-locally so that diff stays small):
- PRIVACY_POLICY: a section on the website's Turnstile check - after
  acceptance, at most daily, what challenges.cloudflare.com reads (IP,
  User-Agent, TLS fingerprint, page signals), that Cloudflare is processor
  for the site and controller where it improves its bot detection (the
  Turnstile Privacy Addendum), that the Worker forwards the token and IP
  and keeps neither; the f2p:human_check storage row. "The only third
  party", "the verification step" and "No fingerprinting" are corrected.
- ToS section 9: the check exists; /api/data/*, /img/* and the apps stay
  excluded from both human checks.

SECURITY_SETUP:
- section 10 rewritten. It said the apps survived Hotlink Protection only
  because their webview sent no Referer (untrue since WebView2 started
  sending tauri.localhost), recommended switching the protection off, and
  said no allowlist could express the apps' origin - a Configuration Rule
  on http.referer can. Now: the per-<img> fix and its test, the rule for
  2.0.0 installs, and the check, with the results measured today.
- new section 12: widget settings (hostname, Managed, pre-clearance off),
  the TURNSTILE_SECRET secret and rotation, what the check is not, local
  testing with Cloudflare's test keys, the optional rate-limit expression.
- the CSP block, the script-src/frame-src prose, "no form posts", the
  rule budget (Configuration Rules 1/10), and two stale paths.

CLAUDE.md gains the human-check and <img> invariants and says "after
consent and the human check" where the service worker, analytics and
/welcome used to say "after consent". README, web/README, DEPLOYMENT,
ACKNOWLEDGEMENTs, SECURITY (bypassing the client-side gate is out of
scope), TAURI troubleshooting and the changelog follow. _headers and
worker/lib/http.ts: comments only - why images override Referrer-Policy,
what X-Frame-Options does and does not govern, and the public/_headers
and SITE_ORIGIN references that were stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 21:47:01 +07:00
poli0981andClaude Opus 5 7d0025112b docs: record the WAF rules as live, and replace the React-era dependency list
THE TWO WAF RULES EXIST NOW. `human-check-pages` (Managed Challenge) and
`blocked-countries` (Block) went live 2026-09-20, so SECURITY_SETUP no
longer reads as instructions for something that has not been done. Section
4 says what is deployed and when, and carries what was measured afterwards:
a plain curl with no browser User-Agent is still served `/`, `/games`,
`/legal/tos`, `/.well-known/security.txt`, `/sitemap.xml` and `/robots.txt`,
the challenge rate has stayed at 0%, and a real browser loads a game page,
the service worker and the beacon uninterrupted. Section 9 records the
analytics beacon returning 200 and its reports 204 on the live site, and
that "Enable with JS Snippet installation" is the only mode this CSP can
ever accept. "Still open" now names the Free-plan rule budget - 1/1 rate
limiting, 2/5 custom - because that is the next thing to run out.

THE DEPENDENCY LIST WAS THE REACT APP'S. ACKNOWLEDGEMENTs credited React 18,
react-router, i18next, Zustand, TanStack Query, Radix, shadcn/ui, cmdk,
OpenPGP.js, Tailwind 3, TypeScript 5 and PostCSS - none of which has
shipped since the v4 rewrite - while omitting Svelte, SvelteKit, Bits UI,
unified and the typefaces that actually do. Rewritten from package.json and
Cargo.toml, with every licence read out of node_modules rather than
remembered: echarts-wordcloud is ISC, not BSD-3-Clause. The claim that
/about carries a "full SPDX list" is gone; it is a curated subset and says
so now.

THIRD_PARTY.md gains svelte-check and vitest, which the pre-publish suite
has been running unlisted, and drops "the TypeScript SPA".

web/README.md documents the two analytics CSP hosts, why automatic
injection can never be used, the navigateFallback fix, and the consent
hashing and diff mechanism - none of which existed when its CSP and PWA
sections were written. Its file tree lists the four new modules.

DEPLOYMENT.md records that a zero-duration "Workers Builds" failure on a PR
branch is a preview-build artefact: it happened twice on PR #130 while the
identical commits deployed from main minutes later, and the GitHub Actions
`check` job already runs the same build, verify-dist and wrangler dry-run.

Also fixes a pre-existing broken curl snippet in section 10, whose
`%{http_code}\n` had been saved with a literal newline in it.

The dead relative links the link checker finds in CHANGELOG.md are left
alone: they are in released sections and name files that existed at the
time. A changelog is a record, not documentation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 20:21:58 +07:00
poli0981andClaude Opus 5 5dfd9dd36e docs: analytics, the two WAF rules, and the claims they made false
The privacy policy said the site had no analytics, set no cookies, loaded
nothing from a third party and did not have Cloudflare Web Analytics
enabled. Three of those were already shaky and all four had to change, so
this rewrites the affected sections rather than bolting a paragraph on:
what the beacon does and does not do, why it waits for consent, the
human-verification step, and where the site is no longer served. ToS gains
section 9, which did not exist - there was no availability or automated-
access clause at all.

SECURITY_SETUP section 9 is reversed. It recommended turning Web Analytics
OFF; it now records why the automatic mode can never work under a
hash-based CSP, so nobody re-enables it, and what the JS-snippet setup is.
Section 4 keeps "leave Bot Fight Mode off" and adds the two custom rules
that are safe here, each exclusion annotated with what breaks without it,
plus the country block with its real costs: Yandex indexing ends, the
packaged apps stop working there, VPNs evade it trivially.

The verification command for the country block is deliberately NOT the
obvious one. `-H 'CF-IPCountry: CN'` proves nothing: geo.ts reads
request.cf.country first, which cannot be spoofed, and Cloudflare
overwrites that header on ingress. The doc gives the two checks that do
prove something, including the local one whose expected result is 403 on
every Worker route AND 200 on / - which is the whole argument for the WAF
rule.

Also corrected: the CSP transcribed in section 1 was missing both new hosts
and still listed a frame-ancestors this policy has never carried (it is
ignored in a meta CSP; X-Frame-Options covers it).

CLAUDE.md gains four standing rules - the navigateFallback invariant, the
two web-only CSP hosts and why automatic injection is impossible,
per-document consent hashing and why it lives outside prefs.svelte.ts, and
BLOCKED_COUNTRIES being defence in depth rather than the boundary.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 20:01:28 +07:00
poli0981andClaude Opus 5 0a4c5013c5 fix(admin): serve the admin API under /admin, in the page's Access app
/admin reported "Your Cloudflare Access session has expired" straight after
signing in, in a private window too. The page and its API were two Cloudflare
Access applications: /admin (AUD ca93...) and /api/admin (AUD a15d..., read
from the kid= of each login redirect). Access issues its session cookie per
application and fetch() cannot follow the sign-in redirect, so the session
for /admin never reached the API. Every call came back as an opaque redirect,
which api.ts correctly reads as an expired session, and a reload only renewed
the page's session. The Worker never answers 401/403 on these routes, so the
redirect could only have come from the edge.

The API now lives at /admin/api/*, under the page's own application:
ADMIN_API_PREFIX in shared/admin-routes.ts, used by the router, both
handlers, the SPA's api() (views pass routes like "queue?...") and the mock
backend. /api/admin/* is no longer served, and its AUD leaves
ACCESS_AUD_ADMIN.

Every existing test called the handlers directly, so none could see this.
worker/index.test.ts drives the real router and Access check with a signed
RS256 token: a reviewer reaches /admin/api/*, a write still needs the header
rather than the cookie alone, another application's token and the old prefix
both get 404. security.test.ts keeps the prefix under /admin and API paths
out of the views. Verified in preview:admin under the production CSP: queue,
stats, me, health and the ping write all answer from /admin/api/*.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 11:38:30 +07:00
poli0981andClaude Opus 5 1b10b33a40 docs: describe v4.0.0 as it is - README, web README, Tauri, security, changelog
- README: SvelteKit rather than React, Cloudflare rather than GitHub Pages, a
  resizable self-updating desktop app, the /admin review queue, the real
  workflow list, and no in-browser editing or GPG signing (removed in
  September).
- web/README.md: the admin app, verified shard generations, prerendered game
  pages, the service worker as it is now, and the checks CI runs.
- TAURI.md: the update feed at /api/updates/desktop (drafts are never offered),
  settings surviving updates, the Android update check; the OAuth note is gone
  with sign-in.
- dev_env (en, vi), CONTRIBUTING, android-support (en, vi): tests exist now,
  and the web side is Svelte.
- SECURITY_SETUP: the admin shell's nonce policy, and the report-only CSP that
  Cloudflare's Continuous script monitoring adds at the edge (turn it off).
- CLAUDE.md: where old /#/ links still come from and why the upgrade uses
  goto; /api/activity sends CORS too.
- CHANGELOG [v4.0.0]: the admin app, verified data, a page per game, the
  installable web app, the desktop updater, the new pages, and the live-site
  fixes. Deploying needs D1 migration 0002.
- Code comments that still described React, GitHub Pages, hash routing or a
  sign-in token.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 23:13:17 +07:00
poli0981andClaude Opus 5 85f1a97f39 fix(web): CSP that lets the app hydrate, the PWA, and two unported modules
Four regressions the port had introduced, all found by looking at the running
app and at knip rather than by assuming the migration was complete.

## The app did not hydrate at all

SvelteKit emits exactly one inline <script> per page - the hydration bootstrap
- and offers no way to avoid it. Under _headers' `script-src 'self'` the
browser blocked it, so every page rendered its prerendered HTML and then sat
there completely inert. Measured in a real browser, on every route:

  Executing inline script violates ... directive 'script-src 'self''

The CSP now lives in svelte.config.js under kit.csp with mode "hash", so
SvelteKit computes that script's sha256 at build time and emits the whole
policy as a <meta> tag that already trusts it.

The header CSP had to GO, not relax: browsers enforce the INTERSECTION of a
header policy and a meta policy, so leaving `script-src 'self'` in _headers
would have kept blocking the script whatever the meta allowed. One directive
is lost in the move - `frame-ancestors` is ignored in a meta CSP - so
X-Frame-Options: DENY in _headers is now load-bearing rather than
belt-and-braces.

Verified after: hydration confirmed by 26 virtualised rows existing (they only
exist if the client ran), both fonts reporting "loaded", and a fresh tab
walking /about and /charts/genres with ZERO console messages. The font
"preloaded but not used" warnings were a symptom of the same thing and are
gone with it.

## The PWA was simply missing

@vite-pwa/sveltekit was installed and never configured, so the build emitted no
service worker at all - no offline support and no update flow, both of which
the React app had. Configured with the runtime caching carried over verbatim,
including the reasons: NetworkFirst for /api/data/* because index.json carries
last_updated and serving THAT from cache strands every reader on stale records,
and the navigateFallbackDenylist because an installed SW answering /admin from
the app shell would serve the public shell where the Access gate is expected.

## Two modules ported but never wired up

- external-link-interceptor: the Tauri webview blocks window.open() and
  target="_blank" to external http(s), so without it every external <a> in the
  packaged builds dead-clicks.
- android-update: Android has no native Tauri updater (the plugin is
  desktop-only), so the APK checks GitHub Releases itself. Both packaged apps
  had silently lost a feature.

## knip was blind to the whole UI

Its project globs were still {ts,tsx} from the React era, so after the
migration it could not see a single .svelte file and reported the entire UI
dependency tree as unused. Fixing that is what surfaced the three items above,
plus two primitives I wrote and never used. No unused files or dependencies
remain.

CLAUDE.md updated: six of its notes described a React app that no longer
exists, which is worse than no note - an agent reading it would go looking for
files that are gone. It now records the four traps this change cost:
the CSP-must-not-be-in-two-places rule, adapter-static's fallback overwriting
index.html, nothing gating markup behind onMount, and $state being required for
a value an $effect must react to.

check / test / build / knip clean. 46 tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 14:04:33 +07:00
poli0981andClaude Opus 5 369cc776d0 feat(web): app shell, data layer and first pages on SvelteKit
The shell runs end to end against real data: consent gate, sidebar, topbar,
command palette, theme switching, i18n, the catalogue load, and a rendering
ECharts chart. Verified in a browser at 1440x900 and at mobile width.

## Data layer, without TanStack Query

lib/resource.svelte.ts is ~90 lines of runes replacing @tanstack/react-query.
What the app used from that library was isLoading/error/data/refetch, a stale
time and one refetchOnWindowFocus. Caching is deliberately NOT reimplemented:
the catalogue's real cache is IndexedDB keyed on index.json.last_updated, the
only invalidation signal this dataset has, and a memory cache on top would be a
second thing to get wrong. The three-step load (read cache, compare
last_updated, else fetch shards and parse in a worker) is carried over exactly.

## i18n gaps closed rather than carried forward

The plan listed eleven categories of hardcoded English inside an otherwise
translated app. Fixed so far:

- The seven KPI labels, which lived as string literals in KpiCards.tsx.
- formatRelativeDate, which returned "today" / "3d ago" / "2w ago" regardless
  of locale. Now Intl.RelativeTimeFormat, which also handles pluralisation -
  the part a template string per language cannot do.
- formatNumber, which hardcoded toLocaleString("en-US"), so a Vietnamese
  reader saw 1,234,567 where their locale groups as 1.234.567.
- The command palette, whose 17 labels were the only untranslated strings in
  the app. It is now built from the nav lists instead of its own array - which
  had already drifted, missing /top-offline, /donate,
  /charts/anti-cheat/list, /charts/delisted and /welcome.

en.json and vi.json go 353 -> 392 keys, edited together by script with the leaf
sets asserted equal, because hand-editing one is how they stop matching.

## Things fixed on the way through

- Ctrl-K now checks e.isComposing. Without it the shortcut fires mid-IME
  composition and steals the keystroke, which made the palette actively
  hostile to Vietnamese input - the locale it exists for.
- The theme "system" option now listens for prefers-color-scheme changes. The
  React Topbar read matchMedia once and never subscribed, so "system" never
  actually reacted.
- The Toaster took the resolved theme instead of a hardcoded "dark", which had
  put a dark toast on a white page in light mode.
- The sidebar version is derived from __APP_VERSION__; it said "Steam · v1.0"
  while package.json was 1.4.5.
- Distinct icons per nav row: Trophy was used for BOTH leaderboards and Shield
  for two anti-cheat entries, which makes an icon useless for finding a row.
- legal.ts said "The 5 binding documents"; the licence split made it six.
- /legal/<slug> links are real links now. Welcome.tsx built that exact href
  and then called preventDefault() to bounce to /about, because nothing was
  there to receive it.

## Two bugs found by looking, not by guessing

**The chart rendered nothing.** ECharts initialised and created its container
but painted no canvas - which looks exactly like the unregistered-theme
failure CLAUDE.md warns about. It was not that: `chart` was a plain `let`, so
the setOption effect ran once while it was still undefined and never re-ran
when init assigned it. Making it $state fixed it, and the comment now names
both failure modes so the next person does not misdiagnose it the same way.

**Cloudflare Hotlink Protection is ON and the packaged apps survive it by
luck.** Every /img/* request from the dev server came back 403, body
`error code: 1011`. Measured against the live zone: no Referer 200, own-origin
Referer 200, but `http://localhost:5173/` 403, `tauri://localhost/` 403 and
`http://tauri.localhost/` 403 - the two origins the desktop and Android builds
actually load images from. They render today only because the Tauri webview
sends no Referer for <img>, which is not a guarantee anyone made: a WebView
update doing the ordinary spec-compliant thing would blank every image in both
apps with no change on our side. Written up as SECURITY_SETUP.md section 10
with the measurements and a recommendation to turn it off - it restricts
nothing that worker/routes/img.ts's anchored PATH_RE and host allowlist do not
already restrict, and Referer is client-set anyway.

## Still to port

The games table, nine of the eleven chart pages, about/settings/health/
activity/donate, /legal/[doc], and the four new surfaces (/stats,
/developers, /publishers, /games/[appid]). The foundation they all sit on -
routing, data, i18n, theming, charts, consent - is proven working.

check / test / build all clean; the 39 Worker tests are untouched by this.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 13:17:27 +07:00
poli0981andClaude Opus 5 3525554eb6 feat(worker): proxy GitHub avatars and the commit feed, add security.txt
Fixes two of the five reported console errors, and narrows the site CSP to
connect-src 'self' as a consequence.

## The avatar error

  Loading the image 'https://avatars.githubusercontent.com/in/15368?v=4'
  violates the following Content Security Policy directive: "img-src ..."

Activity.tsx rendered commit.author.avatar_url straight from the GitHub API.
avatars.githubusercontent.com appears in NONE of this repo's four CSPs
(_headers, admin-ui, edit-ui, tauri.conf.json), so every avatar on /activity
was blocked - in the browser and in both packaged apps. `in/15368` is the
pipeline's GitHub App; verified live, the page requests exactly three avatars
(in/15368, in/29110, u/127664709).

Widening img-src was the smaller diff and the wrong call: it puts a
third-party host back in the page and hands every visitor's IP to GitHub,
which PRIVACY_POLICY.md says does not happen. Instead /img/gh/{u|in}/{id}
proxies them, reusing the existing /img/ prefix so run_worker_first and the
service-worker CacheFirst rule both needed no change. Anchored regex, digits
only, fixed 56px size (a caller-chosen size is unbounded cache keys).

## /api/activity

The commits fetch was the last third-party request the public app made. It now
goes through the Worker, which also lets connect-src drop to 'self'.

Two things the proxy deliberately drops, both found by reading live output:

- commit.author.email, which GitHub returns for every commit and the page
  never used. Forwarding it would make this a bulk email-harvesting endpoint
  for everyone who has ever contributed.
- the commit message BODY. Only the subject line is rendered, and the bodies
  here carry Co-Authored-By trailers with real addresses - the first version
  of this route shipped them to every visitor from a publicly edge-cached
  response. Sending the subject only also cut the payload 98,203 -> 30,324
  bytes.

Edge-cached 5 minutes, keyed on the path alone so `?x=1` cannot mint cache
entries and walk past that. This bounds upstream traffic to ~12 calls/hour
against GitHub's anonymous budget of 60/hour, which a pass-through would
exhaust immediately since a Worker egresses from a shared address. It is NOT
authenticated: the GitHub App token is a repo-write credential and has no
business on a public route. Carries ACAO: * for the same reason /api/data/*
does - the Tauri builds read it cross-origin from tauri://localhost.

## security.txt

web/public/.well-known/security.txt (RFC 9116). It had to be a real file:
not_found_handling is "single-page-application", so a request for it returned
dist/index.html at HTTP 200 and scanners got a web page with no error.
Verified it now returns text/plain. Expires 2027-09-01; renewal is logged as a
recurring task in SECURITY_SETUP.md.

## Header gaps found while in here

- worker/index.ts's unauthenticated /admin 404 shipped NO security headers -
  it was the one response built by hand instead of through jsonError. It now
  uses withSecurityHeaders(), which was exported and never called.
- admin-ui.ts and edit-ui.ts contained byte-identical copies of the CSP for
  the only origin holding a repository-write credential. Extracted to
  adminCsp()/adminHtmlResponse() in lib/http.ts; a hardening change applied to
  one copy and not the other is invisible. Adds an explicit object-src and the
  Cross-Origin-Opener-Policy the SPA had and these pages did not.
- SITE_ORIGIN was duplicated in fetcher.ts and image.ts with the same comment.
  A third caller made lib/site.ts the right shape.

## Two things the maintainer must do, both dashboard-only

Recorded in SECURITY_SETUP.md sections 2 and 9:

- HSTS preload: the header already carries `preload` and the domain passes
  hstspreload.org's preloadable check with {"errors": [], "warnings": []},
  port 80 301s to HTTPS. Status is still "unknown" = not submitted. Submission
  is irreversible on any useful timescale, so it is yours to make.
- Cloudflare Web Analytics is ON and injecting static.cloudflareinsights.com's
  beacon at the edge, which our own script-src 'self' blocks - two CSP errors
  on every page load of the live site, and analytics that have never collected
  anything. Not in the repo; curl of the deployed HTML shows no such tag.
  Recommend turning it off rather than allowlisting, since the privacy policy
  promises no third-party resources.

Verified against a local `wrangler dev`: avatars 200 through the proxy, all
malformed avatar paths 404, Steam variants unaffected, /api/activity
unauthenticated and 200, /api/data CORS intact, /admin 404 now carrying
headers, and zero requests to any GitHub host from the browser. typecheck,
build, wrangler --dry-run and knip all pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 12:10:52 +07:00
poli0981andClaude Opus 5 bc625f285e docs(security): correct rate limiting and Bot Fight Mode for the Free plan
The setup guide recommended two rate-limiting rules at one minute each with
Managed Challenge. The Free plan allows exactly ONE rule and fixes most of it:
IP counting only, a 10-second period, a 10-second timeout, path and
verified-bot fields only, cached requests counted. Rewritten as the single rule
this site should have: /img/* and /api/data/* together, 150 requests per 10
seconds, Block, verified bots excluded. Block is tolerable precisely because
the Free timeout is fixed at 10 seconds — a false positive costs ten seconds of
missing thumbnails, not a lockout.

It also said to turn Bot Fight Mode on. That was wrong for this site.
Cloudflare documents that it "may challenge API or mobile app traffic" and that
it cannot be bypassed with WAF custom rules or Page Rules. The desktop and
Android apps fetch /api/data/* with plain fetch() and the discovery workflow
calls /api/ingest/* from GitHub Actions — a challenge page would break both,
with no way to exempt them short of allowlisting GitHub's runner ranges. The
guide now says to leave it off, and why.

HSTS: the guide and web/public/_headers now say where it comes from. It is set
by the Cloudflare zone and stamps every response, static and Worker alike,
verified live on /, /api/data/* and /assets/*. It is deliberately not repeated
in code, which would risk a second Strict-Transport-Security header — browsers
honour only the first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 07:25:16 +07:00
poli0981andClaude Opus 5 3b4ece183c feat(security): CSP and hardening headers, plus a verifiable setup guide
The site had NO Content-Security-Policy. Static assets carried only HSTS (added
by Cloudflare at the edge) and X-Content-Type-Options; Worker responses carried
three headers. That is the gap this closes.

web/public/_headers covers static assets, worker/lib/http.ts covers everything
the Worker generates, and neither inherits from the other — a header that must
hold everywhere has to be added twice. Said so in both files.

The CSP was VERIFIED, not assumed: built the app, served it under the policy,
and walked /games, four chart pages, /about and /health. Zero console errors,
zero violations, images and lazy chunks all loading.

Two directives are shaped by measurement:

- style-src needs 'unsafe-inline'. Radix positions popovers and dialogs with
  inline style attributes and ECharts sizes its canvas the same way — /games
  alone renders 471 inline-styled elements. It is the acceptable half of the
  trade: no user-supplied HTML is ever rendered, and script-src stays strict,
  which is the directive that actually stops execution.
- script-src 'self' is safe despite an inline <script> in index.html: it is
  type="application/ld+json", a data block that is never executed, so
  script-src does not govern it. Checked the BUILT output, not the source.

Cross-Origin-Resource-Policy is deliberately static-only. Setting it on Worker
responses would have broken the Tauri desktop and Android builds, which run on
tauri://localhost and fetch /api/data/* and /img/* from this origin cross-site
(SITE_ORIGIN in src/lib/fetcher.ts and src/lib/image.ts) — every image blank,
catalogue never loading. Caught before shipping; the reason is in the code.

docs/SECURITY_SETUP.md documents what remains, each item with a command to
check it, because a setting you believe is on and is not is worse than one you
know is off. Two findings in it are worth surfacing here:

- HSTS is already max-age=31536000; includeSubDomains; preload — the maximum.
  The domain is NOT on the preload list (hstspreload.org status: "unknown"),
  but the list accepts submissions from ANYBODY for a domain whose header
  advertises `preload`. Leaving the directive in means a third party can put
  the domain on a list that takes months and a browser-vendor process to leave.
  Either submit deliberately or drop the directive.
- Rate limiting belongs in a WAF rule, not in the Worker. A dashboard rule
  rejects at the edge before the Worker runs; a Worker-side limiter has already
  paid for the request by the time it says no, which is backwards for cost
  control. Thresholds given (600/min for /img/*, 120/min for /api/data/*) are
  derived from a measured session — /games issues index.json + 5 shards + ~30
  thumbnails in one burst — not from a template.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-11 00:41:20 +07:00