Skip to content

Commit c5e46ef

Browse files
authored
Merge pull request rails#41503 from santib/improve-active-storage-security-docs
Improve ActiveStorage security documentation [ci skip]
2 parents 9053b8f + 63dd10c commit c5e46ef

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

activestorage/app/controllers/active_storage/blobs/proxy_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# frozen_string_literal: true
22

33
# Proxy files through application. This avoids having a redirect and makes files easier to cache.
4+
#
5+
# WARNING: All Active Storage controllers are publicly accessible by default. The
6+
# generated URLs are hard to guess, but permanent by design. If your files
7+
# require a higher level of protection consider implementing
8+
# {Authenticated Controllers}[https://edgeguides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
49
class ActiveStorage::Blobs::ProxyController < ActiveStorage::BaseController
510
include ActiveStorage::SetBlob
611

activestorage/app/controllers/active_storage/blobs/redirect_controller.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# frozen_string_literal: true
22

33
# Take a signed permanent reference for a blob and turn it into an expiring service URL for download.
4-
# Note: These URLs are publicly accessible. If you need to enforce access protection beyond the
5-
# security-through-obscurity factor of the signed blob references, you'll need to implement your own
6-
# authenticated redirection controller.
4+
#
5+
# WARNING: All Active Storage controllers are publicly accessible by default. The
6+
# generated URLs are hard to guess, but permanent by design. If your files
7+
# require a higher level of protection consider implementing
8+
# {Authenticated Controllers}[https://edgeguides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
79
class ActiveStorage::Blobs::RedirectController < ActiveStorage::BaseController
810
include ActiveStorage::SetBlob
911

activestorage/app/controllers/active_storage/representations/proxy_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# frozen_string_literal: true
22

33
# Proxy files through application. This avoids having a redirect and makes files easier to cache.
4+
#
5+
# WARNING: All Active Storage controllers are publicly accessible by default. The
6+
# generated URLs are hard to guess, but permanent by design. If your files
7+
# require a higher level of protection consider implementing
8+
# {Authenticated Controllers}[https://edgeguides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
49
class ActiveStorage::Representations::ProxyController < ActiveStorage::Representations::BaseController
510
def show
611
http_cache_forever public: true do

activestorage/app/controllers/active_storage/representations/redirect_controller.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# frozen_string_literal: true
22

33
# Take a signed permanent reference for a blob representation and turn it into an expiring service URL for download.
4-
# Note: These URLs are publicly accessible. If you need to enforce access protection beyond the
5-
# security-through-obscurity factor of the signed blob and variation reference, you'll need to implement your own
6-
# authenticated redirection controller.
4+
#
5+
# WARNING: All Active Storage controllers are publicly accessible by default. The
6+
# generated URLs are hard to guess, but permanent by design. If your files
7+
# require a higher level of protection consider implementing
8+
# {Authenticated Controllers}[https://edgeguides.rubyonrails.org/active_storage_overview.html#authenticated-controllers].
79
class ActiveStorage::Representations::RedirectController < ActiveStorage::Representations::BaseController
810
def show
911
expires_in ActiveStorage.service_urls_expire_in

guides/source/active_storage_overview.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,10 @@ guess but permanent. Anyone that knows the blob URL will be able to access it,
646646
even if a `before_action` in your `ApplicationController` would otherwise
647647
require a login. If your files require a higher level of protection, you can
648648
implement your own authenticated controllers, based on the
649-
[`ActiveStorage::Blobs::RedirectController`](ActiveStorage::Blobs::RedirectController) and
650-
[`ActiveStorage::Representations::RedirectController`](ActiveStorage::Representations::RedirectController)
649+
[`ActiveStorage::Blobs::RedirectController`](ActiveStorage::Blobs::RedirectController),
650+
[`ActiveStorage::Blobs::ProxyController`](ActiveStorage::Blobs::ProxyController),
651+
[`ActiveStorage::Representations::RedirectController`](ActiveStorage::Representations::RedirectController) and
652+
[`ActiveStorage::Representations::ProxyController`](ActiveStorage::Representations::ProxyController)
651653

652654
To only allow an account to access their own logo you could do the following:
653655

@@ -683,7 +685,9 @@ config.active_storage.draw_routes = false
683685
to prevent files being accessed with the publicly accessible URLs.
684686

685687
[ActiveStorage::Blobs::RedirectController]: (https://github.com/rails/rails/blob/main/activestorage/app/controllers/active_storage/blobs/redirect_controller.rb)
688+
[ActiveStorage::Blobs::ProxyController]: (https://github.com/rails/rails/blob/main/activestorage/app/controllers/active_storage/blobs/proxy_controller.rb)
686689
[ActiveStorage::Representations::RedirectController]: (https://github.com/rails/rails/blob/main/activestorage/app/controllers/active_storage/representations/redirect_controller.rb)
690+
[ActiveStorage::Representations::ProxyController]: (https://github.com/rails/rails/blob/main/activestorage/app/controllers/active_storage/representations/proxy_controller.rb)
687691

688692
Downloading Files
689693
-----------------

0 commit comments

Comments
 (0)