-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Description
Problem: Malicious packages
With the recent news of the event-stream/flatmap-stream attack (summary), it seems like now would be a good time to discuss defending against these kind of attacks.
Presently available defences:
- use a lockfile
- fully audit the published code of entire dependency tree
While a lockfile is generally good practice, it would require auditing to be effective. There lies the issue, auditing is not feasible. Dependency graphs are too large in most modern projects to effectively audit manually.
Suggestion
One defence is to introduce permissions for node core modules such as fs, http, process, and others.
A package.json would need to specify which core modules it uses, ex:
{
"name": "package-name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"permissions": [
"fs"
]
}
Restrict import/require such that requiring http in this package would throw an error, but fs would be permitted.
Each package would be provided a uniquely restricted import/require.
For backwards compatibility packages without a permissions, would be considered to have all permissions. This could be deprecated in favour of always requiring a permissions field.
Additionally tooling could be developed for package managers such as yarn and npm. Users could be alerted when permissions have changed anywhere in their dependency graph. Upon install of a dependency the user could be prompted with accepting the permissions for all packages added to the dependency graph.
This is not intended to eliminate the need for auditing, but could reduce the amount of packages needing audits to a reasonable level.
Outstanding Issues
- What to do with C++ addons? Being able to identify them as such may be enough, during install the user could be warned that module has full access to their system (equivalent to all permissions).
- Permissions of main package during development, build scripts, ect.
Other Defences
- Content security policy / sandboxing (restrict access to white-listed directories, and domains)