-
Notifications
You must be signed in to change notification settings - Fork 0
Fix path traversal vulnerability in setup script dependency removal #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e706f6b
4a958eb
ee399d2
4733bf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |||||||||||||||||||||||||
| import { $ } from "bun"; | ||||||||||||||||||||||||||
| import { existsSync, rmSync } from "fs"; | ||||||||||||||||||||||||||
| import { mkdir, writeFile } from "fs/promises"; | ||||||||||||||||||||||||||
| import { join } from "path"; | ||||||||||||||||||||||||||
| import { join, resolve } from "path"; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const ROOT_DIR = join(import.meta.dir, ".."); | ||||||||||||||||||||||||||
| const ATOM_TRAIL_DIR = join(ROOT_DIR, ".atom-trail"); | ||||||||||||||||||||||||||
|
|
@@ -101,8 +101,17 @@ async function installDependencies(force: boolean): Promise<boolean> { | |||||||||||||||||||||||||
| const nodeModulesPath = join(ROOT_DIR, "node_modules"); | ||||||||||||||||||||||||||
| if (force) { | ||||||||||||||||||||||||||
| log("step", "Force reinstalling dependencies..."); | ||||||||||||||||||||||||||
| // Validate path before removal for safety | ||||||||||||||||||||||||||
| if (existsSync(nodeModulesPath) && nodeModulesPath.endsWith("node_modules")) { | ||||||||||||||||||||||||||
| // Validate path before removal for security | ||||||||||||||||||||||||||
| // Ensure the resolved path is within the project directory | ||||||||||||||||||||||||||
| const resolvedNodeModules = resolve(nodeModulesPath); | ||||||||||||||||||||||||||
| const resolvedRoot = resolve(ROOT_DIR); | ||||||||||||||||||||||||||
| const expectedPath = resolve(resolvedRoot, "node_modules"); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Check that the resolved path exactly matches the expected node_modules path | ||||||||||||||||||||||||||
| // This prevents path traversal attacks (e.g., /etc/node_modules) | ||||||||||||||||||||||||||
| const isValidPath = resolvedNodeModules === expectedPath; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+107
to
+113
|
||||||||||||||||||||||||||
| const resolvedRoot = resolve(ROOT_DIR); | |
| const expectedPath = resolve(resolvedRoot, "node_modules"); | |
| // Check that the resolved path exactly matches the expected node_modules path | |
| // This prevents path traversal attacks (e.g., /etc/node_modules) | |
| const isValidPath = resolvedNodeModules === expectedPath; | |
| const expectedPath = resolve(ROOT_DIR, "node_modules"); | |
| // Check that the resolved path exactly matches the expected node_modules path | |
| // This prevents path traversal attacks (e.g., /etc/node_modules) | |
| const isValidPath = resolvedNodeModules === expectedPath; |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This security-critical path validation logic lacks test coverage. Given that this fix addresses a path traversal vulnerability, it should include tests that verify:
- The validation correctly accepts valid paths (e.g.,
ROOT_DIR/node_modules) - The validation correctly rejects malicious paths (e.g.,
/etc/node_modules,../../../etc/node_modules) - Edge cases are handled (symlinks, Windows paths, relative paths)
The repository has comprehensive test coverage for other packages (e.g., quantum-ethics), so adding tests for this security fix would be consistent with the project's testing practices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Ensure the resolved path is within the project directory" but the validation actually checks for exact path equality, not containment. Consider updating the comment to be more accurate:
"Ensure the resolved path exactly matches the expected node_modules location"
This better reflects that the code validates exact equality rather than directory containment.