ci: Qodana analysis and a licence check over the whole dependency tree (#135)
* ci: Qodana analysis and a licence check over the whole dependency tree - Qodana (JetBrains, Qodana for JS) runs on every PR, on main and by hand (.github/workflows/qodana.yml, settings in qodana.yaml): native mode on the runner's Node 26 after `npm ci --ignore-scripts` and the generated types, profile qodana.recommended over the whole repository, build output, generated files, the content submodule and the design docs excluded, spelling/grammar checks off (they do not read Vietnamese). Results go to Qodana Cloud and, for main, to code scanning as SARIF. Dependabot and fork PRs skip it (no secrets), so it stays advisory. - Licences: the allowlist moves to scripts/license-policy.mjs, shared by gen-notices (direct dependencies, THIRD-PARTY-NOTICES.md) and a new check-licenses step in the build job that reads every package in package-lock.json — transitive ones and every platform binary — with a small SPDX evaluator (OR, AND, WITH, parentheses). Packages with no licence fail; reviews are per package with a reason instead of per licence (an MPL note written for satori used to clear @axe-core/playwright too). Today: 735 packages, 42 cleared (MPL-2.0 build/test tools, sharp's LGPL libvips). - README badges and Quality row, THIRD-PARTY-NOTICES tool list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: Qodana's first findings, and a zero-problem quality gate The first Qodana run reported 11 problems; all are handled: - scripts/smoke-worker.mjs: the forged Access JWT is now built from its JSON parts at run time (same bytes) instead of sitting in the source as a token literal, which secret scanners rightly flag; the "did not come up" case reports through the same helper as any other failure instead of throwing into its own catch. - scripts/check-csp-hashes.mjs: ("|') → ["'] in the JSON-LD matcher. - src/lib/format.ts: drop the two escapes of `]` outside a character class (a lone `]` is a literal there); the classes keep theirs. - src/lib/legal-lang.ts: the heading → language table is a Map, so "Tiếng Việt" is data, not a property name mixing scripts. - qodana.yaml: ES6PreferShortImport off, with the reason — the build scripts and astro.config.mjs run under plain Node, where the `@/` alias doesn't resolve and a TypeScript import keeps its `.ts`. - failThreshold: 0, so any new problem turns the check red. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: sort the licence report with an explicit compare function Sonar S2871: Array#sort() without a compare function sorts by UTF-16 code units, which is not alphabetical for every name. Both lists now sort with localeCompare. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1b7364a2aa
commit
0c56acd806
14 files changed
+467
-54
No files matched your search
@@ -102,6 +102,11 @@ jobs:
|
||||
- name: Third-party notices
|
||||
run: npm run gen-notices -- --check
|
||||
|
||||
# The same policy over every package in package-lock.json, transitive dependencies and
|
||||
# each platform's binaries included; anything outside it needs a per-package review.
|
||||
- name: Licences (whole dependency tree)
|
||||
run: npm run check-licenses
|
||||
|
||||
# Fail if any changed image under src/assets/ still carries GPS or a camera serial.
|
||||
- name: Check EXIF (changed images)
|
||||
env:
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
name: Qodana
|
||||
|
||||
# JetBrains Qodana (Qodana for JS, WebStorm's inspections) over the whole repository: on every
|
||||
# PR, on main and by hand. Settings live in qodana.yaml. Results go to Qodana Cloud (the
|
||||
# project token is the QODANA_TOKEN secret) and, for main, to GitHub code scanning as SARIF.
|
||||
#
|
||||
# Advisory, not required: the main ruleset requires only `build`, and Dependabot and fork PRs
|
||||
# get no secrets, so they skip this job like the SonarCloud one in ci.yml.
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore: ["poli0981.dev-docs/**", "*.md", "LICENSE"]
|
||||
workflow_dispatch:
|
||||
|
||||
# Explicit — a missing block makes GitHub default every scope to `none`.
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
# Cancel superseded PR runs; let main runs finish.
|
||||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
||||
|
||||
jobs:
|
||||
qodana:
|
||||
if: >-
|
||||
github.event_name != 'pull_request' ||
|
||||
(github.event.pull_request.head.repo.full_name == github.repository &&
|
||||
github.actor != 'dependabot[bot]')
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
permissions:
|
||||
contents: read
|
||||
checks: write # problem annotations on the commit
|
||||
pull-requests: write # the summary comment on PRs
|
||||
security-events: write # SARIF upload (main and manual runs)
|
||||
steps:
|
||||
# Pinned to commit SHAs like every other workflow here; Dependabot keeps them current.
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
# The PR's own head commit, not the merge preview, so Qodana Cloud links to it.
|
||||
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
|
||||
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||
with:
|
||||
node-version-file: .nvmrc
|
||||
cache: npm
|
||||
|
||||
# Same rules as ci.yml: no dependency lifecycle script runs in CI, and any lockfile
|
||||
# package with an install script must be on package.json#allowScripts.
|
||||
- name: Install
|
||||
run: npm ci --ignore-scripts
|
||||
|
||||
- name: Install scripts allow-listed
|
||||
run: npm run check-install-scripts
|
||||
|
||||
# Gitignored, generated types the TypeScript service needs to resolve imports of
|
||||
# cloudflare:workers, astro:content and friends.
|
||||
- name: Generate types
|
||||
run: |
|
||||
npm run types
|
||||
npm run types:widgets
|
||||
npm run astro -- sync
|
||||
|
||||
- name: Qodana scan
|
||||
uses: JetBrains/qodana-action@13e3acbbaeb2cbfc37893b98e74594985edf42eb # v2026.2.4
|
||||
env:
|
||||
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
|
||||
QODANA_ENDPOINT: https://qodana.cloud
|
||||
with:
|
||||
# Whole repository every time (it is small), so the quality gate in qodana.yaml
|
||||
# always judges the full picture rather than the files a PR happens to touch.
|
||||
pr-mode: false
|
||||
upload-result: true
|
||||
|
||||
# Like the OSV scan: main and manual runs only, so PR runs don't open code-scanning
|
||||
# alerts for code that may never merge.
|
||||
- name: Upload SARIF to code scanning
|
||||
if: ${{ !cancelled() && github.event_name != 'pull_request' }}
|
||||
uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066 # v4.39.3
|
||||
with:
|
||||
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
|
||||
category: qodana
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
[](https://github.com/poli0981/poli0981-dev/actions/workflows/ci.yml)
|
||||
[](https://sonarcloud.io/summary/new_code?id=poli0981_poli0981-dev)
|
||||
[](https://github.com/poli0981/poli0981-dev/actions/workflows/qodana.yml)
|
||||
[](LICENSE)
|
||||
|
||||
The personal site of Kokone (SkullMute) — dev portfolio, blog, short fiction and a hub for
|
||||
@@ -20,7 +21,7 @@ the SkullMute channel, in Vietnamese and English. Live at **[poli0981.dev](https
|
||||
| Content | Markdown/MDX in [`poli0981/content`](https://github.com/poli0981/content) (git submodule `src/content`) |
|
||||
| Search | Pagefind (built after `astro build`) |
|
||||
| Tooling | Node 26 · TypeScript 7 (`tsc`) next to TypeScript 6 (astro check, typescript-eslint) · `node:test` · ESLint · Prettier · knip |
|
||||
| Quality | SonarCloud quality gate · CodeQL · OSV-Scanner · Snyk · Dependabot (3-day cooldown) · axe-core accessibility gate |
|
||||
| Quality | SonarCloud quality gate · Qodana · CodeQL · OSV-Scanner · Snyk · Dependabot (3-day cooldown) · axe-core gate · licence check |
|
||||
|
||||
## How it fits together
|
||||
|
||||
|
||||
@@ -74,9 +74,11 @@ inventory is `package-lock.json`; platform binaries are covered in prose below.
|
||||
|
||||
## Licenses outside the standard allowlist
|
||||
|
||||
**MPL-2.0** — 3 package(s): `@axe-core/playwright`, `@resvg/resvg-js`, `satori`
|
||||
**MPL-2.0** — 3 package(s):
|
||||
|
||||
> Reviewed: File-level copyleft. satori and @resvg/resvg-js are used unmodified as build-time tools and never shipped to the browser, so no source-disclosure obligation is triggered.
|
||||
- `@axe-core/playwright` — reviewed: File-level copyleft. Runs only in the accessibility tests (tests/a11y); never shipped.
|
||||
- `@resvg/resvg-js` — reviewed: File-level copyleft. Used unmodified at build time to draw the OG cards (scripts/gen-og.mjs); never shipped to the browser or the Worker.
|
||||
- `satori` — reviewed: File-level copyleft. Used unmodified at build time to draw the OG cards (scripts/gen-og.mjs); never shipped to the browser or the Worker.
|
||||
|
||||
<!-- END GENERATED -->
|
||||
|
||||
@@ -108,8 +110,8 @@ Not packages — listed for transparency:
|
||||
- **Discord** — a webhook receiving bug-report notifications.
|
||||
- **YouTube, Steam and GitHub public APIs** — read by the widgets cron worker; visitors' browsers
|
||||
never call them (images are mirrored and served from the site).
|
||||
- **SonarCloud, CodeQL, OSV-Scanner, Snyk** — code and dependency analysis in CI; nothing they do
|
||||
reaches the running site.
|
||||
- **SonarCloud, Qodana (JetBrains), CodeQL, OSV-Scanner, Snyk** — code and dependency analysis in
|
||||
CI; nothing they do reaches the running site.
|
||||
|
||||
## Fonts
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"test:coverage": "node --import ./tests/support/register.mjs --test --experimental-test-coverage --test-coverage-include=\"src/**/*.ts\" --test-coverage-include=\"workers/widgets/src/**/*.ts\" --test-coverage-exclude=\"**/*.d.ts\" --test-coverage-exclude=\"src/lib/easter.ts\" --test-coverage-exclude=\"src/content.config.ts\" --test-coverage-lines=80 --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info \"tests/**/*.test.ts\"",
|
||||
"test:a11y": "node --test --test-concurrency=1 \"tests/a11y/*.spec.ts\"",
|
||||
"gen-notices": "node scripts/gen-notices.mjs",
|
||||
"check-licenses": "node scripts/check-licenses.mjs",
|
||||
"new:post": "node scripts/new-post.mjs",
|
||||
"gen-og": "node scripts/gen-og.mjs",
|
||||
"preview": "astro preview",
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
# JetBrains Qodana — run by .github/workflows/qodana.yml on every PR and on main
|
||||
# (docs 08 §0). Reference: https://www.jetbrains.com/help/qodana/configuration-reference.html
|
||||
#
|
||||
# Qodana for JS is WebStorm's inspection engine. It reads .ts/.js/.mjs, CSS, JSON, YAML and
|
||||
# Markdown — not .astro or .svelte, which stay with astro check, eslint-plugin-astro/-svelte
|
||||
# and Prettier in ci.yml.
|
||||
version: "1.0"
|
||||
linter: qodana-js
|
||||
|
||||
# Native mode: the workflow sets up Node from .nvmrc and runs `npm ci` itself, so the analysis
|
||||
# resolves the same Node 26 and node_modules as the build (the Docker image ships its own Node).
|
||||
withinDocker: false
|
||||
|
||||
# Quality gate: the first run's 11 findings were fixed or, for one inspection, switched off
|
||||
# below with the reason, so any problem now is a new one and turns the check red.
|
||||
failThreshold: 0
|
||||
|
||||
profile:
|
||||
name: qodana.recommended
|
||||
inspections:
|
||||
# Not source code: build output, coverage, generated types, the content submodule (prose,
|
||||
# in its own repo), the design docs and the frontmatter templates.
|
||||
- group: ALL
|
||||
ignore:
|
||||
- "dist/**"
|
||||
- "coverage/**"
|
||||
- ".astro/**"
|
||||
- ".wrangler/**"
|
||||
- "src/content/**"
|
||||
- "poli0981.dev-docs/**"
|
||||
- "docs/templates/**"
|
||||
- "public/pagefind/**"
|
||||
- "worker-configuration.d.ts"
|
||||
- "workers/widgets/worker-configuration.d.ts"
|
||||
# Prose checkers don't read Vietnamese: every other word of the bilingual UI strings,
|
||||
# comments and docs would be a "typo".
|
||||
- inspection: SpellCheckingInspection
|
||||
enabled: false
|
||||
- inspection: GrazieInspection
|
||||
enabled: false
|
||||
# "Import can be shortened" wants tsconfig's `@/` alias or extensionless paths. The build
|
||||
# scripts and astro.config.mjs run under plain Node, where `@/` doesn't resolve and a
|
||||
# TypeScript import needs its `.ts`; in src/ relative vs alias imports are a style choice.
|
||||
- inspection: ES6PreferShortImport
|
||||
enabled: false
|
||||
@@ -37,7 +37,7 @@ const CONTENT = /\bcontent\s*=\s*(?:"([^"]*)"|'([^']*)')/i;
|
||||
// CodeQL js/bad-tag-filter found three separate holes here, one patch at a time, so the
|
||||
// cases below are now asserted on every run instead of being re-reasoned from scratch.
|
||||
const SCRIPT = /<script(\s[^>]*)?>([\s\S]*?)<\/script(\s[^>]*)?>/gi;
|
||||
const JSON_LD = /type=("|')?application\/ld\+json/i;
|
||||
const JSON_LD = /type=["']?application\/ld\+json/i;
|
||||
// Inline <style> blocks need their hash in the policy just the same, and Astro misses some:
|
||||
// the styles of a component rendered only from MDX content (Callout) shipped unhashed, so the
|
||||
// browser dropped them. A style *attribute* can never pass a policy without 'unsafe-inline'.
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Licence check over the whole dependency tree. CI runs it in the `build` job (docs 08 §6).
|
||||
*
|
||||
* node scripts/check-licenses.mjs
|
||||
*
|
||||
* gen-notices.mjs writes THIRD-PARTY-NOTICES.md from the direct dependencies only (what is
|
||||
* installed differs per platform, and that file must not). This check reads package-lock.json
|
||||
* instead, which records the declared licence of EVERY package — transitive ones and each
|
||||
* platform's binaries included — so it gives the same answer on Windows and on Linux CI, with
|
||||
* nothing installed.
|
||||
*
|
||||
* A package passes when its licence expression is satisfied by ALLOWED, or by the one licence
|
||||
* its REVIEWED entry clears (scripts/license-policy.mjs). A package with no licence, or one
|
||||
* that is not an SPDX expression, fails. So does a REVIEWED entry that no longer matches any
|
||||
* package: the list should say what is actually in the tree.
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
import { ALLOWED, REVIEWED, reviewFor, satisfies } from "./license-policy.mjs";
|
||||
|
||||
const PREFIX = "node_modules/";
|
||||
const lock = JSON.parse(readFileSync("package-lock.json", "utf8"));
|
||||
|
||||
/** null when the package is fine, "reviewed" when its REVIEWED entry clears it, else why not. */
|
||||
function verdict(name, license) {
|
||||
if (!license) return "declares no licence";
|
||||
try {
|
||||
if (satisfies(license, ALLOWED)) return null;
|
||||
const review = reviewFor(name);
|
||||
if (review && satisfies(license, new Set([...ALLOWED, review.license]))) return "reviewed";
|
||||
return `${license} is outside the policy`;
|
||||
} catch (error) {
|
||||
return error.message;
|
||||
}
|
||||
}
|
||||
|
||||
const problems = new Set();
|
||||
const byName = (a, b) => a.localeCompare(b);
|
||||
const reviewed = new Set();
|
||||
const usedReviews = new Set();
|
||||
let total = 0;
|
||||
|
||||
for (const [path, entry] of Object.entries(lock.packages ?? {})) {
|
||||
// "" is this project; anything without node_modules/ would be a workspace or a link.
|
||||
if (!path.includes(PREFIX) || entry.link) continue;
|
||||
const name = path.slice(path.lastIndexOf(PREFIX) + PREFIX.length);
|
||||
total++;
|
||||
const result = verdict(name, entry.license);
|
||||
if (result === "reviewed") {
|
||||
reviewed.add(name);
|
||||
usedReviews.add(reviewFor(name));
|
||||
} else if (result) {
|
||||
problems.add(`${name}@${entry.version}: ${result}`);
|
||||
}
|
||||
}
|
||||
|
||||
for (const entry of REVIEWED) {
|
||||
if (!usedReviews.has(entry)) {
|
||||
problems.add(`REVIEWED entry for ${entry.packages.join(", ")} matches no package — remove it`);
|
||||
}
|
||||
}
|
||||
|
||||
if (problems.size > 0) {
|
||||
console.error(`Licence check failed (${problems.size}):`);
|
||||
for (const problem of [...problems].sort(byName)) console.error(` ${problem}`);
|
||||
console.error(
|
||||
"Clear a package in REVIEWED (scripts/license-policy.mjs) with a reason, or drop it.",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(
|
||||
`licences ok — ${total} packages in package-lock.json; cleared by review: ` +
|
||||
`${reviewed.size} (${[...reviewed].sort(byName).join(", ")})`,
|
||||
);
|
||||
+35
-39
@@ -11,46 +11,41 @@
|
||||
* `license-checker`. Same source of truth, one less dependency to vet — which is the
|
||||
* point of the exercise.
|
||||
*
|
||||
* Any license outside ALLOWED is reported. That is deliberately noisy: an unexpected
|
||||
* license is exactly the thing a human should look at, so it fails rather than being
|
||||
* quietly folded into the table. Cleared cases go in REVIEWED with a reason.
|
||||
* Any license outside the shared policy's ALLOWED list is reported. That is deliberately
|
||||
* noisy: an unexpected license is exactly the thing a human should look at, so it fails rather
|
||||
* than being quietly folded into the table. Cleared packages go in REVIEWED with a reason
|
||||
* (scripts/license-policy.mjs, shared with check-licenses.mjs, which covers the whole tree).
|
||||
*
|
||||
* The block holds nothing that changes on a routine version bump (no versions, no package
|
||||
* count): it used to print the size of the resolved tree, so every Dependabot PR that added
|
||||
* or dropped one transitive package failed CI here.
|
||||
*/
|
||||
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
||||
import { ALLOWED, reviewFor, satisfies } from "./license-policy.mjs";
|
||||
|
||||
const NOTICES = "THIRD-PARTY-NOTICES.md";
|
||||
const BEGIN = "<!-- BEGIN GENERATED — edit scripts/gen-notices.mjs, not this block -->";
|
||||
const END = "<!-- END GENERATED -->";
|
||||
|
||||
// docs 12: the licenses that need no discussion.
|
||||
const ALLOWED = new Set([
|
||||
"MIT",
|
||||
"Apache-2.0",
|
||||
"ISC",
|
||||
"BSD-2-Clause",
|
||||
"BSD-3-Clause",
|
||||
"OFL-1.1",
|
||||
"0BSD",
|
||||
"Unlicense",
|
||||
"CC0-1.0",
|
||||
"MIT OR Apache-2.0",
|
||||
"(MIT OR Apache-2.0)",
|
||||
"Apache-2.0 WITH LLVM-exception",
|
||||
"BlueOak-1.0.0",
|
||||
"Python-2.0",
|
||||
]);
|
||||
/** Whether a license expression passes without review; an unparseable one never does. */
|
||||
function allowedOutright(license) {
|
||||
try {
|
||||
return satisfies(license, ALLOWED);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Licenses cleared by hand. A reason is required — "we shipped it anyway" is not one.
|
||||
const REVIEWED = new Map([
|
||||
[
|
||||
"MPL-2.0",
|
||||
"File-level copyleft. satori and @resvg/resvg-js are used unmodified as build-time " +
|
||||
"tools and never shipped to the browser, so no source-disclosure obligation is triggered.",
|
||||
],
|
||||
]);
|
||||
/** Whether the package's REVIEWED entry clears its license. */
|
||||
function clearedByReview(name, license) {
|
||||
const review = reviewFor(name);
|
||||
if (!review) return false;
|
||||
try {
|
||||
return satisfies(license, new Set([...ALLOWED, review.license]));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function licenseOf(name) {
|
||||
const p = `node_modules/${name}/package.json`;
|
||||
@@ -98,7 +93,7 @@ for (const { name } of direct) {
|
||||
}
|
||||
|
||||
const flagged = [...byLicense.entries()]
|
||||
.filter(([lic]) => !ALLOWED.has(lic))
|
||||
.filter(([lic]) => !allowedOutright(lic))
|
||||
.sort((a, b) => a[0].localeCompare(b[0]));
|
||||
|
||||
// ---------------------------------------------------------------- render
|
||||
@@ -142,10 +137,11 @@ const lines = [
|
||||
if (flagged.length > 0) {
|
||||
lines.push("## Licenses outside the standard allowlist", "");
|
||||
for (const [lic, list] of flagged) {
|
||||
const note = REVIEWED.get(lic);
|
||||
lines.push(`**${lic}** — ${list.length} package(s): ${list.map((n) => `\`${n}\``).join(", ")}`);
|
||||
lines.push("");
|
||||
lines.push(note ? `> Reviewed: ${note}` : `> ⚠️ NOT YET REVIEWED.`);
|
||||
lines.push(`**${lic}** — ${list.length} package(s):`, "");
|
||||
for (const name of list) {
|
||||
const note = clearedByReview(name, lic) ? `reviewed: ${reviewFor(name).reason}` : null;
|
||||
lines.push(`- \`${name}\` — ${note ?? "⚠️ NOT YET REVIEWED."}`);
|
||||
}
|
||||
lines.push("");
|
||||
}
|
||||
}
|
||||
@@ -175,7 +171,9 @@ if (start === -1 || stop === -1) {
|
||||
}
|
||||
const next = current.slice(0, start) + generated + current.slice(stop + END.length);
|
||||
|
||||
const unreviewed = flagged.filter(([lic]) => !REVIEWED.has(lic));
|
||||
const unreviewed = flagged.flatMap(([lic, list]) =>
|
||||
list.filter((name) => !clearedByReview(name, lic)).map((name) => `${name} (${lic})`),
|
||||
);
|
||||
|
||||
if (process.argv.includes("--check")) {
|
||||
if (next !== current) {
|
||||
@@ -187,8 +185,8 @@ if (process.argv.includes("--check")) {
|
||||
}
|
||||
if (unreviewed.length > 0) {
|
||||
console.error(
|
||||
`Unreviewed license(s) in the dependency tree: ${unreviewed.map(([l]) => l).join(", ")}\n` +
|
||||
`Review them and add an entry to REVIEWED in scripts/gen-notices.mjs.`,
|
||||
`Unreviewed license(s) among the direct dependencies: ${unreviewed.join(", ")}\n` +
|
||||
`Review them and add an entry to REVIEWED in scripts/license-policy.mjs.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -197,8 +195,6 @@ if (process.argv.includes("--check")) {
|
||||
writeFileSync(NOTICES, next);
|
||||
console.log(`wrote ${NOTICES} — ${direct.length} direct, ${resolvedCount} resolved packages`);
|
||||
if (unreviewed.length > 0) {
|
||||
console.log(
|
||||
` note: ${unreviewed.length} license(s) need review: ${unreviewed.map(([l]) => l).join(", ")}`,
|
||||
);
|
||||
console.log(` note: ${unreviewed.length} package(s) need review: ${unreviewed.join(", ")}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* Licence policy shared by scripts/gen-notices.mjs (direct dependencies → the table in
|
||||
* THIRD-PARTY-NOTICES.md) and scripts/check-licenses.mjs (every package in package-lock.json).
|
||||
* See docs 08 §6 and docs 12.
|
||||
*
|
||||
* The code is GPL-3.0-only. ALLOWED holds the licences that need no discussion. Anything else
|
||||
* has to be cleared PER PACKAGE in REVIEWED, with a reason: clearing a licence for everyone
|
||||
* would let the next package under it in without anyone looking (that is how
|
||||
* @axe-core/playwright once passed under a note written for satori).
|
||||
*/
|
||||
|
||||
/** SPDX licence identifiers that need no review. */
|
||||
export const ALLOWED = new Set([
|
||||
"MIT",
|
||||
"Apache-2.0",
|
||||
"ISC",
|
||||
"BSD-2-Clause",
|
||||
"BSD-3-Clause",
|
||||
"OFL-1.1",
|
||||
"0BSD",
|
||||
"Unlicense",
|
||||
"CC0-1.0",
|
||||
"BlueOak-1.0.0",
|
||||
"Python-2.0",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Packages cleared by hand: `packages` are exact names or a prefix ending in `*`, `license`
|
||||
* is the one extra licence the entry allows for them. "We shipped it anyway" is not a reason.
|
||||
*/
|
||||
export const REVIEWED = [
|
||||
{
|
||||
packages: ["satori", "@resvg/resvg-js", "@resvg/resvg-js-*"],
|
||||
license: "MPL-2.0",
|
||||
reason:
|
||||
"File-level copyleft. Used unmodified at build time to draw the OG cards " +
|
||||
"(scripts/gen-og.mjs); never shipped to the browser or the Worker.",
|
||||
},
|
||||
{
|
||||
packages: ["axe-core", "@axe-core/playwright"],
|
||||
license: "MPL-2.0",
|
||||
reason:
|
||||
"File-level copyleft. Runs only in the accessibility tests (tests/a11y); never shipped.",
|
||||
},
|
||||
{
|
||||
packages: ["lightningcss", "lightningcss-*"],
|
||||
license: "MPL-2.0",
|
||||
reason:
|
||||
"File-level copyleft. Vite and Tailwind run it unmodified at build time to transform " +
|
||||
"this site's own CSS; the tool itself is not shipped.",
|
||||
},
|
||||
{
|
||||
packages: ["@img/sharp-libvips-*", "@img/sharp-win32-*", "@img/sharp-wasm32"],
|
||||
license: "LGPL-3.0-or-later",
|
||||
reason:
|
||||
"sharp's prebuilt libvips, loaded unmodified by Astro's image service at build time; " +
|
||||
"none of it is shipped. LGPL-3.0 is compatible with GPL-3.0.",
|
||||
},
|
||||
];
|
||||
|
||||
/** The REVIEWED entry that covers a package, if any. */
|
||||
export function reviewFor(name) {
|
||||
return REVIEWED.find((entry) =>
|
||||
entry.packages.some((pattern) =>
|
||||
pattern.endsWith("*") ? name.startsWith(pattern.slice(0, -1)) : name === pattern,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an SPDX licence expression is satisfied by a set of allowed identifiers:
|
||||
* `A OR B` needs one side, `A AND B` needs both, parentheses group, and `X WITH exception`
|
||||
* counts as X (an exception only adds permissions). Throws a SyntaxError for anything that
|
||||
* is not an expression, such as "SEE LICENSE IN LICENSE".
|
||||
*/
|
||||
export function satisfies(expression, allowed) {
|
||||
const tokens = expression.replaceAll("(", " ( ").replaceAll(")", " ) ").trim().split(/\s+/);
|
||||
let at = 0;
|
||||
const isOperator = (token, op) => token?.toUpperCase() === op;
|
||||
const fail = () => {
|
||||
throw new SyntaxError(`Not an SPDX expression: "${expression}"`);
|
||||
};
|
||||
|
||||
function primary() {
|
||||
const token = tokens[at++];
|
||||
if (token === "(") {
|
||||
const value = anyOf();
|
||||
if (tokens[at++] !== ")") fail();
|
||||
return value;
|
||||
}
|
||||
if (!token || token === ")" || ["AND", "OR", "WITH"].some((op) => isOperator(token, op))) {
|
||||
fail();
|
||||
}
|
||||
if (isOperator(tokens[at], "WITH")) {
|
||||
if (!tokens[at + 1]) fail();
|
||||
at += 2;
|
||||
}
|
||||
return allowed.has(token);
|
||||
}
|
||||
function allOf() {
|
||||
let value = primary();
|
||||
while (isOperator(tokens[at], "AND")) {
|
||||
at++;
|
||||
const next = primary();
|
||||
value = value && next;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function anyOf() {
|
||||
let value = allOf();
|
||||
while (isOperator(tokens[at], "OR")) {
|
||||
at++;
|
||||
const next = allOf();
|
||||
value = value || next;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
const result = anyOf();
|
||||
if (at !== tokens.length) fail();
|
||||
return result;
|
||||
}
|
||||
@@ -108,6 +108,11 @@ async function withWorker(port, vars, run) {
|
||||
const base = `http://127.0.0.1:${port}`;
|
||||
const get = (path, init) =>
|
||||
fetch(`${base}${path}`, { redirect: "manual", signal: AbortSignal.timeout(15000), ...init });
|
||||
// A phase that can't run is a failure, reported with the tail of wrangler's own output.
|
||||
const fail = (error) => {
|
||||
failures.push(String(error));
|
||||
console.error(error, `\n${log.slice(-4000)}`);
|
||||
};
|
||||
try {
|
||||
let up = false;
|
||||
for (let i = 0; i < 60 && !up; i++) {
|
||||
@@ -116,11 +121,10 @@ async function withWorker(port, vars, run) {
|
||||
() => sleep(1000).then(() => false),
|
||||
);
|
||||
}
|
||||
if (!up) throw new Error(`wrangler dev did not come up on ${base}`);
|
||||
await run(get, port);
|
||||
if (up) await run(get, port);
|
||||
else fail(new Error(`wrangler dev did not come up on ${base}`));
|
||||
} catch (error) {
|
||||
failures.push(String(error));
|
||||
console.error(error, `\n${log.slice(-4000)}`);
|
||||
fail(error);
|
||||
} finally {
|
||||
stop(server);
|
||||
}
|
||||
@@ -272,8 +276,12 @@ await withWorker(8788, {}, async (get, port) => {
|
||||
"/api/admin/content without Access → 403",
|
||||
(await get("/api/admin/content")).status === 403,
|
||||
);
|
||||
// Well-formed but signed by nobody: real JSON header and claims, a junk signature. Built
|
||||
// here rather than pasted as a token literal, which secret scanners rightly flag.
|
||||
const part = (value) => Buffer.from(JSON.stringify(value)).toString("base64url");
|
||||
const forgedJwt = `${part({ alg: "RS256" })}.${part({ email: "a@b.c" })}.c2ln`;
|
||||
const forged = await get("/api/admin/content", {
|
||||
headers: { "cf-access-jwt-assertion": "eyJhbGciOiJSUzI1NiJ9.eyJlbWFpbCI6ImFAYi5jIn0.c2ln" },
|
||||
headers: { "cf-access-jwt-assertion": forgedJwt },
|
||||
});
|
||||
expect("/api/admin with a forged JWT → 403", forged.status === 403);
|
||||
});
|
||||
|
||||
+2
-2
@@ -42,8 +42,8 @@ export function plainText(markdown: string): string {
|
||||
// [ \t] rather than \s, which (under /m) could run across newlines and backtrack.
|
||||
return markdown
|
||||
.replace(/```[\s\S]*?```/g, "") // fenced code
|
||||
.replace(/!\[[^[\]]*\]\([^()]*\)/g, "") // images
|
||||
.replace(/\[([^[\]]+)\]\([^()]*\)/g, "$1") // links → their text
|
||||
.replace(/!\[[^[\]]*]\([^()]*\)/g, "") // images
|
||||
.replace(/\[([^[\]]+)]\([^()]*\)/g, "$1") // links → their text
|
||||
.replace(/^[ \t]{0,3}#{1,6}[ \t]+/gm, "") // headings
|
||||
.replace(/^[ \t]{0,3}>[ \t]?/gm, "") // blockquotes
|
||||
.replace(/^[ \t]*[-*+][ \t]+/gm, "") // list bullets
|
||||
|
||||
@@ -7,14 +7,17 @@
|
||||
* section under any other `<h2>` (the "Models" and "Components" tables) is left alone and
|
||||
* keeps the page's language. The container is styled `display: contents` (prose.css).
|
||||
*/
|
||||
const HALVES: Record<string, string> = { English: "en", "Tiếng Việt": "vi" };
|
||||
const HALVES = new Map([
|
||||
["English", "en"],
|
||||
["Tiếng Việt", "vi"],
|
||||
]);
|
||||
|
||||
export function markLanguageHalves(html: string): string {
|
||||
return html
|
||||
.split(/(?=<h2[\s>])/)
|
||||
.map((section) => {
|
||||
const heading = /^<h2[^>]*>([^<]*)<\/h2>/.exec(section)?.[1].trim();
|
||||
const lang = heading === undefined ? undefined : HALVES[heading];
|
||||
const lang = heading === undefined ? undefined : HALVES.get(heading);
|
||||
return lang ? `<div lang="${lang}">${section}</div>` : section;
|
||||
})
|
||||
.join("");
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// The licence policy shared by scripts/gen-notices.mjs and scripts/check-licenses.mjs: the
|
||||
// SPDX expression evaluator and the per-package review lookup.
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { ALLOWED, REVIEWED, reviewFor, satisfies } from "../scripts/license-policy.mjs";
|
||||
|
||||
describe("satisfies (SPDX expressions)", () => {
|
||||
it("accepts a single allowed identifier and refuses an unlisted one", () => {
|
||||
assert.equal(satisfies("MIT", ALLOWED), true);
|
||||
assert.equal(satisfies("GPL-2.0-only", ALLOWED), false);
|
||||
});
|
||||
|
||||
it("needs one side of OR and both sides of AND", () => {
|
||||
assert.equal(satisfies("MIT OR GPL-2.0-only", ALLOWED), true);
|
||||
assert.equal(satisfies("GPL-2.0-only OR MIT", ALLOWED), true);
|
||||
assert.equal(satisfies("Apache-2.0 AND LGPL-3.0-or-later", ALLOWED), false);
|
||||
assert.equal(
|
||||
satisfies(
|
||||
"Apache-2.0 AND LGPL-3.0-or-later AND MIT",
|
||||
new Set([...ALLOWED, "LGPL-3.0-or-later"]),
|
||||
),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("binds AND tighter than OR and honours parentheses", () => {
|
||||
assert.equal(satisfies("GPL-2.0-only AND MIT OR ISC", ALLOWED), true);
|
||||
assert.equal(satisfies("GPL-2.0-only AND (MIT OR ISC)", ALLOWED), false);
|
||||
assert.equal(satisfies("(MIT OR Apache-2.0)", ALLOWED), true);
|
||||
});
|
||||
|
||||
it("treats `X WITH exception` as X and accepts lower-case operators", () => {
|
||||
assert.equal(satisfies("Apache-2.0 WITH LLVM-exception", ALLOWED), true);
|
||||
assert.equal(satisfies("GPL-2.0-only WITH Classpath-exception-2.0", ALLOWED), false);
|
||||
assert.equal(satisfies("MIT or Apache-2.0", ALLOWED), true);
|
||||
});
|
||||
|
||||
it("throws on text that is not an expression", () => {
|
||||
for (const bad of [
|
||||
"SEE LICENSE IN LICENSE",
|
||||
"",
|
||||
"(MIT",
|
||||
"MIT AND",
|
||||
"AND MIT",
|
||||
"MIT WITH",
|
||||
"MIT)",
|
||||
]) {
|
||||
assert.throws(() => satisfies(bad, ALLOWED), SyntaxError, bad);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("reviewFor (per-package clearance)", () => {
|
||||
it("matches exact names and prefix patterns only", () => {
|
||||
assert.equal(reviewFor("satori")?.license, "MPL-2.0");
|
||||
assert.equal(reviewFor("@resvg/resvg-js-linux-x64-gnu")?.license, "MPL-2.0");
|
||||
assert.equal(reviewFor("lightningcss-darwin-arm64")?.license, "MPL-2.0");
|
||||
assert.equal(reviewFor("@img/sharp-libvips-linux-x64")?.license, "LGPL-3.0-or-later");
|
||||
assert.equal(reviewFor("satori-html"), undefined);
|
||||
assert.equal(reviewFor("@img/sharp-linux-x64"), undefined);
|
||||
});
|
||||
|
||||
it("gives every entry a reason and a single extra licence", () => {
|
||||
for (const entry of REVIEWED) {
|
||||
assert.ok(entry.reason.length > 40, entry.packages.join(", "));
|
||||
assert.ok(!ALLOWED.has(entry.license), entry.license);
|
||||
assert.doesNotThrow(() => satisfies(entry.license, ALLOWED));
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user