Security: Unsafe File Write with User-Controlled Path#1099
Conversation
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>
|
✅ Deploy Preview for react-docgen canceled.
|
|
We added a documentation note for |
Summary
Security: Unsafe File Write with User-Controlled Path
Problem
Severity:
High| File:packages/react-docgen-cli/src/commands/parse/output/outputResult.ts:L8The
outputResultfunction writes to a file path specified by theoutputoption without any validation. If an attacker can control theoutputparameter (e.g., via CLI--outputflag), 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
outputpath to ensure it resolves within an expected output directory. Usepath.resolve()and check that the resolved path starts with the allowed base directory. Consider usingfs.realpath()to resolve symlinks before validation.Changes
packages/react-docgen-cli/src/commands/parse/output/outputResult.ts(modified)