Skip to content

Security: Unsafe File Write with User-Controlled Path#1099

Open
tomaioo wants to merge 1 commit into
reactjs:mainfrom
tomaioo:fix/security/unsafe-file-write-with-user-controlled-p
Open

Security: Unsafe File Write with User-Controlled Path#1099
tomaioo wants to merge 1 commit into
reactjs:mainfrom
tomaioo:fix/security/unsafe-file-write-with-user-controlled-p

Conversation

@tomaioo
Copy link
Copy Markdown

@tomaioo tomaioo commented May 25, 2026

Summary

Security: Unsafe File Write with User-Controlled Path

Problem

Severity: High | File: packages/react-docgen-cli/src/commands/parse/output/outputResult.ts:L8

The outputResult function writes to a file path specified by the output option without any validation. If an attacker can control the output parameter (e.g., via CLI --output flag), they could write files to arbitrary locations on the filesystem, potentially overwriting critical files or achieving remote code execution by overwriting executable files.

Solution

Validate and sanitize the output path to ensure it resolves within an expected output directory. Use path.resolve() and check that the resolved path starts with the allowed base directory. Consider using fs.realpath() to resolve symlinks before validation.

Changes

  • packages/react-docgen-cli/src/commands/parse/output/outputResult.ts (modified)

The `outputResult` function writes to a file path specified by the `output` option without any validation. If an attacker can control the `output` parameter (e.g., via CLI `--output` flag), they could write files to arbitrary locations on the filesystem, potentially overwriting critical files or achieving remote code execution by overwriting executable files.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 25, 2026

⚠️ No Changeset found

Latest commit: d6029f5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link
Copy Markdown

netlify Bot commented May 25, 2026

Deploy Preview for react-docgen canceled.

Name Link
🔨 Latest commit d6029f5
🔍 Latest deploy log https://app.netlify.com/projects/react-docgen/deploys/6a1394cbc61ac2000750a70c

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