All about Paperclip’s CVE-2017–0889 Server Side Request Forgery (SSRF) vulnerability

Ron Gutierrez
Jan 23, 2018 · 6 min read
Image for post
Image for post

Issue Description

class GenericUploadController < ActionController::Base
..snip..
def create
GenericAttachment.create(:attachment => params[:attachment])
..snip..
end
class GenericAttachment < ActiveRecord::Base
has_attached_file :attachment
POST /upload HTTP/1.1
Host: example.com
..snip..
— — — WebKitFormBoundaryGB91jEIcBxpCcDwwContent-Disposition: form-data; name=”attachment”;http://169.254.169.254/latest/
class GenericUploadController < ActionController::Base
..snip..
def create
GenericAttachment.create(:attachment =>
URI(params[:attachment]))
..snip..
end

What’s the impact?


So.. how do I fix it?

worrisome_adapters = [Paperclip::UriAdapter, Paperclip::HttpUrlProxyAdapter, Paperclip::DataUriAdapter]Paperclip.io_adapters
.registered_handlers
.delete_if do |_block, handler_class|
worrisome_adapters.include?(handler_class)
end
POST /upload HTTP/1.1
Host: example.com
..snip..
— — — WebKitFormBoundaryGB91jEIcBxpCcDwwContent-Disposition: form-data; name=”attachment”;http://www.somevalidurl.com
HTTP/1.1 302 Moved Temporarily
..snip..
Location: http://169.254.169.254/latest/
module PaperclipUriAdapterSafe
def download_content
RoutableUrlValidator.open_http(@target)
end
end

Paperclip::UriAdapter.send(:prepend, PaperclipUriAdapterSafe)
def open_http(name, *rest, &block)
max_redirect_tries = 3
options = rest.extract_options!
options[:redirect] = false
rest << options

begin
uri = validate_and_parse_url(name)
open(uri, *rest, &block)
rescue OpenURI::HTTPRedirect => redirect
name = redirect.uri.to_s
retry if (max_redirect_tries -= 1) > 0
raise
end
end

Wrap it up already!

In the Weeds

A blog by the Greenhouse Engineering team

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store