Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(deps): remove sprintf-js from accessibility tests (#7245)

LearningCircuitad9a42662373
diff --git a/Dockerfile b/Dockerfile
index f1c040b116..4810f320d8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -216,6 +216,7 @@ RUN playwright install --with-deps chromium || echo "Playwright install failed,
COPY tests/api_tests_with_login/package.json tests/api_tests_with_login/package-lock.json /install/tests/api_tests_with_login/
COPY tests/ui_tests/package.json tests/ui_tests/package-lock.json /install/tests/ui_tests/
COPY tests/accessibility_tests/package.json tests/accessibility_tests/package-lock.json /install/tests/accessibility_tests/
+COPY tests/accessibility_tests/tooling/ /install/tests/accessibility_tests/tooling/
# Install npm packages - Skip Puppeteer Chrome download since we have Playwright's Chrome
WORKDIR /install/tests/api_tests_with_login
@@ -225,7 +226,8 @@ RUN for i in 1 2 3; do if npm ci; then break; else echo "npm ci attempt $i faile
WORKDIR /install/tests/ui_tests
RUN for i in 1 2 3; do if npm ci; then break; else echo "npm ci attempt $i failed, retrying..."; sleep 5; fi; done
WORKDIR /install/tests/accessibility_tests
-RUN for i in 1 2 3; do if npm ci; then break; else echo "npm ci attempt $i failed, retrying..."; sleep 5; fi; done
+RUN for i in 1 2 3; do if npm ci; then exit 0; fi; echo "npm ci attempt $i failed"; sleep 5; done; exit 1
+RUN npm test
# Install Node.js Playwright browsers (version may differ from Python playwright)
RUN npx playwright install chromium
diff --git a/changelog.d/+accessibility-sprintf.security.md b/changelog.d/+accessibility-sprintf.security.md
new file mode 100644
index 0000000000..224b4edc71
--- /dev/null
+++ b/changelog.d/+accessibility-sprintf.security.md
@@ -0,0 +1 @@
+Remove the vulnerable sprintf-js dependency from the Lighthouse accessibility test toolchain while preserving YAML configuration support and audit failure reporting.
diff --git a/tests/accessibility_tests/package-lock.json b/tests/accessibility_tests/package-lock.json
index e2bcefdc1f..f077b326f0 100644
--- a/tests/accessibility_tests/package-lock.json
+++ b/tests/accessibility_tests/package-lock.json
@@ -5,9 +5,10 @@
"packages": {
"": {
"name": "ldr-accessibility-tests",
+ "hasInstallScript": true,
"dependencies": {
"@axe-core/playwright": "^4.13.0",
- "@lhci/cli": "^0.15.1",
+ "@lhci/cli": "0.15.1",
"@playwright/test": "^1.63.0"
},
"engines": {
@@ -634,13 +635,10 @@
}
},
"node_modules/argparse": {
- "version": "1.0.10",
- "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
- "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
- "license": "MIT",
- "dependencies": {
- "sprintf-js": "~1.0.2"
- }
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
+ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
+ "license": "Python-2.0"
},
"node_modules/array-flatten": {
"version": "1.1.1",
@@ -1844,13 +1842,22 @@
}
},
"node_modules/js-yaml": {
- "version": "3.15.2",
- "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.15.2.tgz",
- "integrity": "sha512-6EuL879VkRA+1Cz578mKMiKvjPNEuk6+r1JaFzoSWejZmtf7xWbIyw1e3KkxlkzTIt9Taw6JBhEppG7utc1P+w==",
+ "version": "4.3.2",
+ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz",
+ "integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/puzrin"
+ },
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/nodeca"
+ }
+ ],
"license": "MIT",
"dependencies": {
- "argparse": "^1.0.7",
- "esprima": "^4.0.0"
+ "argparse": "^2.0.1"
},
"bin": {
"js-yaml": "bin/js-yaml.js"
@@ -2950,12 +2957,6 @@
"node": ">=8.0"
}
},
- "node_modules/sprintf-js": {
- "version": "1.0.3",
- "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
- "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==",
- "license": "BSD-3-Clause"
- },
"node_modules/statuses": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
diff --git a/tests/accessibility_tests/package.json b/tests/accessibility_tests/package.json
index d84e76f7f2..21e302f1ab 100644
--- a/tests/accessibility_tests/package.json
+++ b/tests/accessibility_tests/package.json
@@ -5,9 +5,13 @@
"engines": {
"node": ">=22.19"
},
+ "scripts": {
+ "postinstall": "node tooling/patch-lhci-yaml.js",
+ "test": "node --test tooling/check-lhci.js"
+ },
"dependencies": {
"@axe-core/playwright": "^4.13.0",
- "@lhci/cli": "^0.15.1",
+ "@lhci/cli": "0.15.1",
"@playwright/test": "^1.63.0"
},
"overrides": {
@@ -25,6 +29,6 @@
"ip-address": "^10.1.1",
"ws": "^8.20.1",
"qs": "^6.15.2",
- "js-yaml": "^3.15.0"
+ "js-yaml": "^4.3.2"
}
}
diff --git a/tests/accessibility_tests/tooling/check-lhci.js b/tests/accessibility_tests/tooling/check-lhci.js
new file mode 100644
index 0000000000..23d1fa8a5b
--- /dev/null
+++ b/tests/accessibility_tests/tooling/check-lhci.js
@@ -0,0 +1,184 @@
+import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { createRequire } from 'node:module';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { test } from 'node:test';
+
+const require = createRequire(import.meta.url);
+const cliManifest = require.resolve('@lhci/cli/package.json');
+const cliRequire = createRequire(cliManifest);
+const utilsManifest = cliRequire.resolve('@lhci/utils/package.json');
+const utilsRequire = createRequire(utilsManifest);
+const cli = cliRequire.resolve('./src/cli.js');
+const loader = utilsRequire.resolve('./src/lighthouserc.js');
+const { loadRcFile, loadAndParseRcFile } = utilsRequire(loader);
+const patchScript = new URL('./patch-lhci-yaml.js', import.meta.url);
+const yamlManifest = utilsRequire.resolve('js-yaml/package.json');
+const yamlCli = path.join(path.dirname(yamlManifest), utilsRequire(yamlManifest).bin['js-yaml']);
+
+function workspace(t) {
+ const directory = mkdtempSync(path.join(tmpdir(), 'ldr-lhci-'));
+ t.after(() => rmSync(directory, { recursive: true, force: true }));
+ return directory;
+}
+
+function node(args, cwd, extraEnv = {}) {
+ const env = { ...process.env };
+ for (const key of Object.keys(env)) {
+ if (key.startsWith('LHCI_') || key === 'npm_config_package_lock_only') delete env[key];
+ }
+ const result = spawnSync(process.execPath, args, {
+ cwd, env: { ...env, ...extraEnv }, encoding: 'utf8', timeout: 30000, maxBuffer: 1024 * 1024,
+ });
+ assert.ifError(result.error);
+ assert.equal(result.signal, null, result.stderr);
+ return result;
+}
+
+test('YAML inheritance retains typed settings and normalized assertion names', t => {
+ const directory = workspace(t);
+ writeFileSync(path.join(directory, 'base.yaml'), `ci:
+ collect:
+ numberOfRuns: 3
+ url: ["http://localhost:5000/auth/login"]
+ settings:
+ disableStorageReset: false
+ onlyCategories: [accessibility]
+ assert:
+ assertions:
+ categories.accessibility: [error, {minScore: 0.90, aggregationMethod: median}]
+`);
+ const filename = path.join(directory, 'lighthouserc.yml');
+ writeFileSync(filename, `ci:
+ extends: ./base.yaml
+ collect:
+ numberOfRuns: 2
+ settings:
+ preset: desktop
+`);
+ assert.deepEqual(loadAndParseRcFile(filename), {
+ numberOfRuns: 2,
+ url: ['http://localhost:5000/auth/login'],
+ settings: { disableStorageReset: false, onlyCategories: ['accessibility'], preset: 'desktop' },
+ assertions: { 'categories:accessibility': ['error', { minScore: 0.9, aggregationMethod: 'median' }] },
+ });
+});
+
+test('JSON and CommonJS Lighthouse configurations still load', t => {
+ const directory = workspace(t);
+ const config = { ci: { collect: { numberOfRuns: 3, settings: { preset: 'desktop' } } } };
+ for (const extension of ['json', 'cjs']) {
+ const filename = path.join(directory, `lighthouserc.${extension}`);
+ writeFileSync(filename, extension === 'json' ? JSON.stringify(config) : `module.exports = ${JSON.stringify(config)};`);
+ assert.deepEqual(loadRcFile(filename), config);
+ }
+});
+
+for (const [name, contents] of [
+ ['malformed YAML', 'ci: [unterminated'],
+ ['JavaScript-specific YAML types', 'ci: !!js/undefined ""'],
+]) {
+ test(`Lighthouse rejects ${name}`, t => {
+ const filename = path.join(workspace(t), 'lighthouserc.yaml');
+ writeFileSync(filename, contents);
+ assert.throws(() => loadRcFile(filename), { name: 'YAMLException' });
+ });
+}
+
+test('normal Lighthouse and YAML CLI version commands produce their versions', t => {
+ const directory = workspace(t);
+ writeFileSync(path.join(directory, 'lighthouserc.yaml'), 'ci: {}\n');
+ const lhci = node([cli, '--version'], directory);
+ assert.equal(lhci.status, 0, lhci.stderr);
+ assert.equal(lhci.stdout.trim(), cliRequire('./package.json').version);
+ const yaml = node([yamlCli, '--version'], directory);
+ assert.equal(yaml.status, 0, yaml.stderr);
+ assert.equal(yaml.stdout.trim(), utilsRequire('js-yaml/package.json').version);
+});
+
+test('YAML CLI still converts typed YAML to JSON', t => {
+ const directory = workspace(t);
+ const filename = path.join(directory, 'input.yaml');
+ writeFileSync(filename, 'enabled: true\nruns: 3\nurls: ["http://localhost/"]\n');
+ const result = node([yamlCli, filename], directory);
+ assert.equal(result.status, 0, result.stderr);
+ assert.deepEqual(JSON.parse(result.stdout), { enabled: true, runs: 3, urls: ['http://localhost/'] });
+});
+
+for (const [score, expectedStatus] of [[0.95, 0], [0.5, 1]]) {
+ test(`real Lighthouse assert CLI enforces YAML threshold for score ${score}`, t => {
+ const directory = workspace(t);
+ writeFileSync(path.join(directory, 'lighthouserc.yaml'), `ci:
+ assert:
+ assertions:
+ categories:accessibility: [error, {minScore: 0.90}]
+`);
+ const reports = path.join(directory, '.lighthouseci');
+ mkdirSync(reports);
+ writeFileSync(path.join(reports, 'lhr-1.json'), JSON.stringify({
+ lighthouseVersion: '13.4.1',
+ finalUrl: 'http://localhost/auth/login',
+ requestedUrl: 'http://localhost/auth/login',
+ audits: {},
+ categories: { accessibility: { id: 'accessibility', title: 'Accessibility', score, auditRefs: [] } },
+ }));
+ const result = node([cli, 'assert', '--includePassedAssertions'], directory);
+ assert.equal(result.status, expectedStatus, result.stderr);
+ const assertions = JSON.parse(readFileSync(path.join(reports, 'assertion-results.json'), 'utf8'));
+ assert.equal(assertions.length, 1);
+ assert.equal(assertions[0].auditId, 'categories');
+ assert.equal(assertions[0].auditProperty, 'accessibility');
+ assert.equal(assertions[0].actual, score);
+ assert.equal(assertions[0].expected, 0.9);
+ assert.equal(assertions[0].passed, expectedStatus === 0);
+ });
+}
+
+// Exercise the installer against isolated copies, leaving the actual toolchain
+// untouched while checking repeated installs and refusal of unknown contents.
+function installation(t, contents = readFileSync(loader, 'utf8')) {
+ const directory = workspace(t);
+ const utilsDir = path.join(directory, 'node_modules/@lhci/utils');
+ const cliDir = path.join(directory, 'node_modules/@lhci/cli');
+ const yamlDir = path.join(directory, 'node_modules/js-yaml');
+ mkdirSync(path.join(utilsDir, 'src'), { recursive: true });
+ mkdirSync(cliDir, { recursive: true });
+ mkdirSync(yamlDir, { recursive: true });
+ copyFileSync(cliManifest, path.join(cliDir, 'package.json'));
+ copyFileSync(utilsManifest, path.join(utilsDir, 'package.json'));
+ copyFileSync(utilsRequire.resolve('js-yaml/package.json'), path.join(yamlDir, 'package.json'));
+ const target = path.join(utilsDir, 'src/lighthouserc.js');
+ writeFileSync(target, contents);
+ const installer = path.join(directory, 'patch.mjs');
+ copyFileSync(patchScript, installer);
+ return { directory, target, installer };
+}
+
+test('compatibility patch is idempotent', t => {
+ const { directory, target, installer } = installation(t);
+ const before = readFileSync(target, 'utf8');
+ for (let run = 0; run < 2; run++) {
+ const result = node([installer], directory);
+ assert.equal(result.status, 0, result.stderr);
+ assert.equal(readFileSync(target, 'utf8'), before);
+ }
+});
+
+test('compatibility patch refuses changed upstream contents without modifying them', t => {
+ const contents = `${readFileSync(loader, 'utf8')}\n// Unexpected upstream change.\n`;
+ const { directory, target, installer } = installation(t, contents);
+ const result = node([installer], directory);
+ assert.notEqual(result.status, 0);
+ assert.match(result.stderr, /refusing to patch unknown source/);
+ assert.equal(readFileSync(target, 'utf8'), contents);
+});
+
+test('lockfile-only updates do not require an installed dependency tree', t => {
+ const directory = workspace(t);
+ const installer = path.join(directory, 'patch.mjs');
+ copyFileSync(patchScript, installer);
+ const result = node([installer], directory, { npm_config_package_lock_only: 'true' });
+ assert.equal(result.status, 0, result.stderr);
+});
diff --git a/tests/accessibility_tests/tooling/patch-lhci-yaml.js b/tests/accessibility_tests/tooling/patch-lhci-yaml.js
new file mode 100644
index 0000000000..0d7236a301
--- /dev/null
+++ b/tests/accessibility_tests/tooling/patch-lhci-yaml.js
@@ -0,0 +1,36 @@
+// LHCI 0.15.1 still calls safeLoad(), which js-yaml 4 renamed to load().
+// Upgrade the parser to remove its argparse 1 / sprintf-js dependency, then
+// adapt this single call in the installed, pinned upstream package. Keeping
+// the normal CLI entrypoint also covers autorun's child processes.
+// Remove this patch when an upstream LHCI release supports js-yaml 4.
+import { createHash } from 'node:crypto';
+import { readFileSync, writeFileSync } from 'node:fs';
+import { createRequire } from 'node:module';
+
+const ORIGINAL_SHA256 = '904e3eb32708ed0171dc17b1d11e0bebfd76765bd310af2060dc1b50d2f033fc';
+const PATCHED_SHA256 = '3f3bbc4e2b2f1b7b22ff2b8ed013322f3b7b5bfb7cf296fbb7605a6570b6e493';
+
+function patchInstalledLhci() {
+ const require = createRequire(import.meta.url);
+ const cliRequire = createRequire(require.resolve('@lhci/cli/package.json'));
+ const utilsRequire = createRequire(cliRequire.resolve('@lhci/utils/package.json'));
+ if (cliRequire('./package.json').version !== '0.15.1' ||
+ utilsRequire('./package.json').version !== '0.15.1' ||
+ !utilsRequire('js-yaml/package.json').version.startsWith('4.')) {
+ throw new Error('Review the LHCI YAML compatibility patch before changing tool versions');
+ }
+
+ const filename = utilsRequire.resolve('./src/lighthouserc.js');
+ const source = readFileSync(filename, 'utf8');
+ const digest = createHash('sha256').update(source).digest('hex');
+ if (digest === PATCHED_SHA256) return;
+ if (digest !== ORIGINAL_SHA256) {
+ throw new Error('Unexpected LHCI configuration loader; refusing to patch unknown source');
+ }
+
+ writeFileSync(filename, source.replace('return yaml.safeLoad(contents);', 'return yaml.load(contents);'));
+}
+
+// Lockfile-only updates do not install a dependency tree. npm ci applies the
+// patch later, including in the automated dependency-update workflow.
+if (process.env.npm_config_package_lock_only !== 'true') patchInstalledLhci();