Repository navigation
📦🔧:check the file the importer opened - #143
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Validate opened destination before writing packages/gh-file-importer/src/index.ts, packages/gh-file-importer/README.md, packages/gh-file-importer/test/index.ts, .changeset/importer-opened-file.md |
The importer opens the destination without truncation. On Linux, it checks the opened descriptor’s physical path before truncating or writing. Documentation describes destination-tree requirements and the limits of the check. Tests cover shorter overwrites, a directory-swap race, and descriptor lookup errors. |
Printable download URLs
| Layer / File(s) | Summary |
|---|---|
Encode control characters in displayed URLs packages/gh-file-importer/src/index.ts, packages/gh-file-importer/test/index.ts |
Download-start logs and HTTP failure messages use URLs with C0 and C1 control characters percent-encoded. A test checks the encoded output. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Possibly related PRs
- OpenINF/sdk#130: Changes the same importer destination-write path. This PR adds a check of the opened destination descriptor before truncation and writing.
Merge Risk: 
Moderate · up to 25b50
-
On restricted Linux systems, a directory swap can still overwrite a file outside the destination. Handle unexpected lookup failures before merging.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
CodeRabbit Verify
- Run CodeRabbit Verify to test the changes in this pull request.
|
@coderabbitai review Generated by Claude Code |
Action not completed
|
679fac5 to
1e5bded
Compare
Every check writeWithinDestDir made was of a path. A directory swapped for a symbolic link after the last check still redirected the open, and O_TRUNC emptied whatever file it reached before a byte was written. The file is now opened without truncating it, and on Linux /proc/self/fd names the file the descriptor actually reached; one outside destDir is refused before any of it changes. Where /proc is mounted but the lookup fails, the import fails rather than writing unchecked. A swap that wins the race costs at most an empty file created outside. No other platform, and no Linux system without /proc, says where a descriptor leads, so the README now asks for a destDir nobody less trusted than the caller can change mid-import. The download log line and the failed-download error printed the URL as given, so a line break in it could forge a log line and an escape could restyle the terminal. Control characters in it are now percent-encoded, the way a URL carries them. Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is> Assisted-by: Claude-Code:claude-opus-5
1e5bded to
25b50b8
Compare
Requested by DerekNonGeneric
Before: every destination check in
writeWithinDestDirchecked a path, not the file actually opened. Suppose a directory was swapped for a symbolic link after the last check. Theopencall would then follow the link, andO_TRUNCwould empty whatever file it reached before anything was written (CWE-367). Separately, the download log line and the error for a failed download printed the URL exactly as given. A URL containing a line break could fake an extra log line, and one containing a terminal escape could change how the terminal displays output (CWE-117). CodeRabbit's security deepscan reported both.After: on Linux, a swapped-in link is refused before any byte of the outside file changes. The worst a winning race can do is create an empty file outside
destDir. Other platforms offer no way to ask where an open file descriptor points. For them, the README now asks callers to use adestDirthat no less trusted user can change during an import. Control characters in a URL are percent-encoded in both the log line and the error message.How: the destination file is now opened with
O_CREAT | O_WRONLY | O_NOFOLLOW, withoutO_TRUNC. On Linux, the code reads the descriptor's real path from/proc/self/fd/<fd>and refuses the write if it is outside the physicaldestDir. Only after that check does it callhandle.truncate(0)and write.printableUrlpercent-encodes C0 and C1 control characters. I added three tests:openso the parent directory is swapped for a link at the last moment. The file outsidedestDirkeeps its contents. This test is skipped on platforms other than Linux.The race test and the URL test fail against the old code. All 69 tests pass on Node 24.
🤖 Generated with Claude Code
Summary by CodeRabbit