Skip to content

Manually execute ng new deps postinstall scripts聽#22013

Description

@dgp1130

馃殌 Feature request

Command (mark with an 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.

Activity

  1. added this to the Backlog milestone on Oct 26, 2021
  2. dgp1130 commented on Nov 23, 2021

    @dgp1130
    CollaboratorAuthor

    One other point to consider is that I think this would only help for the automatic npm install in ng new. Any subsequent npm install executions would be just as vulnerable as normal (and are the vast majority of installs). We could generate a project with ignore-scripts, which would mitigate this issue for following npm install runs, but we also want to have a hook to execute allowlisted, legitimate postinstall usages (such as ESBuild). If the user is directly invoking npm install, we have no means of directly invoking postinstall for legitimate packages. Also users could add new packages with postinstall in the future which we can't know about in advance.

    Ideally there would be some kind of feature for allowlisting postinstall packages in NPM which Angular could use to curate our own set of transitive dependencies, but I'm not aware of such a feature. As it stands the impact of this change would be relatively low since it only applies to ng new, not applications after the initial scaffolding.

  3. angular-robot commented on Feb 1, 2022

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  4. modified the milestones: Backlog, needsTriage on Feb 1, 2022
  5. angular-robot commented on Feb 22, 2022

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  6. added
    feature: insufficient votesLabel to add when the not a sufficient number of votes or comments from unique authors
    and removed
    feature: votes requiredFeature request which is currently still in the voting phase
    on Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions