Skip to content

Commit

Permalink
Fix ThreadResolveWorker getting queued with invalid URLs (#9628)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored Dec 26, 2018
1 parent 17cd91c commit aa9a20c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def process_attachments
end

def resolve_thread(status)
return unless status.reply? && status.thread.nil?
return unless status.reply? && status.thread.nil? && Request.valid_url?(in_reply_to_uri)
ThreadResolveWorker.perform_async(status.id, in_reply_to_uri)
end

Expand Down
2 changes: 1 addition & 1 deletion app/lib/ostatus/activity/creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def process_status
save_emojis(status)
end

if thread? && status.thread.nil?
if thread? && status.thread.nil? && Request.valid_url?(thread.second)
Rails.logger.debug "Trying to attach #{status.id} (#{id}) to #{thread.first}"
ThreadResolveWorker.perform_async(status.id, thread.second)
end
Expand Down
12 changes: 12 additions & 0 deletions app/lib/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ def headers
(@account ? @headers.merge('Signature' => signature) : @headers).without(REQUEST_TARGET)
end

class << self
def valid_url?(url)
begin
parsed_url = Addressable::URI.parse(url)
rescue Addressable::URI::InvalidURIError
return false
end

%w(http https).include?(parsed_url.scheme) && parsed_url.host.present?
end
end

private

def set_common_headers!
Expand Down

0 comments on commit aa9a20c

Please sign in to comment.