Skip to content

fix: prevent yarn directory traversal on plugin installation#6829

Merged
gatzjames merged 2 commits intoKong:developfrom
techchrism:fix/yarn-directory-traversal
Feb 7, 2025
Merged

fix: prevent yarn directory traversal on plugin installation#6829
gatzjames merged 2 commits intoKong:developfrom
techchrism:fix/yarn-directory-traversal

Conversation

@techchrism
Copy link
Copy Markdown
Contributor

fixes #4041 (and possibly others)

Yarn would previously traverse up the directory tree looking for a workspace package.json.
This PR prevents this behavior by writing a dummy package.json so yarn stops looking.

Solves errors that occur when a package.json exists in a parent directory (such as the user home directory or the root directory). Even when those errors don't occur, this may speed up execution very slightly by making fewer disk calls.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Nov 20, 2023

CLA assistant check
All committers have signed the CLA.

@techchrism
Copy link
Copy Markdown
Contributor Author

@gatzjames any reason in particular this was closed?
I still have people reporting an inability to install my plugin because of the underlying issue this PR fixes.
For another recent example from a repo that isn't mine, see jreyesr/insomnia-plugin-batch-requests#17

@gatzjames gatzjames reopened this Feb 7, 2025
@gatzjames gatzjames force-pushed the fix/yarn-directory-traversal branch from 35b0626 to 041913e Compare February 7, 2025 11:04
const tmpDir = path.join(electron.app.getPath('temp'), `${lookupName}-${Date.now()}`);
await mkdir(tmpDir, { recursive: true });
// Write a dummy package.json so that yarn doesn't traverse up the directory tree
await writeFile(path.join(tmpDir, 'package.json'), JSON.stringify({ license: 'ISC', workspaces: [] }), 'utf-8');

Check warning

Code scanning / Semgrep OSS

Semgrep Finding: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal

Detected possible user input going into a `path.join` or `path.resolve` function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.
@gatzjames
Copy link
Copy Markdown
Contributor

Thanks for the PR!
We were doing some cleanup and this was closed because the issue it references seemed to be resolved.

@gatzjames gatzjames enabled auto-merge (squash) February 7, 2025 11:12
@gatzjames gatzjames merged commit cf42d46 into Kong:develop Feb 7, 2025
pavkout pushed a commit to pavkout/insomnia that referenced this pull request Feb 17, 2025
* fix: prevent yarn directory traversal on plugin installation
fixes Kong#4041

* fix: fix code formatting in `install-plugin.ts`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed to install because "No license field"

4 participants