mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-23 04:02:19 -05:00
22 lines
395 B
Ruby
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
|