[BUG] FileStore::Directory follows links to folders inside its own folder
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 30/100
Research direction
Start in RubyLLM::FileStore::Directory, at #full_path, which today rejects a path only when its last segment is hidden or when the resolved target lands outside root; the failing check is the one that lets a symlinked folder inside the root through, since File::NOFOLLOW on the final open covers only the last segment. Run the reproduction script from the issue to see read, [], text and delete reach .private/secret.txt via an alias link, and compare with #write, which already replaces links in its way. Done means a path whose intermediate folder is a symlink raises the same ArgumentError as a link out of the root, the hidden file survives after delete, and the existing file-store specs still pass — but note a linked pull request (#1677) is already open against this, so read it before writing your own fix.
Written by the indexing model from the issue text.
Description
Basic checks
- I searched existing issues - this hasn't been reported
- I can reproduce this consistently
- This is a RubyLLM bug, not my application code
What's broken?
The File Stores guide and the FileStore::Directory RDoc say a Directory store leaves out hidden files and folders and never follows symbolic links. #full_path refuses a hidden part such as .private/secret.txt, and for links it resolves the folder a path ends in and refuses it only when the result is outside the root. A link that points to another folder inside the root passes that check. File::NOFOLLOW on the final open only covers the last part of the path, so the link in the middle is followed.
With alias pointing at .private, read, [], text, and delete all reach .private/secret.txt, and delete removes it. A link to an ordinary folder, like shortcut pointing at reports, is followed the same way, though #list never shows anything behind it. #write already behaves differently: it replaces a link that stands in the way instead of writing through it (#1353, "avoid modifying files reached through symbolic links").
The impact is limited. The file tools cannot create links, and code execution can already read hidden files in the folder, so this is not a way around code execution. It matters when a store is pointed at a folder that already holds links, or when another program adds them: read_file then shows the model hidden files, such as a .git folder or a .env file, through a link, and delete_file deletes them.
How to reproduce
require "ruby_llm"
require "tmpdir"
Dir.mktmpdir do |folder|
store = RubyLLM::FileStore::Directory.new(folder)
Dir.mkdir(File.join(store.root, ".private"))
File.write(File.join(store.root, ".private/secret.txt"), "test-secret")
File.symlink(File.join(store.root, ".private"), File.join(store.root, "alias"))
begin
store.read(".private/secret.txt")
rescue ArgumentError => e
puts "direct: #{e.message}"
end
puts "through the link: #{store.read('alias/secret.txt').inspect}"
store.delete("alias/secret.txt")
puts "hidden file still there: #{File.exist?(File.join(store.root, '.private/secret.txt'))}"
end
Expected behavior
A path through a link to a folder is refused, with the ArgumentError a link out of the folder already gets, and the hidden file is left alone.
What actually happened
direct: .private/secret.txt is not inside the chat's files
through the link: "test-secret"
hidden file still there: false
I have a small local fix with specs: #full_path refuses a path when any folder on the way to it is a link to a folder. That also covers links out of the root, so the realpath check goes. A link to a file that stands where a folder goes is still replaced on write, as now.
@crmne, one question:
- The fix refuses links to any folder inside the store, not only to hidden ones, because the docs say links are never followed and
#listalready hides what is behind them. A store pointed at a folder that uses links to ordinary subfolders can no longer read through them. I recommend this, but if you would rather keep following links to non-hidden folders, the check can test the link's target for a hidden part instead.
Environment
- Ruby version: ruby 3.3.5
- RubyLLM version:
mainat9c20ca61 - Provider: none (file store only)
- OS: macOS (Darwin 27, APFS)
- Dominant language
- Ruby
- Stars
- 4.5k
- Forks
- 537
- Avg merge
- 7h 30m
- Merged PRs (30d)
- 378
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from crmne/ruby_llm
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
crmne/ruby_llm#1682 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 22/100
crmne/ruby_llm#1674 · 1 comment ·
Maintainers usually reply within 1 day
-
[BUG] FileStore::Directory#list returns nothing when a file vanishes mid-listingPossibly taken @yorzi claimed this 1 day ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 32/100
Maintainers usually reply within 1 day
-
Body logging is tied to the logger's debug level, and streaming debug lines ignore the context loggerPossibly taken @josh-sanders claimed this 1 day ago. Openbug
Difficulty 3/5 Half a day Newbie friendliness 55/100
crmne/ruby_llm#1669 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Bug Ruby
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-ruby#3211 · 1 comment ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
internetee/registry#2984 ·
Maintainers usually reply within 6 days
-
interest-zsv
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
hitobito/hitobito_zsv#6 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
ecosyste-ms/issues#862 ·
Maintainers usually reply within 1 day
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredPossibly taken @mimosa claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day