Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow scripts related checks. #70

Merged
merged 7 commits into from
Mar 28, 2024
Merged

allow scripts related checks. #70

merged 7 commits into from
Mar 28, 2024

Conversation

kanthesha
Copy link
Contributor

We want to make sure that for a given project:

  • The project contains @lavamoat/allow-scripts and @lavamoat/preinstall-always-fail as dev dependencies, and the versions match the same dev dependencies as in the module template.
  • The project's package.json contains a lavamoat field with an allowScripts field inside of it, and this file contains "@lavamoat/preinstall-always-fail": false.
  • If the project has a .yarnrc.yml (Yarn Modern), then it has a enableScripts: false.
  • If the project has a .yarnrc.yml file, then .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs is present and its content matches the same file as in the module template; additionally, .yarnrc.yml's plugins field contains the object { path: ".yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs", spec: "https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js" }.

Copy link

socket-security bot commented Mar 21, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/auto-changelog@3.4.2 None +1 558 kB metamaskbot
npm/@metamask/eslint-config-jest@12.0.0 None 0 8.51 kB metamaskbot
npm/@metamask/eslint-config-typescript@12.0.0 None 0 18.3 kB metamaskbot
npm/@metamask/utils@8.3.0 Transitive: environment, network +21 4.49 MB metamaskbot
npm/@swc/cli@0.1.62 environment, filesystem Transitive: network, shell +73 2.78 MB kdy1
npm/@swc/core@1.3.66 environment, filesystem, shell +1 33.3 MB kdy1
npm/@types/jest@28.1.7 Transitive: environment +8 541 kB types
npm/@types/lodash@4.14.202 None 0 862 kB types
npm/@types/node@16.18.31 None 0 3.46 MB types
npm/@typescript-eslint/eslint-plugin@5.43.0 Transitive: environment, filesystem +12 4.47 MB jameshenry
npm/@typescript-eslint/parser@5.43.0 Transitive: environment, filesystem +8 1.61 MB jameshenry
npm/depcheck@1.4.3 filesystem, unsafe Transitive: environment, eval +26 12.3 MB rumpl
npm/eslint-plugin-jest@27.2.2 filesystem Transitive: environment +11 2.99 MB simenb
npm/eslint@8.44.0 environment, filesystem +10 4.1 MB eslintbot
npm/jest-it-up@2.0.2 filesystem Transitive: environment, shell +4 306 kB rbardini
npm/prettier-plugin-packagejson@2.3.0 Transitive: filesystem +11 327 kB matzkoh
npm/ts-node@10.7.0 environment, filesystem, unsafe +7 831 kB cspotcode
npm/typedoc@0.23.15 environment, filesystem, shell, unsafe Transitive: network +5 10.7 MB typedoc-bot
npm/yaml@2.4.1 environment 0 671 kB eemeli

🚮 Removed packages: npm/@ampproject/remapping@2.3.0, npm/@babel/code-frame@7.24.2, npm/@babel/compat-data@7.24.1, npm/@babel/core@7.24.3, npm/@babel/generator@7.24.1, npm/@babel/helper-compilation-targets@7.23.6, npm/@babel/helper-module-imports@7.24.3, npm/@babel/helper-module-transforms@7.23.3, npm/@babel/helper-plugin-utils@7.24.0, npm/@babel/helper-string-parser@7.24.1, npm/@babel/helper-validator-option@7.23.5, npm/@babel/helpers@7.24.1, npm/@babel/highlight@7.24.2, npm/@babel/parser@7.24.1, npm/@babel/plugin-syntax-typescript@7.24.1, npm/@babel/template@7.24.0, npm/@babel/traverse@7.24.1, npm/@babel/types@7.24.0, npm/@eslint-community/regexpp@4.10.0, npm/@eslint/eslintrc@2.1.4, npm/@eslint/js@8.57.0, npm/@humanwhocodes/config-array@0.11.14, npm/@humanwhocodes/object-schema@2.0.2, npm/@jridgewell/gen-mapping@0.3.5, npm/@jridgewell/resolve-uri@3.1.2, npm/@jridgewell/set-array@1.2.1, npm/@jridgewell/trace-mapping@0.3.25, npm/@lavamoat/aa@3.1.5, npm/@lavamoat/allow-scripts@2.5.1, npm/@lavamoat/preinstall-always-fail@1.0.3, npm/@metamask/utils@8.4.0, npm/@noble/curves@1.3.0, npm/@noble/hashes@1.4.0, npm/@npmcli/fs@2.1.2, npm/@npmcli/move-file@2.0.1, npm/@scure/base@1.1.6, npm/@scure/bip32@1.3.3, npm/@scure/bip39@1.2.2, npm/@sinclair/typebox@0.24.51, npm/@sinonjs/commons@1.8.6, npm/@swc/cli@0.1.65, npm/@swc/core-darwin-arm64@1.4.11, npm/@swc/core-darwin-x64@1.4.11, npm/@swc/core-linux-arm-gnueabihf@1.4.11, npm/@swc/core-linux-arm64-gnu@1.4.11, npm/@swc/core-linux-arm64-musl@1.4.11, npm/@swc/core-linux-x64-gnu@1.4.11, npm/@swc/core-linux-x64-musl@1.4.11, npm/@swc/core-win32-arm64-msvc@1.4.11, npm/@swc/core-win32-ia32-msvc@1.4.11, npm/@swc/core-win32-x64-msvc@1.4.11, npm/@swc/core@1.4.11, npm/@tsconfig/node10@1.0.10, npm/@tsconfig/node16@1.0.4, npm/@types/babel__core@7.20.5, npm/@types/babel__generator@7.6.8, npm/@types/babel__template@7.4.4, npm/@types/babel__traverse@7.20.5, npm/@types/debug@4.1.12, npm/@types/graceful-fs@4.1.9, npm/@types/http-cache-semantics@4.0.4, npm/@types/istanbul-lib-coverage@2.0.6, npm/@types/istanbul-lib-report@3.0.3, npm/@types/istanbul-reports@3.0.4, npm/@types/json-schema@7.0.15, npm/@types/lodash@4.17.0, npm/@types/ms@0.7.34, npm/@types/node@16.18.91, npm/@types/parse-json@4.0.2, npm/@types/prettier@2.7.3, npm/@types/responselike@1.0.3, npm/@types/semver@7.5.8, npm/@types/stack-utils@2.0.3, npm/@types/yargs-parser@21.0.3, npm/@types/yargs@17.0.32, npm/@typescript-eslint/eslint-plugin@5.62.0, npm/@typescript-eslint/parser@5.62.0, npm/@typescript-eslint/scope-manager@5.62.0, npm/@typescript-eslint/type-utils@5.62.0, npm/@typescript-eslint/types@5.62.0, npm/@typescript-eslint/typescript-estree@5.62.0, npm/@typescript-eslint/utils@5.62.0, npm/@typescript-eslint/visitor-keys@5.62.0, npm/@vue/compiler-core@3.4.21, npm/@vue/compiler-dom@3.4.21, npm/@vue/compiler-sfc@3.4.21, npm/@vue/compiler-ssr@3.4.21, npm/@vue/shared@3.4.21, npm/acorn-walk@8.3.2, npm/acorn@8.11.3, npm/agentkeepalive@4.5.0, npm/array-buffer-byte-length@1.0.1, npm/array-includes@3.1.8, npm/array.prototype.flat@1.3.2, npm/array.prototype.flatmap@1.3.2, npm/available-typed-arrays@1.0.7, npm/bin-version-check@5.1.0, npm/browserslist@4.23.0, npm/cacache@16.1.3, npm/call-bind@1.0.7, npm/caniuse-lite@1.0.30001600, npm/ci-info@3.9.0, npm/cjs-module-lexer@1.2.3, npm/cli-spinners@2.9.2, npm/cmd-shim@6.0.2, npm/collect-v8-coverage@1.0.2, npm/convert-source-map@1.9.0, npm/debug@2.6.9, npm/deepmerge@4.3.1, npm/define-properties@1.2.1, npm/diff@5.2.0, npm/electron-to-chromium@1.4.717, npm/es-abstract@1.23.2, npm/es-set-tostringtag@2.0.3, npm/es-shim-unscopables@1.0.2, npm/escalade@3.1.2, npm/eslint-config-prettier@8.10.0, npm/eslint-import-resolver-node@0.3.9, npm/eslint-module-utils@2.8.1, npm/eslint-plugin-import@2.29.1, npm/eslint-plugin-jest@27.9.0, npm/eslint-visitor-keys@3.4.3, npm/eslint@8.57.0, npm/ethereum-cryptography@2.1.3, npm/fast-diff@1.3.0, npm/fast-glob@3.3.2, npm/fastq@1.17.1, npm/flat-cache@3.2.0, npm/flatted@3.3.1, npm/fsevents@2.3.3, npm/function-bind@1.1.2, npm/function.prototype.name@1.1.6, npm/get-intrinsic@1.2.4, npm/get-symbol-description@1.0.2, npm/graceful-fs@4.2.11, npm/has-property-descriptors@1.0.2, npm/has-proto@1.0.3, npm/has-tostringtag@1.0.2, npm/has@1.0.4, npm/ignore@5.3.1, npm/internal-slot@1.0.7, npm/is-array-buffer@3.0.4, npm/is-core-module@2.13.1, npm/is-negative-zero@2.0.3, npm/is-shared-array-buffer@1.0.3, npm/is-typed-array@1.1.13, npm/istanbul-lib-coverage@3.2.2, npm/istanbul-lib-instrument@5.2.1, npm/istanbul-lib-report@3.0.1, npm/istanbul-reports@3.1.7, npm/jest-pnp-resolver@1.2.3, npm/jsonc-parser@3.2.1, npm/keyv@4.5.4, npm/magic-string@0.30.8, npm/make-dir@4.0.0, npm/make-fetch-happen@10.2.1, npm/minimist@1.2.8, npm/minipass-fetch@2.1.2, npm/minipass@3.3.6, npm/nanoid@3.3.7, npm/node-gyp@9.4.1, npm/node-releases@2.0.14, npm/object-inspect@1.13.1, npm/object.assign@4.1.5, npm/object.values@1.2.0, npm/postcss@8.4.38, npm/prettier-plugin-packagejson@2.4.12, npm/punycode@2.3.1, npm/readable-stream@3.6.2, npm/regexp.prototype.flags@1.5.2, npm/resolve.exports@1.1.1, npm/safe-regex-test@1.0.3, npm/semver-truncate@3.0.0, npm/semver@7.6.0, npm/shiki@0.14.7, npm/side-channel@1.0.6, npm/socks@2.8.1, npm/sort-package-json@2.8.0, npm/source-map-js@1.2.0, npm/spdx-exceptions@2.5.0, npm/spdx-license-ids@3.0.17, npm/stack-utils@2.0.6, npm/string.prototype.trim@1.2.9, npm/string.prototype.trimend@1.0.8, npm/string.prototype.trimstart@1.0.8, npm/superstruct@1.0.4, npm/tar@6.2.1, npm/ts-node@10.9.2, npm/tsconfig-paths@3.15.0, npm/tslib@2.6.2, npm/typed-array-length@1.0.6, npm/unique-filename@2.0.1, npm/unique-slug@3.0.0, npm/v8-to-istanbul@9.2.0, npm/which-typed-array@1.1.15

View full report↗︎

Copy link

socket-security bot commented Mar 21, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSource
Install scripts npm/@lavamoat/preinstall-always-fail@1.0.0
  • Install script: preinstall
  • Source: echo "Don't run npm lifecycle scripts by default, whitelist them with @lavamoat/allow-scripts" && exit 1
  • orphan: npm/@lavamoat/preinstall-always-fail@1.0.0
New author npm/kind-of@6.0.3
  • orphan: npm/kind-of@6.0.3
Shell access npm/open@8.4.2
  • orphan: npm/open@8.4.2
Network access npm/mz@2.7.0
  • orphan: npm/mz@2.7.0
Shell access npm/mz@2.7.0
  • orphan: npm/mz@2.7.0
New author npm/unique-slug@2.0.2
Install scripts npm/esbuild@0.18.20
  • orphan: npm/esbuild@0.18.20
Shell access npm/esbuild@0.18.20
  • orphan: npm/esbuild@0.18.20
Network access npm/esbuild@0.18.20
  • orphan: npm/esbuild@0.18.20
Network access npm/esbuild@0.18.20
  • orphan: npm/esbuild@0.18.20
Shell access npm/foreground-child@3.1.1
  • orphan: npm/foreground-child@3.1.1
Shell access npm/foreground-child@3.1.1
  • orphan: npm/foreground-child@3.1.1
Mild CVE npm/semver@6.3.0
  • orphan: npm/semver@6.3.0
Mild CVE npm/semver@5.7.1
  • orphan: npm/semver@5.7.1
Shell access npm/tree-kill@1.2.2
  • orphan: npm/tree-kill@1.2.2
New author npm/json-parse-even-better-errors@3.0.0
  • orphan: npm/json-parse-even-better-errors@3.0.0
New author npm/fast-diff@1.2.0
  • orphan: npm/fast-diff@1.2.0
New author npm/source-map@0.8.0-beta.0
  • orphan: npm/source-map@0.8.0-beta.0
New author npm/@lavamoat/allow-scripts@2.3.1
  • orphan: npm/@lavamoat/allow-scripts@2.3.1
New author npm/fs-minipass@3.0.2
  • orphan: npm/fs-minipass@3.0.2
New author npm/which@3.0.0
New author npm/@npmcli/move-file@2.0.0
  • New Author: gar
  • Previous Author: nlf
New author npm/@npmcli/run-script@6.0.1

View full report↗︎

Next steps

What is an install script?

Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.

Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.

What is new author?

A new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.

Scrutinize new collaborator additions to packages because they now have the ability to publish code into your dependency tree. Packages should avoid frequent or unnecessary additions or changes to publishing rights.

What is shell access?

This module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.

Packages should avoid accessing the shell which can reduce portability, and make it easier for malicious shell access to be introduced.

What is network access?

This module accesses the network.

Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

What is a mild CVE?

Contains a low severity Common Vulnerability and Exposure (CVE).

Remove or replace dependencies that include known low severity CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/@lavamoat/preinstall-always-fail@1.0.0
  • @SocketSecurity ignore npm/kind-of@6.0.3
  • @SocketSecurity ignore npm/open@8.4.2
  • @SocketSecurity ignore npm/mz@2.7.0
  • @SocketSecurity ignore npm/unique-slug@2.0.2
  • @SocketSecurity ignore npm/esbuild@0.18.20
  • @SocketSecurity ignore npm/foreground-child@3.1.1
  • @SocketSecurity ignore npm/semver@6.3.0
  • @SocketSecurity ignore npm/semver@5.7.1
  • @SocketSecurity ignore npm/tree-kill@1.2.2
  • @SocketSecurity ignore npm/json-parse-even-better-errors@3.0.0
  • @SocketSecurity ignore npm/fast-diff@1.2.0
  • @SocketSecurity ignore npm/source-map@0.8.0-beta.0
  • @SocketSecurity ignore npm/@lavamoat/allow-scripts@2.3.1
  • @SocketSecurity ignore npm/fs-minipass@3.0.2
  • @SocketSecurity ignore npm/which@3.0.0
  • @SocketSecurity ignore npm/@npmcli/move-file@2.0.0
  • @SocketSecurity ignore npm/@npmcli/run-script@6.0.1

@kanthesha kanthesha marked this pull request as ready for review March 21, 2024 21:11
@kanthesha kanthesha requested a review from a team as a code owner March 21, 2024 21:11
Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me, just had some minor comments.

src/rules/package-allow-scripts-yarn-conform.ts Outdated Show resolved Hide resolved
src/repository-filesystem.ts Outdated Show resolved Hide resolved
src/rules/package-allow-scripts-yarn-conform.test.ts Outdated Show resolved Hide resolved
src/rules/package-allow-scripts-yarn-conform.ts Outdated Show resolved Hide resolved
src/rules/package-allow-scripts-yarn-plugins-conform.ts Outdated Show resolved Hide resolved
export default buildRule({
name: RuleName.PackageLavamoatAllowScriptsConforms,
description:
'Does lavamoat lists `@lavamoat/preinstall-always-fail: false` in allow scripts?',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just occurred to me that we include this package in the module template, but then immediately disable its functionality. That seems odd to me. I've raised a question about this in chat to see if we still need this or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. similar thoughts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, it seems that we still want this.

Maybe, however, we can reword this to sound a little more natural?

Suggested change
'Does lavamoat lists `@lavamoat/preinstall-always-fail: false` in allow scripts?',
'Are postinstall scripts disabled for `@lavamoat/preinstall-always-fail`?',

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in this commit 9a6cd36

@kanthesha kanthesha self-assigned this Mar 26, 2024
Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@kanthesha kanthesha merged commit 6d17d3f into main Mar 28, 2024
23 of 24 checks passed
@kanthesha kanthesha deleted the allow-scripts-checks branch March 28, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add allow-scripts-related checks
2 participants