1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

25 commits

Author SHA1 Message Date
Rosa Gutierrez
06ab7b27ea 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.
2018-11-27 15:36:27 -05:00
Graham Conzett
bba5ecc923 Use content_mime_type 2018-10-08 09:50:51 -04:00
Graham Conzett
1986048d27 Fix issue ActiveStorage direct upload disk
Fix an issue in ActiveStorage where a direct upload to disk storage
would fail due to a content type mismatch if the file was uploaded using
a mime-type synonym.
2018-10-07 16:07:09 -04:00
Cameron Bothner
22efb2ec49 Respond with 404 in ActiveStorage::DiskController#show when file missing
`ActiveStorage::DiskController#show` generates a 404 Not Found response when
the requested file is missing from the disk service. It previously raised
`Errno::ENOENT`.
2018-08-21 15:35:58 -04:00
George Claghorn
e33c3cd8cc Extract ActiveStorage::SetCurrent
Provide a handy concern for custom Active Storage controllers that can't inherit from ActiveStorage::BaseController.
2018-08-16 01:41:15 -04:00
George Claghorn
94f2558f6a Restore inadvertently-removed fallback 2018-07-15 20:12:53 -04:00
George Claghorn
390097531b Support HTTP Range downloads from disk
Closes #32193.
2018-07-15 19:58:14 -04:00
George Claghorn
b21f50d8ae Permit configuring the default service URL expiry 2018-06-21 11:06:32 -04:00
George Claghorn
847342c25c Stream blobs from disk 2018-05-02 18:56:09 -04:00
Javan Makhmali
efb7dc65d9 Always exclude JSON root from direct_uploads#create response
The JavaScript component expects a bare response.

Fixes #32365
2018-04-10 06:36:47 -04:00
Andrew White
9436c22e2a
Use a current model to provide the host for service urls
Trying to pass the current request down to the service so that it can
create full urls instead of paths makes the API messy so use a model
based on ActiveSupport::CurrentAttributes to provide the current host
to services that need it (primarily the disk service).
2018-04-06 20:07:52 +01:00
Rafael Mendonça França
03bd370c02
Protect all active storage controllers agains CSRF
Before it was possible to for example use the direct upload controller
without using the site.
2018-04-06 14:28:44 -04:00
Kasper Timm Hansen
0f302b8970
Merge Previews/Variants controller into one Representations controller.
Since ActiveStorage::Blob::Representable unifies the idea of previews and
variants under one roof as representation, we may as well have the
controllers follow suit.

Thus ActiveStorage::RepresenationsController enters the fray. I've copied
the old tests for both previews and variants and unified those as well.
2018-03-03 21:36:43 +01:00
George Claghorn
dbff1cee55 Exclude ActiveStorage::SetBlob from API docs [ci skip] 2018-01-02 22:49:18 -05:00
George Claghorn
af0caadb8d Handle invalid signed blob IDs gracefully 2017-12-15 19:26:53 -05:00
George Claghorn
4d5f0bb30b Fix loading ActiveStorage::DiskController when CSRF protection is disabled by default 2017-11-21 14:59:30 -05:00
George Claghorn
2d20a7696a Fix direct uploads to local service
Disable CSRF protection for ActiveStorage::DiskController#update. The local disk service is intended to imitate a third-party service like S3 or GCS, so we don't care where direct uploads originate: they’re authorized by signed tokens.

Closes #30290.

[Shinichi Maeshima & George Claghorn]
2017-11-20 10:54:46 -05:00
George Claghorn
d30586211b Preview PDFs and videos 2017-09-28 16:43:37 -04:00
George Claghorn
376dd5c001 DRY 2017-08-20 18:09:44 -04:00
Xavier Noria
d8bf5d73c3 restores some double newlines deleted in ae87217
These were intentional, see

https://github.com/rails/rails/pull/30061#issuecomment-320068368
2017-08-15 22:01:24 +02:00
Xavier Noria
ae87217382 minor tweaks in Active Storage after a walkthrough 2017-08-15 18:50:46 +02:00
Koichi ITO
d02844f249 Use frozen string literal in Active Storage 2017-08-12 21:43:42 +09:00
Anton Khamets
e25466b142 Enable browser caching for blobs and variants (#30196) 2017-08-11 13:18:12 -04:00
Rafael Mendonça França
f601a01b2c Do not eager load ActiveRecord::Base
Everything inside the app directory of a engine is autoload/eager loaded automatically so we don't need to require them.
2017-08-03 16:57:48 -04:00
Rafael Mendonça França
9330d01ada Add 'activestorage/' from commit '3f4a7218a4a4923a0e7ce1b2eb0d2888ce30da58'
git-subtree-dir: activestorage
git-subtree-mainline: 0d58e7e478
git-subtree-split: 3f4a7218a4
2017-07-31 15:21:22 -04:00