Skip to content

Commit a8a856d

Browse files
jespinoona-agent
andauthored
Disable npm lifecycle scripts and npx for security (#71)
* Disable npm lifecycle scripts and npx for security - Create Dockerfile with ignore-scripts configuration for npm/yarn - Disable npx with informative error message - Update devcontainer.json to use the new Dockerfile Fixes PDE-183 Co-authored-by: Ona <[email protected]> * Use dynamic npx path detection instead of hardcoded paths Replace hardcoded /usr/bin/npx and /usr/local/bin/npx with $(which npx) to handle different npx installation locations. Co-authored-by: Ona <[email protected]> * Trying with postCreateCommand Co-authored-by: Ona <[email protected]> --------- Co-authored-by: Ona <[email protected]>
1 parent f3c0ab0 commit a8a856d

File tree

2 files changed

+1
-8
lines changed

2 files changed

+1
-8
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,3 @@ FROM mcr.microsoft.com/devcontainers/typescript-node:latest
33
# Disable npm/yarn lifecycle scripts for security
44
RUN npm config set ignore-scripts true --location=user && \
55
echo 'ignore-scripts true' >> ~/.yarnrc
6-
7-
# Disable npx for security
8-
RUN rm -f /usr/bin/npx /usr/local/bin/npx && \
9-
echo '#!/bin/sh' > /usr/local/bin/npx && \
10-
echo 'echo "npx is disabled for security reasons. Use explicit package installation instead." >&2' >> /usr/local/bin/npx && \
11-
echo 'exit 1' >> /usr/local/bin/npx && \
12-
chmod +x /usr/local/bin/npx

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"features": {
99
"ghcr.io/devcontainers/features/node:1": {}
1010
},
11-
"postCreateCommand": "yarn install --frozen-lockfile",
11+
"postCreateCommand": "NPX_PATH=$(which npx) && rm -f \"$NPX_PATH\" && echo '#!/bin/sh' > \"$NPX_PATH\" && echo 'echo \"npx is disabled for security reasons. Use explicit package installation instead.\" >&2' >> \"$NPX_PATH\" && echo 'exit 1' >> \"$NPX_PATH\" && chmod +x \"$NPX_PATH\" && yarn install --frozen-lockfile",
1212
"customizations": {
1313
"vscode": {
1414
"extensions": ["esbenp.prettier-vscode"]

0 commit comments

Comments
 (0)