Skip to content

fix(importer): keep imports inside the download folder and refuse symlink sources - #4083

Merged
vavallee merged 4 commits into
mainfrom
fix/importer-symlink-dir
Nov 20, 2026
Merged

vavallee merged 4 commits into
mainfrom
fix/importer-symlink-dir

Conversation

@vavallee

Copy link
Copy Markdown
Owner

Summary

Hardening for the import path. The download client's file list was checked for a symlink only on the last path component, so a directory symlink inside a download (torrent, or an extracted archive) could name a book-extension file outside it.

  • A listed file whose real path (EvalSymlinks) leaves the download root is skipped, in the file filter and in the retry guard so the two keep agreeing. A download whose files all escape is blocked, as a symlinked job folder already was.
  • copyFileModeCtx opens the source with O_NOFOLLOW and requires a regular file on the open handle. Windows has no O_NOFOLLOW, so a build-tagged helper Lstats first (GOOS=windows go vet passes).
  • Unchanged: normal nested folders, links that stay inside the download, a download root reached through the operator's own link, hardlink and copy modes.
  • Note: library-internal cross-device copies also go through copyFileModeCtx, so a symlinked library file is no longer copied through by that fallback.

Test plan

  • New tests in source_confine_test.go: a symlinked directory to an outside tempdir holding an .epub is refused; a nested real directory, internal links and a linked root still import; copy refuses a symlink or directory source.
  • Fail before: TestDiscoverBookFiles_DirectorySymlinkOutsideDownloadRefused and TestCopyFile_RefusesSymlinkSource fail on main's code, pass with the change.
  • Full go test -p 2 ./internal/importer and golangci-lint on importer and api pass.

🤖 Generated with Claude Code

…link sources

Hardening: the client file list was checked for a symlink only on the
last path component, so a directory symlink inside a download could name
a book outside it. Files that resolve outside the download root are now
skipped, and the copy opens its source with O_NOFOLLOW and requires a
regular file (Lstat-based on Windows).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: vavallee <vavallee@protonmail.com>
vavallee added a commit that referenced this pull request Nov 20, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: vavallee <vavallee@protonmail.com>
vavallee added a commit that referenced this pull request Nov 20, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: vavallee <vavallee@protonmail.com>
Signed-off-by: Vincent <vavallee@protonmail.com>
@vavallee
vavallee force-pushed the fix/importer-symlink-dir branch from c4f7344 to b408fb7 Compare November 20, 2026 00:38
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
@vavallee
vavallee force-pushed the fix/importer-symlink-dir branch from b408fb7 to f16ebc6 Compare November 20, 2026 00:38
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.67347% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/importer/source_confine.go 78.57% 3 Missing and 3 partials ⚠️
internal/importer/renamer.go 60.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Comment thread internal/importer/nofollow_unix.go Fixed
…es not move (#4083)

Open the copy source inline with a build-tagged no-follow flag instead of
through a helper in a new file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Signed-off-by: vavallee <vavallee@protonmail.com>
Comment thread internal/importer/renamer.go Dismissed
@vavallee
vavallee merged commit 7ef39f7 into main Nov 20, 2026
42 checks passed
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.

2 participants