diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f8275de --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,90 @@ +# Changelog + +Notable changes to poli0981.dev. The site deploys continuously from `main`; tags mark +milestones. Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +Content changes (posts, stories, albums) live in [`poli0981/content`](https://github.com/poli0981/content) +and are not listed here. + +## [2.0.0] — 2026-10-24 + +A platform upgrade, a security pass, a new palette and a rebuilt admin +([#98](https://github.com/poli0981/poli0981-dev/pull/98), +[#99](https://github.com/poli0981/poli0981-dev/pull/99), +[#100](https://github.com/poli0981/poli0981-dev/pull/100)). + +### Security + +- **Turnstile gate bypass fixed** ([#97](https://github.com/poli0981/poli0981-dev/pull/97)): a pass + cookie with a malformed signature made the check throw and the Worker failed open, serving the + real page. Decoding is now total, signatures must be exactly 43 characters, and if deciding or + rendering the gate throws the visitor gets a 503 — never the page behind it. +- Admin: Access tokens older than 24 hours are refused, and `ADMIN_EMAILS` is required (fail + closed). Every admin action is recorded in a KV audit log (90 days). +- The IP denylist is enforced by the Worker entry for every route, pages included (it only + covered on-demand routes), supports CIDR ranges and expiry, and is managed from the admin. +- Request bodies are capped (report 32 KB, gate 8 KB, admin JSON 512 KB, uploads 20 MB) and + every outgoing fetch has a timeout. +- Bug reports go to the private `poli0981/site-reports` repository (the site repo is public); + `@mentions` in reports are neutralised and Discord pings are disabled. +- Widget thumbnails and game icons are mirrored by the cron worker and served from `/ext-img`, so + browsers no longer contact Google or Steam before a visitor clicks; `img-src` is `'self'` only. +- `frame-ancestors 'none'` is now sent as a header (it has no effect in a meta CSP). +- CI installs with `--ignore-scripts` and fails on new install scripts; Dependabot waits three days + before proposing a release; SonarCloud, CodeQL, OSV-Scanner and Snyk run on every PR. + +### Added + +- Light/dark theme that **follows the OS** by default, with a system → light → dark toggle. +- "Glacier Teal" palette (navy and teal) across the site and admin, checked against WCAG AA by + `tests/palette.test.ts`. +- Admin: an overview dashboard, an activity page (audit log + content commits), a security page + (IP denylist, configuration), editor draft autosave with restore, Ctrl/⌘+S, client-side field + validation, a sandboxed preview, media search and usage, parallel uploads, gallery cover picker, + drag-and-drop ordering and album deletion, a "session expired" banner. +- Reader routes for one-shot stories (`/truyen//`). +- `/api/health` reports the running Worker version and the commit it was built from; the 500 page + shows the Cloudflare Ray ID, which matches the structured JSON logs in Workers Logs. +- Test suite on `node:test` (about 200 tests, ~99% line coverage of the TypeScript sources) and a + SonarCloud quality gate. + +### Changed + +- Node 26; TypeScript 7 (`tsc`) for type checking, alongside TypeScript 6 for tools that need its + API; ES2025 target. Astro 7.4, @astrojs/cloudflare 14.4, Wrangler 4.152 and current + dependencies. +- Vietnamese and English pages share one component each (eleven duplicated pages removed). +- The header shows the full navigation from 960 px (it overflowed between 768 and 900 px). +- Workers Builds deploys only `main`; other branches upload preview versions. + +### Fixed + +- The language switch no longer leads to a 404 on posts whose slugs differ between languages. +- The story reader bar no longer hides behind the sticky header. +- Modal dialogs (the bug-report dialog) were stuck in the top-left corner; lists in posts had no + bullets — both caused by Tailwind's preflight. +- Callouts in MDX posts rendered unstyled: Astro left their inline styles out of the page's CSP, so + the browser refused them. The rules moved to the shared prose stylesheet, and the build's CSP + check now verifies every inline `", true], + ["", true], + ["X", false], + ]) { + STYLE.lastIndex = 0; + if (STYLE.test(html) !== shouldMatch) failures.push(`style block: wrong result for ${html}`); + } + for (const [html, shouldMatch] of [ + ['

', true], + ["", true], + ['', false], + ['

', false], + ]) { + STYLE_ATTR.lastIndex = 0; + if (STYLE_ATTR.test(html) !== shouldMatch) + failures.push(`style attribute: wrong result for ${html}`); + } if (failures.length > 0) { console.error("CSP guard SELFTEST FAILED — a matcher is wrong:\n"); for (const failure of failures) console.error(` ${failure}`); @@ -107,6 +130,7 @@ const offenders = []; const withoutCsp = []; let pages = 0; let scripts = 0; +let styles = 0; for (const file of htmlFiles(ROOT)) { const html = readFileSync(file, "utf8"); @@ -128,6 +152,17 @@ for (const file of htmlFiles(ROOT)) { offenders.push({ file, hash, preview: body.trim().slice(0, 80) }); } } + + for (const [, , body] of html.matchAll(STYLE)) { + styles += 1; + const hash = `sha256-${createHash("sha256").update(body, "utf8").digest("base64")}`; + if (!declared.has(hash)) { + offenders.push({ file, hash, preview: ` diff --git a/src/styles/prose.css b/src/styles/prose.css index 6910168..9cccf93 100644 --- a/src/styles/prose.css +++ b/src/styles/prose.css @@ -144,3 +144,52 @@ .prose .token.url { color: var(--muted); } + +/* Callout (src/components/Callout.astro) — used from MDX content, so its rules live here. */ +.callout { + display: flex; + gap: 0.75rem; + padding: 0.9rem 1rem; + border-radius: var(--radius-card); + border: 1px solid var(--line); + background: var(--surface); + font-family: var(--ff-body); + font-size: var(--text-body); +} +.callout-icon { + flex: none; + inline-size: 1.5rem; + block-size: 1.5rem; + display: grid; + place-items: center; + border-radius: 999px; + font-family: var(--ff-mono); + font-weight: 700; + font-size: 0.85rem; + color: var(--bg); +} +.callout-title { + font-weight: 600; + margin-block-end: 0.25rem; +} +.callout-body > * + * { + margin-block-start: 0.5em; +} +.callout.info { + border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); +} +.callout.info .callout-icon { + background: var(--accent); +} +.callout.tip { + border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); +} +.callout.tip .callout-icon { + background: var(--ok); +} +.callout.warn { + border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); +} +.callout.warn .callout-icon { + background: var(--warn); +} diff --git a/tests/widgets-worker.test.ts b/tests/widgets-worker.test.ts index e236bb7..7c14c81 100644 --- a/tests/widgets-worker.test.ts +++ b/tests/widgets-worker.test.ts @@ -72,7 +72,10 @@ function upstream( { type: "PushEvent" }, ]) ); - if (url.startsWith("https://i.ytimg.com/") || url.startsWith("https://media.steampowered.com/")) + if ( + url.startsWith("https://i.ytimg.com/") || + url.startsWith("https://cdn.cloudflare.steamstatic.com/") + ) return overrides.img?.(call) ?? image(); if (url.startsWith("https://discord.example/")) return overrides.discord?.(call) ?? new Response(null, { status: 204 }); @@ -172,9 +175,13 @@ describe("widget sources", () => { assert.ok(calls.some((c) => c.url.includes("key=key%26x"))); // Push, release, release-without-a-tag — WatchEvent skipped, capped at three. assert.deepEqual( - (await fetchGitHub()).map((e) => e.detail), + (await fetchGitHub({})).map((e) => e.detail), ["2 commits", "v1", "release"], ); + const gh = calls.find((c) => c.url.startsWith("https://api.github.com/")); + assert.equal(gh?.headers.get("authorization"), null); + await fetchGitHub({ GITHUB_TOKEN: "ro-token" }); + assert.equal(calls.at(-1)?.headers.get("authorization"), "Bearer ro-token"); assert.ok(kv.store.has(`widgets:img:steam:570:${HASH}`)); }); @@ -197,7 +204,7 @@ describe("widget sources", () => { }); await assert.rejects(fetchYouTube(env(kv)), /youtube 500/); await assert.rejects(fetchSteam(env(kv)), /steam 403/); - await assert.rejects(fetchGitHub(), /github 503/); + await assert.rejects(fetchGitHub({}), /github 503/); }); }); diff --git a/workers/widgets/src/feeds.ts b/workers/widgets/src/feeds.ts index 802480b..4efd8ec 100644 --- a/workers/widgets/src/feeds.ts +++ b/workers/widgets/src/feeds.ts @@ -25,6 +25,12 @@ export interface WidgetsEnv { STEAM_API_KEY: string; STEAM_ID64: string; DISCORD_WEBHOOK_CI?: string; + /** + * Optional, any fine-grained token with no permissions (public data only). Unauthenticated + * the events API allows 60 requests an hour per IP, and Workers share their egress IPs, + * so the GitHub feed goes stale for hours at a time without one. + */ + GITHUB_TOKEN?: string; } const DAY_MS = 24 * 60 * 60 * 1000; @@ -36,9 +42,13 @@ const IMAGE_TTL_SECONDS = 14 * 24 * 60 * 60; const MAX_IMAGE_BYTES = 2 * 1024 * 1024; const IMAGE_TYPES = new Set(["image/jpeg", "image/png", "image/webp"]); -const get = (url: string, accept?: string) => +const get = (url: string, accept?: string, token?: string) => fetch(url, { - headers: { "user-agent": UA, ...(accept ? { accept } : {}) }, + headers: { + "user-agent": UA, + ...(accept ? { accept } : {}), + ...(token ? { authorization: `Bearer ${token}` } : {}), + }, signal: AbortSignal.timeout(TIMEOUT_MS), }); @@ -155,17 +165,20 @@ export async function fetchSteam(env: WidgetsEnv): Promise { return Promise.all( games.map(async ({ iconHash, ...game }) => { if (!iconHash) return game; - const source = `https://media.steampowered.com/steamcommunity/public/images/apps/${game.appid}/${iconHash}.jpg`; + // media.steampowered.com answers Workers with 403; Steam's own Cloudflare CDN serves + // the same file. + const source = `https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/${game.appid}/${iconHash}.jpg`; const ok = await mirrorImage(env.KV, `steam:${game.appid}:${iconHash}`, source); return { ...game, icon: ok ? `/ext-img/steam/${game.appid}/${iconHash}` : "" }; }), ); } -export async function fetchGitHub(): Promise { +export async function fetchGitHub(env: Pick): Promise { const res = await get( "https://api.github.com/users/poli0981/events/public?per_page=10", "application/vnd.github+json", + env.GITHUB_TOKEN, ); if (!res.ok) throw new Error(`github ${res.status}`); return normalizeGitHub((await res.json()) as GhEvent[]); diff --git a/workers/widgets/src/index.ts b/workers/widgets/src/index.ts index d6a0885..fc3ed44 100644 --- a/workers/widgets/src/index.ts +++ b/workers/widgets/src/index.ts @@ -43,7 +43,7 @@ export default { const sources: [Source, string, () => Promise][] = [ ["yt", "widgets:yt", () => fetchYouTube(env)], ["steam", "widgets:steam", () => fetchSteam(env)], - ["gh", "widgets:gh", fetchGitHub], + ["gh", "widgets:gh", () => fetchGitHub(env)], ]; const results = await Promise.all( sources.map(([src, key, fetcher]) => refresh(env.KV, key, src, status, now, fetcher)),