angular / angular/angular-cli

Manually execute `ng new` deps postinstall scripts

未關閉
#22,013 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
area: @schematics/angular feature feature: insufficient votes severity6: security
主要語言
TypeScript
星號
27k
分支
11.8k
平均合併
14 小時 23 分鐘
30 天內合併 PR
162

描述

# 🚀 Feature request

### Command (mark with an `x`)

- [X] new

### Description

Currently, `ng new` will automatically run `npm install` which (if the user has not disabled it), automatically runs all postinstall scripts. This can be a vulnerability since any compromised package in the NPM dependency graph could add a postinstall step to install malware on developer machines.

### Describe the solution you'd like

We could reduce the attack surface by disabling postinstall on the automatic `npm install` and then manually invoke the postinstall for a known set of required packages. Only 3 packages currently use postinstall steps, so limiting execution to just those would significantly reduce the attack surface for a potential supply chain attack.

One possible concern is for dependencies which add a required postinstall step in the future. We can pretty easily add a test to make sure we aren't missing any postinstall steps from our transitive dependencies, though this inherently breaks abstraction somewhat. Adding a postinstall step is (somewhat debate-ably) a breaking change, so any package which adds one in the future should require a major version bump where we have an opportunity to allowlist it.

The one edge case I can think of is if we have:

```
ng-new-app@0.0.0 -> package-a@^1.0.0 -> package-b@^1.0.0
```

And `package-b` gets a new postinstall step in `v2.0.0`. However, `package-a` may be able to manage the breakage without violating their own public API (or maybe doesn't notice the new postinstall step) and simply bumps to `v1.0.1`. This would immediately be pulled in to the next `ng new` command and fail. I think such a scenario would actually be a bad patch release for `package-a`, since adding a required postinstall step is fundamentally a breaking change. We would rely on NPM package maintainers to make the right semver-compatible decisions for a somewhat nuanced case, but this is probably better than the alternative.

貢獻指南

開啟貢獻指南

研究方向

首先檢查會自動執行 npm install 的 ng new 流程,並確認目前如何處理 postinstall 指令碼。完成標準是停用廣泛的自動 postinstall 執行,只呼叫必要的已知套件,並新增用於偵測缺少 postinstall 相依性的覆蓋測試。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
typescript
領域
cli, security
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。