LoginSignup
3
1

More than 5 years have passed since last update.

Angularでtarの脆弱性(Arbitrary File Overwrite)を指摘されたので修正する

Last updated at Posted at 2019-05-06

概要

この記事ではAngularの新規プロジェクトを作成した所、tarの脆弱性(Arbitrary File Overwrite)を指摘されたので、その修正方法について説明します。

angular/cli のバージョン

$ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.3.8
Node: 10.8.0
OS: win32 x64
Angular: 7.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.8
@angular-devkit/build-angular     0.13.8
@angular-devkit/build-optimizer   0.13.8
@angular-devkit/build-webpack     0.13.8
@angular-devkit/core              7.3.8
@angular-devkit/schematics        7.3.8
@angular/cli                      7.3.8
@ngtools/webpack                  7.3.8
@schematics/angular               7.3.8
@schematics/update                0.13.8
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.29.0

Angularで新規プロジェクトを作成すると脆弱性が指摘される

新規プロジェクト作成

$ng new hoge
? Would you like to add Angular routing? No
? Which stylesheet format would you like to use? CSS

脆弱性が指摘される

found 1 high severity vulnerability

脆弱性の詳細を確認

npm audit で脆弱性の詳細を確認します。npm audit はインストールしたパッケージに対してセキュリティチェックを行い、脆弱性がある場合は詳細なレポートを表示してくれます。

$npm audit

                       === npm audit security report ===                        


                                 Manual Review                                  
             Some vulnerabilities require your attention to resolve             

          Visit https://go.npm.me/audit-guide for additional guidance           


  High            Arbitrary File Overwrite                                      

  Package         tar                                                           

  Patched in      >=4.4.2                                                       

  Dependency of   @angular-devkit/build-angular [dev]                           

  Path            @angular-devkit/build-angular > node-sass > node-gyp > tar

  More info       https://nodesecurity.io/advisories/803

found 1 high severity vulnerability in 42611 scanned packages
  1 vulnerability requires manual review. See the full report for details.

4.4.2より前のバージョンを使用していると任意のファイルに上書きされる脆弱性がtarにありました。tarのバージョンを上げて対応します。

node-gyp の package.json を開く

node_modules\node-gyp\package.json

tarのバージョンを上げる

変更前

"dependencies": {
  "tar": "^2.0.0"
},

変更後

"dependencies": {
  "tar": "^4.4.8"
},

パッケージを再度インストール

$npm install

パッケージの脆弱性を自動修復

npm audit fix はインストールしたパッケージの脆弱性を自動で修復してくれます。
今回の脆弱性の場合はnode-gypのpackage.jsonを手動で修正してから実行する必要があります。

$npm audit fix

脆弱性の確認

再度、セキュリティチェックを行うと脆弱性が解消されていることが確認できます。

$npm audit

                       === npm audit security report ===                        

found 0 vulnerabilities
 in 42604 scanned packages

参考

今回はこちらのstackoverflowを参考にして対応しました。
https://stackoverflow.com/questions/55635378/npm-audit-arbitrary-file-overwrite

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1