File Inclusion Injection (ARCH6139)
هذا المحتوى غير متوفر بلغتك بعد.
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.
Incorrect
Section titled “Incorrect”def load_plugin(name) require "#{Rails.root}/plugins/#{params[:name]}"endCorrect
Section titled “Correct”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_sendNever build include paths dynamically; resolve them from a fixed allowlist.