Disable npm lifecycle scripts and npx for security#71
Merged
jespino merged 4 commits intoDec 10, 2025
Merged
Conversation
- 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 <no-reply@ona.com>
481ec5c to
f98e706
Compare
geropl
reviewed
Dec 8, 2025
geropl
reviewed
Dec 8, 2025
| echo 'ignore-scripts true' >> ~/.yarnrc | ||
|
|
||
| # Disable npx for security | ||
| RUN rm -f /usr/bin/npx /usr/local/bin/npx && \ |
Member
Contributor
Author
There was a problem hiding this comment.
I'm updating this here, and in other PRs
geropl
requested changes
Dec 8, 2025
Replace hardcoded /usr/bin/npx and /usr/local/bin/npx with $(which npx) to handle different npx installation locations. Co-authored-by: Ona <no-reply@ona.com>
…in-gitpod-sdk-typescript
geropl
reviewed
Dec 10, 2025
| echo 'echo "npx is disabled for security reasons. Use explicit package installation instead." >&2' >> /usr/local/bin/npx && \ | ||
| echo 'exit 1' >> /usr/local/bin/npx && \ | ||
| chmod +x /usr/local/bin/npx | ||
| RUN NPX_PATH=$(which npx) && \ |
Member
There was a problem hiding this comment.
I tested, and it seems it does not work - it seems features are installed after the docker image which also makes sense if you think about it.
Which means we either:
- have to resort to "postCreateCommand"
- or develop our own feature :(
#10 [dev_container_auto_added_stage_label 2/3] RUN npm config set ignore-scripts true --location=user && echo 'ignore-scripts true' >> ~/.yarnrc
#10 CACHED
#11 [dev_container_auto_added_stage_label 3/3] RUN bash -c '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"'
#11 DONE 0.2s
#12 [dev_containers_feature_content_normalize 1/2] COPY --from=dev_containers_feature_content_source devcontainer-features.builtin.env /tmp/build-features/
#12 DONE 0.0s
#13 [dev_containers_target_stage 1/4] RUN mkdir -p /tmp/dev-container-features
#13 DONE 0.2s
#14 [dev_containers_feature_content_normalize 2/2] RUN chmod -R 0755 /tmp/build-features/
#14 DONE 0.2s
#15 [dev_containers_target_stage 2/4] COPY --from=dev_containers_feature_content_normalize /tmp/build-features/ /tmp/dev-container-features
#15 DONE 0.0s
#16 [dev_containers_target_stage 3/4] RUN echo "_CONTAINER_USER_HOME=$( (command -v getent >/dev/null 2>&1 && getent passwd 'root' || grep -E '^root|^[^:]*:[^:]*:root:' /etc/passwd || true) | cut -d: -f6)" >> /tmp/dev-container-features/devcontainer-features.builtin.env && echo "_REMOTE_USER_HOME=$( (command -v getent >/dev/null 2>&1 && getent passwd 'node' || grep -E '^node|^[^:]*:[^:]*:node:' /etc/passwd || true) | cut -d: -f6)" >> /tmp/dev-container-features/devcontainer-features.builtin.env
#16 DONE 0.2s
#17 [dev_containers_target_stage 4/4] RUN --mount=type=bind,from=dev_containers_feature_content_source,source=node_0,target=/tmp/build-features-src/node_0 cp -ar /tmp/build-features-src/node_0 /tmp/dev-container-features && chmod -R 0755 /tmp/dev-container-features/node_0 && cd /tmp/dev-container-features/node_0 && chmod +x ./devcontainer-features-install.sh && ./devcontainer-features-install.sh && rm -rf /tmp/dev-container-features/node_0
#17 0.143 ===========================================================================
#17 0.143 Feature : Node.js (via nvm), yarn and pnpm
#17 0.143 Description : Installs Node.js, nvm, yarn, pnpm, and needed dependencies.
#17 0.143 Id : ghcr.io/devcontainers/features/node
#17 0.143 Version : 1.6.3
#17 0.143 Documentation : https://github.com/devcontainers/features/tree/main/src/node
#17 0.143 Options :
#17 0.143 VERSION="lts"
#17 0.143 NODEGYPDEPENDENCIES="true"
#17 0.143 NVMINSTALLPATH="/usr/local/share/nvm"
#17 0.143 PNPMVERSION="latest"
#17 0.143 NVMVERSION="latest"
#17 0.143 INSTALLYARNUSINGAPT="true"
#17 0.143 ===========================================================================
#17 0.376 NVM_VERSION=0.40.3
#17 0.566 NVM already installed.
#17 0.786 Downloading and installing node v24.11.1...
#17 0.905 Downloading https://nodejs.org/dist/v24.11.1/node-v24.11.1-linux-x64.tar.xz...
#17 1.139 Computing checksum with sha256sum
#17 1.171 Checksums matched!
#17 2.948 Now using node v24.11.1 (npm v11.6.2)
#17 3.070 Creating default alias: default -> lts/* (-> v24.11.1 *)
#17 3.170 default -> lts/* (-> v24.11.1 *)
#17 3.176 Yarn is already installed.
#17 3.467 npm warn using --force Recommended protections disabled.
#17 4.640
#17 4.640 added 1 package in 1s
#17 4.641
#17 4.641 1 package is looking for funding
#17 4.641 run `npm fund` for details
#17 4.687 Verifying node-gyp OS requirements...
#17 4.819 nvm cache cleared.
#17 4.890 Done!
``
Co-authored-by: Ona <no-reply@ona.com>
Contributor
Author
|
@geropl now, this is working |
geropl
approved these changes
Dec 10, 2025
geropl
approved these changes
Dec 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Disable npm/yarn lifecycle scripts and npx in the devcontainer for security.
Changes
.devcontainer/Dockerfilewith security configurations.devcontainer/devcontainer.jsonto use the new DockerfileSecurity configurations
npm config set ignore-scripts true- disables npm lifecycle scriptsignore-scripts truein.yarnrc- disables yarn lifecycle scriptsFixes PDE-183