【问题标题】:Vulnerabilities when installing axios安装axios时的漏洞
【发布时间】:2021-10-14 13:20:24
【问题描述】:

我刚刚开始学习 node 并从 Udemy 上的一门课程中做出反应(课程于去年上传 - 2020 年)。我知道,当我尝试做同样的事情时,导师使用的代码可能已经过时了,但除了尝试安装 axios 之外,我没有收到任何安装任何东西的漏洞。我已经在全球范围内安装了 npm,创建了一个 react 应用程序(create-react-app)并使用了 express,所有这些都可以正常工作。安装 axios 时我缺少什么吗?

这是我得到的错误:

npm WARN @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.15.4 requires a peer of @babel/core@^7.13.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ axios@0.23.0
updated 1 package and audited 1911 packages in 10.84s

153 packages are looking for funding
  run `npm fund` for details        

found 27 vulnerabilities (8 moderate, 18 high, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

它说尝试运行npm audit fix,但是当我这样做时,它说我必须手动修复这些问题。 Axios 确实存在于我的 package.json 中。

"dependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "axios": "^0.23.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.1.2"
  }

这些只是依赖项。我需要修复这些漏洞,还是我的程序会继续正常运行?

【问题讨论】:

  • Axios 0.23 没问题。如果你使用 create-react-app,你会遇到 npm audit 的警告和问题。这是 Facebook 负责 create-react-app 的 React 负责人的一篇文章,解释了原因:overreacted.io/npm-audit-broken-by-design
  • 所以我不用担心有什么损坏?我之所以担心,是因为一年前我正在上一门这样的课程(一门 React Native 课程),当一个组件失败时,我不知道该怎么办。
  • 我建议忽略这些警告并专注于您的课程作业。只有当您计划发布到生产环境时,警告才会成为问题,即便如此,它们也是逐案发生的。

标签: node.js reactjs npm axios


【解决方案1】:

您看到的错误不是来自 axios,而是来自 npm audit 报告来自 create-react-app 的错误,尤其是 react-scripts 包。如果您将 create-react-app 用于课程作业,这些错误不会影响您的项目,因为它们与安全性相关,而不是功能性。

如果您计划将此项目发布到生产环境,我建议您考虑以下因素来评估错误:

  • 我的项目需要有多安全?我在写入来自互联网的数据吗?
  • 这是 jest 等开发人员工具的错误,还是 express 等应用程序的一部分?
  • 如果需要通过强大的验证工具实现高安全性,是时候放弃 create-react-app 了吗?

npm audit 目前的状态在开发者中是有争议的。这是一种有价值的免费安全扫描,但更复杂的工具(如 snyk)和其他付费工具通常在大公司中使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-26
    • 2021-12-04
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    相关资源
    最近更新 更多