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

Abierto
#1,673 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@yorzi ya está trabajando en esto.

Desde el 15/11/2026.

  • #1677 de @yorzi — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
ruby
Área
security

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)
Lenguaje dominante
Ruby
Estrellas
4.5k
Forks
537
Merge medio
7 h 30 min
PR fusionados (30 d)
378

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de crmne/ruby_llm

Todos los issues de crmne/ruby_llm

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.