Files
manyfold/app/validators/safe_path_validator.rb
T
2024-09-20 16:01:24 +01:00

22 lines
395 B
Ruby

class SafePathValidator < ActiveModel::EachValidator
UNSAFE = [
"/bin",
"/boot",
"/dev",
"/etc",
"/lib",
"/lost",
"/proc",
"/root",
"/run",
"/sbin",
"/selinux",
"/srv",
"/usr"
]
def validate_each(record, attribute, value)
record.errors.add attribute, :unsafe if value === "/" || UNSAFE.any? { |x| value&.starts_with?(x) }
end
end