Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/smile-identity-core/web_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def zip_up_file(info_json)
end

def upload_file(url, info_json, smile_job_id)
validate_upload_url!(url)
file = zip_up_file(info_json)
file.rewind

Expand All @@ -336,6 +337,20 @@ def upload_file(url, info_json, smile_job_id)
request.run
end

# Validate upload_url against expected host/prefix
def validate_upload_url!(upload_url)
allowed_host = URI.parse(@url).host
begin
uri = URI.parse(upload_url)
rescue URI::InvalidURIError
raise ArgumentError, "Invalid upload_url"
end
# Only allow URLs that match the known host
unless uri.host == allowed_host
raise ArgumentError, "Untrusted upload_url: #{upload_url}"
end
end

def query_job_status(counter = 0)
counter < 4 ? (sleep 2) : (sleep 6)
counter += 1
Expand Down
Loading