Skip to content

Commit f552353

Browse files
jespinoclaudejeanp413
authored
Block npx and disable npm scripts in devcontainer (#215)
* Block npx and disable npm scripts in devcontainer Add security hardening to the devcontainer by: - Disabling npx command to prevent arbitrary package execution - Setting ignore-scripts=true for npm and yarn to block lifecycle scripts This prevents potential security risks from running untrusted scripts during package installation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Replace npx puppeteer with global install in CI workflow Install puppeteer globally using npm -g before calling it directly, since npx is being disabled for security reasons. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * pin npm deps * Fix --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Jean Pierre <jeanp413@hotmail.com>
1 parent 2f574b0 commit f552353

File tree

7 files changed

+369
-17
lines changed

7 files changed

+369
-17
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// Use "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
88
// instead of the build to use a pre-built image.
99
"build": {
10-
"context": ".",
11-
"dockerfile": "Dockerfile"
10+
"context": "../dev",
11+
"dockerfile": "../dev/Dockerfile"
1212
},
1313
"features": {
1414
"ghcr.io/devcontainers/features/node:1": {
@@ -21,4 +21,4 @@
2121
}
2222
},
2323
"privileged": true
24-
}
24+
}

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
cache: "pnpm"
2020
- name: Install dependencies
2121
run: |
22-
pnpm install
23-
npx puppeteer browsers install
24-
cd test && pnpm install
22+
pnpm install --frozen-lockfile
23+
pnpm run puppeteer-install
24+
cd test && pnpm install --frozen-lockfile
2525
- name: Build the extension
2626
run: pnpm build
2727
- name: Run tests

dev/Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04
2+
3+
# Install Node.js and npm
4+
RUN apt-get update && apt-get install -y curl && \
5+
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
6+
apt-get install -y nodejs && \
7+
apt-get clean && rm -rf /var/lib/apt/lists/*
8+
9+
# Install global npm packages
10+
COPY npm-tools/package.json npm-tools/package-lock.json /opt/npm-tools/
11+
RUN cd /opt/npm-tools && \
12+
npm ci && \
13+
# Create symlinks for all binaries in node_modules/.bin
14+
for bin in /opt/npm-tools/node_modules/.bin/*; do \
15+
ln -sf "$bin" /usr/local/bin/$(basename "$bin"); \
16+
done && \
17+
# Cleanup npm cache
18+
rm -rf ~/.npm/_cacache
19+
20+
# Disable npm/yarn lifecycle scripts by default (security hardening)
21+
# To allow specific packages, use: npm rebuild <package> or yarn rebuild <package>
22+
RUN npm config set ignore-scripts true --location=user && \
23+
echo 'ignore-scripts true' >> ~/.yarnrc
24+
25+
# Disable npx (security hardening - prevents arbitrary package execution)
26+
RUN rm -f /usr/bin/npx /usr/local/bin/npx && \
27+
echo '#!/bin/sh' > /usr/local/bin/npx && \
28+
echo 'echo "npx is disabled for security reasons. Use explicit package installation instead." >&2' >> /usr/local/bin/npx && \
29+
echo 'exit 1' >> /usr/local/bin/npx && \
30+
chmod +x /usr/local/bin/npx

dev/npm-tools/package-lock.json

Lines changed: 322 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)