Aller au contenu

File Inclusion Injection (ARCH6139)

Ce contenu n’est pas encore disponible dans votre langue.

Key ruby.security.file-inclusion-injection · Severity critical · Category security · CWE CWE-98

Including a user-controlled path with require/load lets attackers load arbitrary files and run code. Restrict included modules to an allowlist.

def load_plugin(name)
require "#{Rails.root}/plugins/#{params[:name]}"
end
PLUGINS = { "csv" => "plugins/csv", "pdf" => "plugins/pdf" }.freeze
def load_plugin(name)
path = PLUGINS.fetch(name) { raise ArgumentError, "unknown plugin" }
require Rails.root.join(path).to_s
end

Never build include paths dynamically; resolve them from a fixed allowlist.