arborist: sanitize packageName in path construction for linked strategy#9078
arborist: sanitize packageName in path construction for linked strategy#9078KevinZhao wants to merge 2 commits intonpm:latestfrom
Conversation
You're gonna need to undo this in order for us to review this. The cli has its own linting rules and linter. |
Add sanitizeName() to strip path traversal sequences from package names before using them in filesystem path construction. Applied at all 9 locations where packageName is interpolated into path.join() calls.
c2bdfde to
9469012
Compare
|
Done — force-pushed a clean commit. The diff now contains only the |
|
This problem is solved elsewhere by using @npmcli/name-from-folder. Our pretend nodes need this, and probably need a better |
Replace custom sanitizeName with @npmcli/name-from-folder to derive safe package names from filesystem paths instead of trusting package.json name field. This addresses path traversal via malicious packageName in isolated mode path construction. Per maintainer feedback: pretend nodes now get a better packageName getter using the existing @npmcli/name-from-folder dependency.
|
Thanks @wraithgar — rewritten to use The pretend node The diff is now just 3 lines changed (1 import + 2 logic changes) using the existing |
Summary
Add
sanitizeName()to strip path traversal sequences (../) from package names before using them in filesystem path construction inisolated-reifier.js.Package names from
package-lock.jsonare used directly inpath.join()calls, which resolves../sequences. This adds sanitization at all 9 locations wherepackageNameis interpolated into paths.Changes
sanitizeName()helper that replaces../with_and strips leading/getKey(),#generateChild(),#externalProxy(),#assignCommonProperties(),createIsolatedTree(),#processEdges(),#processDeps()Test plan
sanitizeName("../../../../tmp/foo")returns____tmp/foosanitizeName("@scope/name")returns@scope/name(scoped packages unaffected)sanitizeName("normal-package")returnsnormal-package(no-op for valid names)