Skip to content

Commit 035ed49

Browse files
jespinoona-agent
andcommitted
Move npx disable from Dockerfile to postCreateCommand
Move the npx disabling logic to postCreateCommand in devcontainer.json to ensure npx gets disabled after the container is fully set up. Co-authored-by: Ona <[email protected]>
1 parent f3c0ab0 commit 035ed49

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) && sudo rm -f \"$NPX_PATH\" && echo '#!/bin/sh' | sudo tee \"$NPX_PATH\" > /dev/null && echo 'echo \"npx is disabled for security reasons. Use explicit package installation instead.\" >&2' | sudo tee -a \"$NPX_PATH\" > /dev/null && echo 'exit 1' | sudo tee -a \"$NPX_PATH\" > /dev/null && sudo chmod +x \"$NPX_PATH\" && yarn install --frozen-lockfile",
1212
"customizations": {
1313
"vscode": {
1414
"extensions": ["esbenp.prettier-vscode"]

0 commit comments

Comments
 (0)