A postinstall script is a script that a package manager, such as npm, runs automatically after installing a package. Developers use it for legitimate tasks such as compiling native code, downloading required binaries or setting up configuration. Because it runs without a separate prompt, it executes with the permissions of the user or build process that did the installation.
This makes it an attractive route for supply-chain attacks. A malicious or compromised package can use a postinstall script to run code on developers' machines or build servers as soon as it is installed, possibly stealing secrets such as tokens and keys that are available in that environment.
Not every package with such a script is dangerous, and many popular packages use them for ordinary reasons. Disabling them can also break packages that really need a build step, so it is a trade-off.
To reduce the risk, install only packages you trust, pin versions and use lock files, review new or changed dependencies, and consider running installs with scripts disabled where your tools allow it, such as the ignore-scripts option in npm. Run builds with limited credentials and avoid exposing long-lived secrets to install steps.