所以,到目前为止,似乎还没有yarn audit --fix,所以我正在尝试找出如何修复我的yarn audit错误。
我已经尝试了一个yarn upgrade,它已经修复了一些错误(这很棒),但仍然有几个剩余。
然后,我尝试了一个针对剩余高漏洞的yarn add <package>@latest,但它升级了我的package.json中的版本,当我认为问题来自于我正在使用的包的依赖项时。
下面是我剩余的一些错误的例子:
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high │ Regular Expression Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=3.0.2 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ gulp > vinyl-fs > glob-stream > glob > minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/118 │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high │ Regular Expression Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=3.0.2 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ gulp > vinyl-fs > glob-stream > minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/118 │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high │ Regular Expression Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=3.0.2 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ gulp > vinyl-fs > glob-watcher > gaze > globule > glob > │
│ │ minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/118 │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high │ Regular Expression Denial of Service │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=3.0.2 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ gulp > vinyl-fs > glob-watcher > gaze > globule > minimatch │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/118 │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ moderate │ Prototype Pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ lodash │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=4.17.11 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ gulp │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ gulp > vinyl-fs > glob-watcher > gaze > globule > lodash │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/782 │
└───────────────┴──────────────────────────────────────────────────────────────┘发布于 2019-07-16 19:41:59
yarn中这个问题的解决方案被称为selective version resolutions,它基本上是为package.json中的传递依赖项定义resolutions。
transitive dependencies是依赖项的依赖项。
{
"resolutions": { "**/**/lodash": "^4.17.12" }
}因此,在这里,即使lodash不是包的直接依赖项,包中的依赖包也会使用解析中定义的版本。还可以提供特定的分辨率。更多信息here。
发布于 2020-03-24 22:01:38
虽然resolutions可以工作,但它不是最佳解决方案,因为:
你用传递性dependencies
A依赖于B@^4.0.0,您更新B并将其解析为^4.3.2。一段时间后,A获得更新并需要B@^5.0.0,但您仍然将B解析为^4.3.2,这不再兼容。这里的是更新传递依赖关系的另一种方法:
从yarn.lock
yarn install中删除要更新的依赖项版本的
通过这种方式,您可以强制yarn再次解析依赖项,并且在大多数情况下,yarn将安装您从yarn.lock中删除的内容的更新版本。
示例:让我们假设您想要更新易受攻击的minimist@0.0.8,然后您需要从yarn.lock中删除一个如下所示的条目
minimist@0.0.8:
version "0.0.8"
resolved "http://10.0.0.1/repository/npm-registry/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=然后运行yarn install。
如果这不起作用,请使用:
尝试更新依赖关系链中较高的依赖关系:
yarn why <dependency>找出哪些包拉动了yarn.lock中删除链中较高的依赖项,然后运行yarn install示例:
下面是一个示例,其中我们更新了一个可传递依赖项minimist
$ yarn why minimist
.....
=> Found "mkdirp#minimist@0.0.8"
info This module exists because "eslint#mkdirp" depends on it.
=> Found "optimist#minimist@0.0.10"
info This module exists because "jest#jest-cli#@jest#core#@jest#reporters#istanbul-reports#handlebars#optimist" depends on it.
.....minimist中删除yarn.lock条目并运行yarn install ->这没有帮助,可能是因为mkdirp和optimist再次需要minimist@0.0.8和minimist的“直接父代”:yarn.lock:mkdirp和code yarn why minimist:$ yarn为什么极简主义.....=>找到"mkdirp#minimist@1.2.5“信息此模块之所以存在,是因为"eslint#mkdirp”依赖于它。因为"jest#jest-cli#@jest#core#@jest#reporters#istanbul-reports#handlebars#optimist“依赖于此模块,所以=>找到了"optimist#minimist@0.0.10”信息。.
在这里,我们看到minimist@0.0.8已更新为minimist@1.2.5,但minimist@0.0.10仍然更改了依赖链中的下一个依赖项:handlebars
yarn install
yarn.lock- nothing yarn why minimist -nothing changed,minimist@0.0.10仍然不存在链中的下一个依赖项yarn.lock:istanbul-reports
yarn install
yarn why minimist:minimist@0.0.10不再存在,因为<代码>D89已更新。<代码>H290<代码>G291https://stackoverflow.com/questions/55131928
复制相似问题