1.0.5 • Published 1 year ago

my-trusted-test v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

my-trusted-test

my-trusted-test 是一个颜色 npm 包 生命周期的各个阶段执行 npm 生命周期脚本。npm script 是如何触发这些生命周期事件的?

Scripts 生命周期: 此软件包包含以下npm生命周期脚本:

  • preinstall:在软件包安装开始之前触发。 "preinstall": "echo 'Trust preinstalling!' # (Running preinstall script)"
  • postinstall:在安装软件包后立即触发。 "postinstall": "echo 'Trust Installed!' # (Running postinstall script)"
  • preuninstall:在卸载软件包之前触发。 "preuninstall": "echo 'Trust preuninstalling!' # (Running preuninstall script)"
  • postuninstall:卸载软件包后触发。 "postuninstall": "echo 'Trust postuninstalling!' # (Running postuninstall script)"
  • prepare:在两种情况下触发:在本地安装软件包后(而不是通过注册表)和软件包打包和发布之前(例如,在npm publish或npm pack期间)。 "prepare": "echo 'Preparing Trust!' # (Running prepare script)"

安装使用

--foreground-scripts: 查看脚本执行情况和输出日志;

npm 7 以上的版本使用,出于安全考虑在前台控制台中,可能不会输出脚本执行日志,所以需要使用命令标识 --foreground-scripts 方便在前台的控制台中观察执行情况和输出日志。 npm i --foreground-scripts my-trusted-test

--ignore-scripts:忽略scripts生命脚本执行;

npm install --foreground-scripts --ignore-scripts my-trusted-test

禁止运行scripts的生命周期脚本的重要醒

在 npm 的包中,发现了很多恶意软件都是利用了 install scripts 的特性,这些脚本通常在未经过用户确认的情况下执行的。 因此允许 install scripts 可能会带来一些风险。

  • 修改和窃取数据: 可以利用 scripts 中的生命周期更改或者窃取用户可访问的文件;
  • 安装恶意软件:利用 scripts 中的生命周期特性,可以在未经过用户同意的情况下下载和安装其他恶意软件包或软件;
  • 未经授权访问系统资源: 利用 scripts 中的生命周期特性,可以利用 npm 的安装功能来执行一些恶意操作,例如访问系统资源、修改系统配置等。

建议

  • 在安装软件包的使用使用 --ignore-scripts: 这个命令选项可以避免 npm 执行安装脚本,从而避免可能存在的恶意软件。 npm install --ignore-scripts XXX
  • 继续禁用脚本: 可以在 .npmrc 文件中设置全局配置,以始终放置在npm安装期间执行脚本。 ignore-scripts=true
1.0.5

1 year ago

1.0.2

1 year ago

1.0.0

1 year ago