Skip to content

fix: path traversal via crafted filenames + command injection in --open#96

Open
JasonOA888 wants to merge 1 commit into
browserbase:mainfrom
JasonOA888:fix/path-traversal-command-injection-compile-report
Open

fix: path traversal via crafted filenames + command injection in --open#96
JasonOA888 wants to merge 1 commit into
browserbase:mainfrom
JasonOA888:fix/path-traversal-command-injection-compile-report

Conversation

@JasonOA888
Copy link
Copy Markdown

@JasonOA888 JasonOA888 commented May 5, 2026

Two vulnerabilities in company-research and event-prospecting compile_report.mjs.

1. Path traversal via crafted .md filenames

The slug is derived directly from the markdown filename:

const slug = file.replace('.md', '');

A crafted filename like ../../etc/evil.md produces slug ../../etc/evil. When passed to:

writeFileSync(join(dir, 'companies', `${slug}.html`), companyHtml)

This resolves to a path outside the output directory (e.g. /tmp/etc/evil.html). The slug is also interpolated unsanitized into <a href="companies/${c.slug}.html">, allowing arbitrary href injection in the generated HTML.

Fix: Strip .., /, and \ from the slug after the .md removal.

2. Command injection via --open

execSync(`open "${join(dir, 'index.html')}"`)

The dir argument comes from process.argv[2]. If it contains $(cmd) or `cmd`, bash executes the command inside the double-quoted template literal.

Fix: Use execFileSync('open', [path]) which passes arguments directly to the executable without shell interpolation — the same pattern used by evaluate.mjs for browse commands.


9 lines changed across 2 files.


Note

Medium Risk
Touches security-sensitive file-path and process-invocation code paths; while the changes are small, they affect how output filenames/links are generated and how the report is launched.

Overview
Closes two injection vectors in the compile_report.mjs scripts for company-research and event-prospecting.

Company page slug values derived from .md filenames are now sanitized to strip .. and path separators, preventing path traversal (and related link/attribute injection) when generating per-company HTML files.

The --open option now uses execFileSync('open', [path]) instead of shelling out via execSync, avoiding shell interpolation/command injection via a crafted output directory.

Reviewed by Cursor Bugbot for commit d396a82. Bugbot is set up for automated code reviews on this repo. Configure here.

…--open

Two vulnerabilities across company-research and event-prospecting
compile_report.mjs:

1. Path traversal: slug is derived directly from the markdown filename
   via file.replace('.md', ''). A crafted filename like
   "../../etc/evil.md" produces slug "../../etc/evil" which, when
   passed to join(dir, 'companies', `${slug}.html`), writes outside
   the intended output directory. Fix: strip ../ and path separators
   from the slug before use.

2. Command injection (--open): execSync(`open "${path}"`) passes
   the user-provided directory name through a shell. Directory names
   containing $(cmd) or `cmd` are executed by bash inside the
   double-quoted string. Fix: use execFileSync('open', [path]) which
   bypasses shell interpolation entirely.
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.

1 participant