Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ ENV PATH=$PNPM_HOME:$PATH

RUN corepack enable

# The npm shipped in the base image bundles libraries with known vulnerabilities.
# Replace them with fixed versions from a separately locked installation.
COPY npm-security /tmp/npm-security
RUN npm ci --prefix /tmp/npm-security --ignore-scripts --no-audit --no-fund \
&& for m in balanced-match brace-expansion http-cache-semantics ip-address tar undici; do \
rm -rf "/usr/local/lib/node_modules/npm/node_modules/$m" \
&& cp -a "/tmp/npm-security/node_modules/$m" /usr/local/lib/node_modules/npm/node_modules/; \
done \
&& node /tmp/npm-security/verify.mjs \
&& rm -rf /tmp/npm-security /root/.npm

COPY --from=deps /repo /repo

WORKDIR /repo/docusaurus
Expand Down
131 changes: 131 additions & 0 deletions npm-security/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions npm-security/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "documentation-npm-security-dependencies",
"version": "1.0.0",
"private": true,
"dependencies": {
"brace-expansion": "5.0.12",
"http-cache-semantics": "4.3.0",
"ip-address": "10.7.4",
"tar": "7.5.22",
"undici": "6.29.1"
}
}
18 changes: 18 additions & 0 deletions npm-security/verify.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';

const root = process.argv[2] || '/usr/local/lib/node_modules/npm/node_modules';
const expected = {
'balanced-match': '4.0.4',
'brace-expansion': '5.0.12',
'http-cache-semantics': '4.3.0',
'ip-address': '10.7.4',
tar: '7.5.22',
undici: '6.29.1',
};

for (const [name, version] of Object.entries(expected)) {
const { version: actual } = JSON.parse(readFileSync(join(root, name, 'package.json'), 'utf8'));
if (actual !== version) throw new Error(`${name}@${actual} in npm, expected ${version}`);
console.log(`${name}@${actual}`);
}
Loading