[BUG] FileStore::Directory follows links to folders inside its own folder
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 30/100
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
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)
- Lenguaje dominante
- Ruby
- Estrellas
- 4.5k
- Forks
- 537
- Merge medio
- 7 h 30 min
- PR fusionados (30 d)
- 378
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de crmne/ruby_llm
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
crmne/ruby_llm#1682 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
crmne/ruby_llm#1674 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[BUG] FileStore::Directory#list returns nothing when a file vanishes mid-listingPosiblemente ocupada @yorzi la tomó hace 1 día. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 32/100
Los mantenedores suelen responder en 1 día
-
Body logging is tied to the logger's debug level, and streaming debug lines ignore the context loggerPosiblemente ocupada @josh-sanders la tomó hace 1 día. Abiertobug
Dificultad 3/5 Medio día Aptitud para principiantes 55/100
crmne/ruby_llm#1669 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de crmne/ruby_llm
Issues similares
-
Bug Ruby
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
getsentry/sentry-ruby#3211 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
internetee/registry#2984 ·
Los mantenedores suelen responder en 6 días
-
interest-zsv
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
hitobito/hitobito_zsv#6 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
ecosyste-ms/issues#862 ·
Los mantenedores suelen responder en 1 día
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredPosiblemente ocupada @mimosa la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día