Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions scripts/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,11 @@ 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 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;

if (existsSync(nodeModulesPath) && isValidPath) {
rmSync(nodeModulesPath, { recursive: true, force: true });
// Validate path before removal for safety - ensure it resolves to expected location
const resolvedPath = resolve(nodeModulesPath);
Comment on lines +105 to +106
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison between resolvedPath and expectedPath is redundant. Since nodeModulesPath is already defined as join(ROOT_DIR, "node_modules") on line 101, calling resolve(nodeModulesPath) and resolve(ROOT_DIR, "node_modules") will always produce identical results. Both expressions are computing the same absolute path from the same inputs.

A more meaningful safety check would validate that the resolved path is within the project directory or matches a specific pattern, rather than comparing two computations of the same value.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

const expectedPath = resolve(ROOT_DIR, "node_modules");
if (existsSync(resolvedPath) && resolvedPath === expectedPath) {
rmSync(resolvedPath, { recursive: true, force: true });
}
await $`cd ${ROOT_DIR} && bun install`.quiet();
} else {
Expand Down
Loading