Commit Graph

39 Commits

Author SHA1 Message Date
Tahsin Hasan bb148d822c
Permit hash on direct upload in active storage (#40662) 2020-11-28 10:33:44 +01:00
George Claghorn b221a4dc43
Proxying: sanitize Content-Type and Content-Disposition
Prevent XSS where unsafe content is served inline on the application origin.

Follows up on #34477. References 06ab7b2 and d40284b.
2020-08-31 11:24:13 -04:00
Evgeniy Rashchepkin 6af5662165
Disable template digesting for Active Storage controllers
Error entries appear in the log when we request ActiveStorage
controllers (`ActiveStorage::Representations::ProxyController#show`,
`ActiveStorage::Blobs::ProxyController#show`).

These entries look like: "Couldn't find template for digesting:
active_storage/representations/proxy/show".

These controllers use the method
`ActionController::ConditionalGet#http_cache_forever`,
and therefore `ActionController::ConditionalGet#combine_etags` method,
and therefore `ActionController::EtagWithTemplateDigest` module via
`etaggers` array.

`ActionController::EtagWithTemplateDigest` module requires a template
(view).

We have no views in ActiveStorage, so `EtagWithTemplateDigest` is
now turned off in ActiveStorage controllers by
`etag_with_template_digest` class attribute.
2020-07-05 10:51:08 -04:00
Santiago Bartesaghi 31148cd6be Use Active Record signed IDs in Active Storage 2020-07-04 21:09:00 -04:00
Jonathan Fleckenstein dfb5a82b25
Active Storage: allow serving files by proxying 2020-05-11 16:21:58 -04:00
André Leoni a5789e7a90 Remove unused space from disk controller of activestorage 2020-03-04 17:22:56 -03:00
Peter Zhu fbb83d78c3 Use DiskController for both public and private files 2019-12-06 16:02:16 -05:00
George Claghorn 317760c5ad Use ActiveStorage::Preview#url instead of deprecated #service_url 2019-12-05 19:41:04 -05:00
Peter Zhu 235f2636cd Deprecate `service_url` in favour of `url` 2019-12-02 14:59:03 -05:00
Peter Zhu feab7031b5 Permanent URLs for public storage blobs
Services can be configured in `config/storage.yml` with a new key
`public: true | false` to indicate whether a service holds public
blobs or private blobs. Public services will always return a
permanent URL.

Deprecates `Blob#service_url` in favor of `Blob#url`.
2019-10-11 15:14:43 -04:00
Akira Matsuda dea19d4ead Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-07 02:44:36 +09:00
Sharang Dashputre 771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
Gannon McGibbon 2e0ca9284a Revert ensure external redirects are explicitly allowed 2019-01-22 11:40:13 -05:00
Yuichi Takeuchi ee65ca46e5 Fix ArgumentError: Unsafe redirect 2019-01-21 14:15:34 +09:00
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