Skip to content

Commit

Permalink
Fix CloudMailin signature digest calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
dnrce committed Sep 8, 2014
1 parent 115ce8e commit 1f95d72
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/controllers/integrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,24 @@ def process_message(message)

def verify_cloudmailin_signature
provided = request.request_parameters.delete(:signature)
signature = Digest::MD5.hexdigest(request.request_parameters.sort{|a,b| a[0].to_s <=> b[0].to_s}.map{|k,v| v}.join + SITE_CONFIG['cloudmailin'])
signature = Digest::MD5.hexdigest(flatten_params(request.request_parameters).sort.map{|k,v| v}.join + SITE_CONFIG['cloudmailin'])
return provided == signature
end

def flatten_params(params, title = nil, result = {})
params.each do |key, value|
if value.kind_of?(Hash)
key_name = title ? "#{title}[#{key}]" : key
flatten_params(value, key_name, result)
else
key_name = title ? "#{title}[#{key}]" : key
result[key_name] = value
end
end

return result
end

def get_applescript(partial_name)
context = current_user.contexts.find params[:context_id]
render :partial => partial_name, :locals => { :context => context }
Expand Down

0 comments on commit 1f95d72

Please sign in to comment.