* chore: add .gitattributes so working trees are LF on every OS core.autocrlf=true (the Windows default) checked 144 text files out as CRLF, which made `prettier --check` and `gen-notices --check` fail locally while CI on Linux passed. The index was already LF, so this changes no content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * build: Node 26, TypeScript 7 next to TS6, ES2025, latest dependencies - Node 26 (.nvmrc, engines); Workers Builds already builds with NODE_VERSION=26. - TypeScript 7.0 ships no JS API, so the tools that need one (astro check/Volar, typescript-eslint, svelte2tsx) keep the real typescript@6 package, while @typescript/native (npm:typescript@7) type-checks every .ts file: `npm run typecheck`. Called by path so the outcome never depends on which package wins the shared `tsc` bin link. - tsconfig: target/lib ES2025, no baseUrl (removed in TS 7; Astro's alias plugin falls back to the tsconfig directory), explicit `types: ["node"]` (TS 6+ default is []), and erasableSyntaxOnly so Node can strip types for the unit tests — which meant turning three constructor parameter properties into plain fields. - Dependencies to current: astro 7.4.2, @astrojs/cloudflare 14.4.2, mdx 8.1.1, svelte 9.1.1, check 0.9.12, zod 4.6.7 (GHSA-mrhx-c7xc-m3w5), wrangler 4.152.0, eslint 10.13, typescript-eslint 8.72 (the Svelte false positives that pinned 8.70 are gone), knip 6.42, lefthook 2.2, prettier 3.9.10, satori 0.63. - Override miniflare's pinned undici to ^7.30.1 (GHSA-xjj6-f33q-929c and two more, published 2026-10-23). `npm audit`: 0 vulnerabilities. - ESLint: defineConfig from eslint/config (tseslint.config is deprecated). - wrangler.jsonc: compatibility date 2026-10-15, version_metadata binding, Workers Logs with invocation logs and redacted query strings, sampled traces, REPORT_REPO. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ci: SonarCloud analysis, no npx or install scripts in CI, Dependabot-proof notices - New `sonarcloud` job (SonarSource/sonarqube-scan-action v8.3.0, pinned) fed with the lcov report from the build job; sonar-project.properties carries the whole setup and waits for the quality gate. Skipped where SONAR_TOKEN can't exist (Dependabot, forks) and for content/bump dispatches. - `npm ci --ignore-scripts`: esbuild, workerd and sharp take their binaries from optionalDependencies, so CI needs no lifecycle script at all (verified with a clean install + full build). Every `npx` became an npm script, and the TS 7 compiler gets its own step. Jobs have timeouts. - Lighthouse runs through treosh/lighthouse-ci-action (pinned) instead of fetching @lhci/cli with npx at run time, and measures mobile as docs 14 says (it was desktop). - gen-notices no longer prints the resolved-package count inside the checked block: every Dependabot PR that changed one transitive package failed CI on it (PR #94). - Dependabot: a 3-day cooldown on both ecosystems, a typescript group, the TS 6 pin explained, and the typescript-eslint pin dropped (8.72 lints Svelte cleanly). - osv-scanner-action v2.7.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(edge): denylist on every route, a gate that fails closed, /ext-img, version reporting - IP denylist moved from the middleware (on-demand routes only — pages were never covered) into the worker entry, for every route. One `denylist` KV key with CIDR ranges and expiry (lib/denylist), memoized per isolate for a minute, failing open on KV errors. - The Turnstile gate fails CLOSED: if deciding or rendering it throws, the visitor gets a 503, never the page behind it. Pass signatures must be exactly 43 characters. - frame-ancestors 'none' as a header-only CSP (it cannot work from <meta>); appended, so /media's and /ext-img's own sandbox CSP stays. Admin responses add CORP same-origin. - /ext-img: the widgets' YouTube thumbnails and Steam icons are mirrored into KV by the cron worker and served from this origin, so a page never contacts Google or Steam before the visitor presses play; img-src is back to 'self' data:. The route only reads KV — nothing a visitor sends makes the Worker fetch anything. - /api/health reports the Worker version (version_metadata) and the git commit it was built from (Workers Builds' WORKERS_CI_COMMIT_SHA), so a deploy is verifiable from outside. Structured JSON logs (lib/log) for denylist, gate, admin and rate limits. - Middleware error pages keep their status under `astro dev` (a rewrite used to answer 200). - Widgets cron: parallel sources, 10 s timeouts, per-source error logs, the KV contract in one shared types module, its bindings typed locally (WidgetsEnv). - gate.js: Turnstile follows the theme actually shown (system preference included). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(api): bounded bodies, timeouts, server-side validation, private bug reports - Request bodies are refused by Content-Length before anything is buffered, and streamed bodies stop at the limit (lib/body): report 32 KB, gate 8 KB, admin JSON 512 KB, upload 20 MB. The old code read the whole body first, whatever its size. - Every outbound fetch has a timeout: GitHub (admin, 15 s), GitHub issues and Discord (10 s). - /api/report files into REPORT_REPO — the private poli0981/site-reports, as the privacy policy always said — breaks @mentions, fences the console log so it can't escape its code block, sends allowed_mentions: none to Discord, and no longer echoes the issue URL. - Admin content API: frontmatter validated against the collection's fields (the same validateFrontmatter the editor will use), plain objects only, JSON content type required, "already exists" instead of a misleading edit conflict when creating, and legal / now / album entries can no longer be deleted from the admin. - Admin gallery and media APIs: the same JSON/size rules, existing-album check on create, oversized uploads refused before formData() parses them. - Publish status says when the content token is doing the dispatching (no publish token). - Structured logs for saves, deletes, uploads, publishes and every GitHub failure. - Admin client: specific messages for the new error codes; a failed Turnstile load is retried instead of replayed until reload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: SonarCloud findings, two checks that passed without checking, RepoLens link Checks that silently checked nothing: - check-exif handed exifr file paths; its reader throws on current Node and the old `.catch(() => null)` read that as "no EXIF" — CI never inspected a single image. It now reads the bytes itself, fails on unreadable images, honours --changed (it ignored the flag) and stops git from octal-quoting Vietnamese file names out of its filter. - check-csp-hashes skipped any page whose CSP meta it failed to parse and reported "ok — 0 pages". The meta tag is now found in any attribute order or quoting (self-tested), a page without one fails, and zero checked pages fails. SonarCloud (29 open issues): - Six super-linear regexes rewritten linearly (format, bugbuffer, access, cookie, new-post); the email mask works token by token. - smoke-worker runs wrangler via process.execPath + its CLI file (no PATH lookup, and it finally works on Windows: no `npx` without a shell, taskkill instead of a POSIX process group), sends `%2e%2e` raw instead of letting fetch normalize it, has a deadline, and covers /ext-img, frame-ancestors, oversized bodies, malformed gate passes and the denylist (a third phase). KV seeding names the namespace, as wrangler 4.152 requires. - strip-exif only walks src/assets (path traversal), recurses, and actually enforces its 1.5 MB budget; sw.js keeps the worker alive until cache.put settles and caps the warm cache; gate.js rejects with Errors; the mini-game draws obstacles from the CSPRNG. - new check-install-scripts: CI installs with --ignore-scripts, which also switches off npm's own strict-allow-scripts — this keeps the "unreviewed install script" alarm. - gen-og imports ogKey() from src/lib/og.ts instead of keeping a copy in sync by hand; new-post parses flags anywhere and escapes titles for YAML properly. Also: the "all repositories" link now points at https://repolens.poli0981.dev/repos. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: run the TypeScript sources under node:test with Astro/Workers stand-ins No new dependencies. tests/support/register.mjs installs Node 26 module hooks: - `@/…` and extensionless/directory imports resolve to the .ts sources; - astro:env/*, astro:content, astro:middleware, cloudflare:workers and the Cloudflare adapter's handler resolve to small stubs whose values tests change at run time; - `import.meta.env` / `import.meta.glob` are rewritten to same-length globals, so V8 coverage still maps character for character onto the files on disk. tests/support/fakes.ts provides KV, R2, Images, the Cache API, ASSETS, rate limiters, a minimal HTMLRewriter and a fetch router; tests/support/github.ts an in-memory content repo speaking REST, Git Data and GraphQL. 162 tests across the worker entry, middleware, every API route, the admin libraries (including real RS256 Access JWTs), media, gate rendering, content queries, RSS, the client modules and the widgets cron: 99.5% of lines, 94.6% of branches. Writing them found the middleware's error pages losing their status under `astro dev`. The frontmatter round-trip test used to skip itself on Windows (`URL.pathname` → "/E:/…"). `npm run test:coverage` writes coverage/lcov.info (80% line floor) for SonarCloud, with the same exclusions as sonar-project.properties, which now also analyzes .github, versions the project, and waits for the quality gate on pull requests only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(content): publish 9265c94 — legal pages for this release Private bug reports, widget images served by the site, Workers Logs and IP blocks disclosed, the AI disclosure's merge policy, and the full third-party/service list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: match script end tags loosely in the HTMLRewriter fake CodeQL (js/bad-tag-filter) flagged the fake's script regexes because they miss end tags such as `</script >` or `</SCRIPT>`. The fake only rewrites HTML this repo builds, but there is no reason to keep a pattern the analyzer rightly calls fragile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: cut script elements by offset in the HTMLRewriter fake The looser end-tag regex did not satisfy CodeQL's js/bad-tag-filter, which distrusts any regex that matches whole <script>…</script> elements. The fake now finds each element with indexOf and checks the opening tag's attributes, so there is no tag-filtering regex left to flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
// src/lib/gate/render.ts: the gate page is the requested page with its <body> swapped out.
|
|
import assert from "node:assert/strict";
|
|
import { before, describe, it } from "node:test";
|
|
import { installHTMLRewriter } from "./support/fakes.ts";
|
|
import { renderGate } from "../src/lib/gate/render.ts";
|
|
|
|
const page = (lang: string) =>
|
|
new Response(
|
|
`<!doctype html><html lang="${lang}"><head><title>Real title</title>` +
|
|
`<meta name="description" content="desc">` +
|
|
`<script src="/_astro/island.js"></script>` +
|
|
`<link rel="modulepreload" href="/_astro/chunk.js">` +
|
|
`<script type="application/ld+json">{"answer":"secret"}</script>` +
|
|
`</head><body><main>full article text</main></body></html>`,
|
|
{
|
|
headers: {
|
|
"content-type": "text/html",
|
|
etag: '"abc"',
|
|
"last-modified": "x",
|
|
"content-length": "1",
|
|
},
|
|
},
|
|
);
|
|
|
|
before(installHTMLRewriter);
|
|
|
|
describe("gate page", () => {
|
|
it("keeps the <head> metadata, drops scripts and JSON-LD, swaps the body", async () => {
|
|
const response = renderGate(page("vi"));
|
|
const html = await response.text();
|
|
assert.match(html, /<title>Real title<\/title>/);
|
|
assert.match(html, /name="description"/);
|
|
assert.doesNotMatch(html, /island\.js|modulepreload|ld\+json|full article text/);
|
|
assert.match(html, /data-human-check/);
|
|
assert.match(html, /Xác minh bạn là người/);
|
|
assert.match(html, /href="\/legal\/privacy\/"/);
|
|
assert.match(html, /<script src="\/gate\.js" defer><\/script>/);
|
|
});
|
|
|
|
it("speaks the page's language and is never cached or indexed", async () => {
|
|
const response = renderGate(page("en"));
|
|
const html = await response.text();
|
|
assert.match(html, /href="\/en\/legal\/privacy\/"/);
|
|
assert.match(html, /data-lang="en"/);
|
|
assert.equal(response.status, 200);
|
|
assert.equal(response.headers.get("cache-control"), "no-store, private");
|
|
assert.equal(response.headers.get("x-robots-tag"), "noindex");
|
|
for (const header of ["etag", "last-modified", "content-length"]) {
|
|
assert.equal(response.headers.get(header), null, header);
|
|
}
|
|
assert.equal(response.headers.get("x-frame-options"), "DENY");
|
|
});
|
|
});
|