diff options
author | Rosa Gutierrez <rosa.ge@gmail.com> | 2018-09-06 16:52:52 +0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2018-11-27 15:36:27 -0500 |
commit | 06ab7b27ea1c1ab357085439abacdb464f6742bf (patch) | |
tree | 2f569fbf03ce6db27de91cc8c6b2885933f3fbd6 /activestorage/test/controllers | |
parent | 72300f9742745f9535b06d45a9632e948ed7d79b (diff) | |
download | rails-06ab7b27ea1c1ab357085439abacdb464f6742bf.tar.gz rails-06ab7b27ea1c1ab357085439abacdb464f6742bf.tar.bz2 rails-06ab7b27ea1c1ab357085439abacdb464f6742bf.zip |
Prevent content type and disposition bypass in storage service URLs
* Force content-type to binary on service urls for relevant content types
We have a list of content types that must be forcibly served as binary,
but in practice this only means to serve them as attachment always. We
should also set the Content-Type to the configured binary type.
As a bonus: add text/cache-manifest to the list of content types to be
served as binary by default.
* Store content-disposition and content-type in GCS
Forcing these in the service_url when serving the file works fine for S3
and Azure, since these services include params in the signature.
However, GCS specifically excludes response-content-disposition and
response-content-type from the signature, which means an attacker can
modify these and have files that should be served as text/plain attachments
served as inline HTML for example. This makes our attempt to force
specific files to be served as binary and as attachment can be easily
bypassed.
The only way this can be forced in GCS is by storing
content-disposition and content-type in the object metadata.
* Update GCS object metadata after identifying blob
In some cases we create the blob and upload the data before identifying
the content-type, which means we can't store that in GCS right when
uploading. In these, after creating the attachment, we enqueue a job to
identify the blob, and set the content-type.
In other cases, files are uploaded to the storage service via direct
upload link. We create the blob before the direct upload, which happens
independently from the blob creation itself. We then mark the blob as
identified, but we have already the content-type we need without having
put it in the service.
In these two cases, then, we need to update the metadata in the GCS
service.
* Include content-type and disposition in the verified key for disk service
This prevents an attacker from modifying these params in the service
signed URL, which is particularly important when we want to force them
to have specific values for security reasons.
* Allow only a list of specific content types to be served inline
This is different from the content types that must be served as binary
in the sense that any content type not in this list will be always
served as attachment but with its original content type. Only types in
this list are allowed to be served either inline or as attachment.
Apart from forcing this in the service URL, for GCS we need to store the
disposition in the metadata.
Fix CVE-2018-16477.
Diffstat (limited to 'activestorage/test/controllers')
-rw-r--r-- | activestorage/test/controllers/disk_controller_test.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/activestorage/test/controllers/disk_controller_test.rb b/activestorage/test/controllers/disk_controller_test.rb index 7b5e989699..0aa8648db3 100644 --- a/activestorage/test/controllers/disk_controller_test.rb +++ b/activestorage/test/controllers/disk_controller_test.rb @@ -5,11 +5,12 @@ require "database/setup" class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest test "showing blob inline" do - blob = create_blob + blob = create_blob(filename: "hello.jpg", content_type: "image/jpg") + get blob.service_url assert_response :ok - assert_equal "inline; filename=\"hello.txt\"; filename*=UTF-8''hello.txt", response.headers["Content-Disposition"] - assert_equal "text/plain", response.headers["Content-Type"] + assert_equal "inline; filename=\"hello.jpg\"; filename*=UTF-8''hello.jpg", response.headers["Content-Disposition"] + assert_equal "image/jpg", response.headers["Content-Type"] assert_equal "Hello world!", response.body end @@ -36,6 +37,10 @@ class ActiveStorage::DiskControllerTest < ActionDispatch::IntegrationTest blob.delete get blob.service_url + end + + test "showing blob with invalid key" do + get rails_disk_service_url(encoded_key: "Invalid key", filename: "hello.txt") assert_response :not_found end |