[BUG] FileStore::Directory follows links to folders inside its own folder

Open
#1,673 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@yorzi is already working on this.

Since Nov 15, 2026.

  • #1677 by @yorzi — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
ruby
Domain
security

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

bug
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:

  1. The fix refuses links to any folder inside the store, not only to hidden ones, because the docs say links are never followed and #list already 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: main at 9c20ca61
  • 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from crmne/ruby_llm

All issues in crmne/ruby_llm

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.