Skip to content
Snippets Groups Projects
Verified Commit 72c27559 authored by tribut's avatar tribut :man_dancing:
Browse files

Secure against directory traversal

We're using checksum as file name and verify that all
externally-controllable path components are harmless.
parent 4ddd1ef4
No related branches found
No related tags found
No related merge requests found
class FiledropFile < ApplicationRecord
belongs_to :session
validates :checksum, presence: true, format: { with: /\A[0-9a-fA-F]+\z/, message: "only allows hexadecimal characters" }
def sanitize_filename(filename)
filename.gsub(/[^\w\s.-]/, '_')
......@@ -36,6 +37,6 @@ class FiledropFile < ApplicationRecord
session.ref_id
)
FileUtils.mkdir_p(dir)
return File.join(dir, name)
return File.join(dir, checksum)
end
end
......@@ -13,6 +13,7 @@ class Session < ApplicationRecord
scope :future, -> { where(starts_at: Time.now..) }
validates :ref_id, uniqueness: { scope: :conference_id }
validates :ref_id, format: { with: /\A[0-9a-fA-F-]+\z/, message: "only allows hexadecimal characters and minus" }
after_update :notify_if_changed
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment