-
Notifications
You must be signed in to change notification settings - Fork 0
fix(security): establish canonical npm, PDF.js, and Undici baseline #783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seonghobae
wants to merge
37
commits into
develop
Choose a base branch
from
fix/high-security-dependency-baseline
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
4294ddc
test(supply-chain): require deterministic npm lock generator
seonghobae afb20be
fix(supply-chain): pin npm lock generator metadata
seonghobae e64c229
ci(supply-chain): prove npm version and lock reproduction
seonghobae ebbde9b
docs(supply-chain): record npm generator provenance
seonghobae 694ca83
docs(changelog): record npm generator contract
seonghobae 90dc2a0
fix(supply-chain): avoid serializing npm into runtime engines
seonghobae fecc36b
test(supply-chain): keep npm enforcement out of runtime engines
seonghobae 9eb83c3
docs(supply-chain): separate npm generator from runtime engines
seonghobae 5609b88
ci(supply-chain): publish deterministic lock reproduction evidence
seonghobae 032314d
test(supply-chain): require preserved lock reproduction evidence
seonghobae 0263ad4
test(security): require coordinated PDF.js and Undici baseline
seonghobae 2cbf767
test(security): disable PDF expression evaluation
seonghobae 475de96
fix(security): pin the patched Undici transitive version
seonghobae deb74ac
fix(security): pin the patched PDF.js release
seonghobae dc90d5b
fix(security): disable PDF expression evaluation
seonghobae b23b957
docs(security): record coordinated PDF and HTTP remediation
seonghobae 2e99f72
docs(changelog): record coordinated security remediation
seonghobae 8f50fe4
fix(security): anchor the Undici override to an exact root floor
seonghobae e2c0c2d
test(security): bind exact root floor and npm package locations
seonghobae dd93f96
ci(pr783): import exact npm 10.9.8 lock artifact
seonghobae dd8d1ac
fix(score): align PDF.js boundary with 6.2.108 API
seonghobae 988dc1d
test(score): prove the supported data-only PDF.js boundary
seonghobae a39e37f
docs(security): record the supported PDF.js 6.2.108 boundary
seonghobae 6b753e6
docs(changelog): describe the supported patched PDF boundary
seonghobae b773653
ci(pr783): rerun lock import after supported API repair
seonghobae 01cb39e
ci(pr783): publish the verified lock from the bounded importer
seonghobae ad558ac
ci(pr783): fetch complete lineage for verified lock publication
seonghobae 83865dc
fix(security): import verified npm 10.9.8 lock
github-actions[bot] e6b48ca
test(ci): preserve canonical npm provenance formatting
seonghobae 3edf173
ci(pr783): diagnose Ruff import ordering
seonghobae 2345219
style(ci): normalize security test imports
seonghobae dc7e8b4
style(ci): normalize npm provenance test imports
seonghobae c5ee630
chore(ci): remove completed Ruff diagnostic
seonghobae f0c9ad1
ci(pr783): finalize exact Ruff formatting
seonghobae 102a89f
chore(ci): remove temporary branch writer
seonghobae d4887ec
style(test): apply Ruff formatting to security contracts
seonghobae 459abdd
style(test): finish Ruff formatting for npm provenance
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { getDocument, GlobalWorkerOptions } from "pdfjs-dist"; | ||
| import { configureScorePdfWorker, loadScorePdf } from "./pdfjs"; | ||
|
|
||
| vi.mock("pdfjs-dist", () => ({ | ||
| getDocument: vi.fn(() => ({ promise: Promise.resolve(), destroy: vi.fn() })), | ||
| GlobalWorkerOptions: { workerSrc: "" } | ||
| })); | ||
|
|
||
| vi.mock("pdfjs-dist/build/pdf.worker.min.mjs?url", () => ({ | ||
| default: "/assets/pdf.worker.min.mjs" | ||
| })); | ||
|
|
||
| describe("score PDF.js boundary", () => { | ||
| beforeEach(() => { | ||
| vi.mocked(getDocument).mockClear(); | ||
| GlobalWorkerOptions.workerSrc = ""; | ||
| }); | ||
|
|
||
| it("uses the locally bundled worker asset", () => { | ||
| configureScorePdfWorker(); | ||
|
|
||
| expect(GlobalWorkerOptions.workerSrc).toBe("/assets/pdf.worker.min.mjs"); | ||
|
|
||
| configureScorePdfWorker(); | ||
| expect(GlobalWorkerOptions.workerSrc).toBe("/assets/pdf.worker.min.mjs"); | ||
| }); | ||
|
|
||
| it("copies validated bytes through the supported data-only API", () => { | ||
| const source = new Uint8Array([0x25, 0x50, 0x44, 0x46]); | ||
|
|
||
| loadScorePdf(source); | ||
|
|
||
| expect(getDocument).toHaveBeenCalledTimes(1); | ||
| const parameters = vi.mocked(getDocument).mock.calls[0]?.[0]; | ||
| expect(parameters).toBeTypeOf("object"); | ||
| expect(Object.keys(parameters as object)).toEqual(["data"]); | ||
| const copiedBytes = (parameters as { data: Uint8Array }).data; | ||
| expect(copiedBytes).toEqual(source); | ||
| expect(copiedBytes).not.toBe(source); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # High-security PDF and HTTP dependency baseline | ||
|
|
||
| ## Decision | ||
|
|
||
| BandScope treats the PDF parser and its transitive HTTP client as one security-release boundary: | ||
|
|
||
| - `pdfjs-dist` is pinned exactly to `6.2.108`; | ||
| - `undici` is pinned exactly to `7.29.0` through the root npm override; and | ||
| - the complete npm workspace lock is generated only by the repository-pinned npm `10.9.8` workflow and imported unchanged from the workflow artifact. | ||
|
|
||
| PDF.js `6.2.108` no longer exposes the legacy `isEvalSupported` member in its public `DocumentInitParameters` contract, and `getDocument` no longer reads that member. BandScope therefore does not cast or pass an unknown option that would be ignored while creating false assurance. The primary remediation is the patched parser release, reinforced by a narrow data-only call, copied caller-owned bytes, and a same-origin bundled worker. | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| A[Validated local PDF bytes] --> B[Copied Uint8Array] | ||
| B --> D[Data-only DocumentInitParameters] | ||
| D --> C[pdfjs-dist 6.2.108] | ||
| C --> W[Same-origin bundled worker] | ||
| W --> R[Canvas render] | ||
| J[jsdom development path] --> U[undici 7.29.0 override] | ||
| N[npm 10.9.8] --> L[Exact package-lock artifact] | ||
| L --> C | ||
| L --> U | ||
| ``` | ||
|
|
||
| ## Threat boundary | ||
|
|
||
| The score viewer accepts only bytes already copied into the app-owned workspace through the native PDF intake boundary. It does not accept a URL, credentials, custom request headers, or a remote worker. This prevents a PDF from selecting an attacker-controlled fetch origin or script asset. | ||
|
|
||
| PDF bytes remain untrusted after the native magic-byte, size, and path checks. Parser vulnerabilities, malformed object graphs, embedded actions, and resource-exhaustion paths can still occur inside a syntactically valid PDF. The patched parser, exact dependency lock, copied data-only input, same-origin worker, and existing native intake limits therefore remain mandatory for locally selected files. | ||
|
|
||
| Undici is currently a development dependency reached through jsdom, but development and CI parsers process attacker-controlled fixtures, generated HTML, and network-like request bodies. A dev-only label does not make header injection, shared-cache disclosure, retry desynchronization, or cookie-attribute injection acceptable in the trusted build boundary. | ||
|
|
||
| ## Lockfile provenance | ||
|
|
||
| The security manifests are changed before the lock. The exact branch workflow then: | ||
|
|
||
| 1. verifies Node `22.22.3` and npm `10.9.8`; | ||
| 2. runs `npm install --package-lock-only --ignore-scripts --no-audit --no-fund`; | ||
| 3. uploads the generated `package-lock.json` under a head-SHA-bound artifact name; and | ||
| 4. fails while the generated lock differs from the branch. | ||
|
|
||
| The maintainer imports that generated artifact byte-for-byte and reruns the workflow. The second run must produce a clean diff. No tarball URL, SRI, dependency range, `peer` classification, or workspace record is edited by hand. | ||
|
|
||
| The lock contract requires the exact public-registry tarball and SHA-512 SRI for both patched packages and requires every existing `node_modules/@esbuild/*` location to retain npm 10.9.8's `peer: true` classification. This distinguishes the intended security graph from unrelated Dependabot generator churn. | ||
|
|
||
| ## Verification | ||
|
|
||
| The merge gate includes: | ||
|
|
||
| - exact manifest and lock artifact tests; | ||
| - a direct PDF.js wrapper test proving copied bytes, the locally bundled worker, and an exact data-only initialization object; | ||
| - TypeScript compilation against the installed PDF.js `DocumentInitParameters` rather than an unsafe cast; | ||
| - valid and malformed local score-PDF component tests; | ||
| - desktop lint, strict typecheck, complete measured tests, and production build; | ||
| - Tauri/Rust checks and native PDF intake regressions; | ||
| - `npm audit --workspaces --audit-level=high` with no high finding; | ||
| - repository SAST, CodeQL, security scan, secret scan, SBOM, and dependency evidence; | ||
| - current-head central coverage and automated review; | ||
| - zero unresolved actionable threads and a qualifying independent non-author approval; and | ||
| - normal branch protection without administrative bypass. | ||
|
|
||
| ## Failure, rollback, and incident evidence | ||
|
|
||
| On a failed lock replay or parser regression, preserve the exact head SHA, Node/npm versions, generated-lock artifact ID and digest, original and generated lock blob SHA, test output, audit report, and workflow run ID. Do not merge a partially updated graph. | ||
|
|
||
| Rollback restores the previous desktop manifest, root override, complete lock, PDF loader, tests, and CHANGELOG entry together. Because the previous graph contains known high findings, rollback is an emergency availability action only and requires an explicit security exception, compensating controls, owner, expiration, and immediate replacement plan. | ||
|
|
||
| ## References | ||
|
|
||
| GitHub. (2026). *PDF.js vulnerable to arbitrary JavaScript execution upon opening a malicious PDF* (GHSA-hq66-cqwq-w95j) [Security advisory]. https://github.com/advisories/GHSA-hq66-cqwq-w95j | ||
|
|
||
| Mozilla. (2026). *Document initialization parameters in PDF.js 6.2.108* [Source code]. GitHub. https://github.com/mozilla/pdf.js/blob/v6.2.108/src/display/api.js | ||
|
|
||
| Mozilla. (2026). *PDF.js 6.2.108* [Software release]. https://github.com/mozilla/pdf.js/releases/tag/v6.2.108 | ||
|
|
||
| Node.js contributors. (2026). *Undici 7.29.0* [Software release]. https://github.com/nodejs/undici/releases/tag/v7.29.0 | ||
|
|
||
| npm, Inc. (2026). *npm ci*. npm Docs. https://docs.npmjs.com/cli/v11/commands/npm-ci/ | ||
|
|
||
| npm, Inc. (2026). *package-lock.json*. npm Docs. https://docs.npmjs.com/cli/v11/configuring-npm/package-lock-json/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # npm lockfile generator provenance | ||
|
|
||
| ## Decision | ||
|
|
||
| BandScope generates and verifies its root npm workspace lock with exactly npm `10.9.8`. The root manifest records that decision through: | ||
|
|
||
| - `packageManager: npm@10.9.8` as package-manager selection metadata; and | ||
| - `devEngines.packageManager` with `onFail: error` as npm's source-tree command gate. | ||
|
|
||
| The npm version is intentionally not repeated under `engines`. npm serializes `engines` into the root lock package, so adding an npm-only source-tool constraint there creates lock metadata churn unrelated to dependency resolution. `devEngines`, the explicit CI assertion, and the replay gate enforce the generator while the published `engines.node` range remains the runtime compatibility contract. | ||
|
|
||
| The primary GitHub Actions workflow uses Node `22.22.3`, verifies the bundled npm version before any installation, runs `npm ci`, then runs a package-lock-only regeneration with scripts, audit, and funding output disabled. Any `package-lock.json` diff fails the exact head. | ||
|
|
||
| The Node runtime support decision remains separate. This change does not raise the public `>=22.13 <23` Node range; a coordinated Node-floor migration is tracked independently. | ||
|
|
||
| ## Why the generator is part of the lock identity | ||
|
|
||
| npm documents `package-lock.json` as the location-keyed description of the exact dependency tree. Lockfile version 3 is intended for npm 9 and newer. npm also notes that different package-manager versions may use different installation algorithms and metadata representations. A committed lockfile therefore is not fully reproducible unless the generator version and install-shaping flags are versioned with it. | ||
|
|
||
| `npm ci` is the immutable consumption path: it requires a lockfile, rejects manifest/lock dependency disagreement, removes an existing `node_modules`, and does not write the manifest or lock. It does not prove that a future dependency update will regenerate byte-identical metadata. The additional package-lock-only replay closes that gap. | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| M[package.json ranges and workspaces] --> G[npm 10.9.8] | ||
| C[project npm configuration] --> G | ||
| G --> L[package-lock.json v3] | ||
| L --> I[npm ci clean install] | ||
| I --> R[npm 10.9.8 package-lock-only replay] | ||
| R --> D{lock diff?} | ||
| D -->|no| A[reproducible exact-head evidence] | ||
| D -->|yes| F[fail closed] | ||
| ``` | ||
|
|
||
| ## Security and operational boundary | ||
|
|
||
| - Dependency PRs may change only manifest ranges and the lock records produced by npm `10.9.8`. | ||
| - Reviewers must reject unrelated lock metadata that cannot be reproduced by the pinned generator. | ||
| - No lock record may be added or removed by hand to satisfy a validator. | ||
| - Install-shaping flags that change the tree, such as `legacy-peer-deps` or `install-links`, must be committed in project configuration and used identically by `npm ci` and regeneration. | ||
| - Dependency lifecycle scripts remain disabled for the reproduction pass. The normal clean install retains the repository's reviewed execution behavior. | ||
| - The exact npm version check occurs before `npm ci`; a different bundled or globally installed npm cannot generate acceptance evidence. | ||
| - The lockfile remains the sole npm workspace lock. Nested workspace locks are prohibited. | ||
|
|
||
| `packageManager` alone is not the enforcement boundary for npm because Corepack's npm shim is not enabled by default in Node distributions. Enforcement is provided by npm `devEngines`, the explicit CI version assertion, and the lock replay. | ||
|
|
||
| ## Verification | ||
|
|
||
| `services/analysis-engine/tests/test_npm_toolchain_contract.py` verifies the manifest metadata, separation of runtime and generator constraints, exact CI Node/npm identity, replay command and flags, clean lock diff, and lockfile version 3. Repository CI then executes the replay using the hosted toolchain. | ||
|
|
||
| A dependency update is mergeable only after: | ||
|
|
||
| 1. npm `10.9.8` produces the checked-in lock from the updated manifest; | ||
| 2. a second package-lock-only replay is byte-clean; | ||
| 3. `npm ci`, lint, strict typecheck, measured tests, production build, Rust/Tauri checks, and security/supply-chain gates succeed on the same head; and | ||
| 4. current-head review, unresolved-thread, independent-approval, and branch-protection requirements succeed without bypass. | ||
|
|
||
| ## Incident response and rollback | ||
|
|
||
| When replay changes the lock unexpectedly: | ||
|
|
||
| 1. preserve the exact head SHA, npm and Node versions, command flags, original lock blob SHA, regenerated lock, and CI run ID; | ||
| 2. determine whether the manifest changed, npm changed, project configuration changed, or the protected lock was generated by a different toolchain; | ||
| 3. never accept a partial or hand-edited lock; | ||
| 4. regenerate from a clean checkout using the reviewed npm version and run the replay twice; | ||
| 5. if rollback is necessary, restore the prior manifest and complete lock together, then rerun the entire exact-head gate. | ||
|
|
||
| ## References | ||
|
|
||
| npm, Inc. (2026). *npm ci*. npm Docs. https://docs.npmjs.com/cli/v11/commands/npm-ci/ | ||
|
|
||
| npm, Inc. (2026). *npm install*. npm Docs. https://docs.npmjs.com/cli/v10/commands/npm-install/ | ||
|
|
||
| npm, Inc. (2026). *package-lock.json*. npm Docs. https://docs.npmjs.com/cli/v11/configuring-npm/package-lock-json/ | ||
|
|
||
| npm, Inc. (2026). *package.json*. npm Docs. https://docs.npmjs.com/cli/configuring-npm/package-json/ | ||
|
|
||
| Node.js contributors. (2026). *Corepack* [Software documentation]. GitHub. https://github.com/nodejs/corepack |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.