aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib
diff options
context:
space:
mode:
authorRosa Gutierrez <rosa.ge@gmail.com>2018-01-04 19:35:54 +0100
committerRosa Gutierrez <rosa.ge@gmail.com>2018-01-05 16:32:32 +0100
commitd40284b1a44773b03d78ca67a888b94fd330d1b1 (patch)
treeac9cada273b492f231bf1b48d215e36ff78fde05 /activestorage/lib
parent5a5014688873f1d6e1b66075eea8a4356b5a4d07 (diff)
downloadrails-d40284b1a44773b03d78ca67a888b94fd330d1b1.tar.gz
rails-d40284b1a44773b03d78ca67a888b94fd330d1b1.tar.bz2
rails-d40284b1a44773b03d78ca67a888b94fd330d1b1.zip
Force content disposition to attachment for specific content types
In this way we avoid HTML, XML, SVG and other files that can be rendered by the browser to be served inline by default. Depending on the origin from where these files are served, this might lead to XSS vulnerabilities, and in the best case, to more realistic phishing attacks and open redirects. We force it rather than falling back to it when other disposition is not provided. Otherwise it would be possible for someone to force inline just by passing `disposition=inline` in the URL. The list of content types to be served as attachments is configurable.
Diffstat (limited to 'activestorage/lib')
-rw-r--r--activestorage/lib/active_storage.rb1
-rw-r--r--activestorage/lib/active_storage/engine.rb11
2 files changed, 12 insertions, 0 deletions
diff --git a/activestorage/lib/active_storage.rb b/activestorage/lib/active_storage.rb
index 01fd0f4415..3bd8ef664f 100644
--- a/activestorage/lib/active_storage.rb
+++ b/activestorage/lib/active_storage.rb
@@ -43,4 +43,5 @@ module ActiveStorage
mattr_accessor :analyzers, default: []
mattr_accessor :paths, default: {}
mattr_accessor :variable_content_types, default: []
+ mattr_accessor :content_types_to_serve_as_binary, default: []
end
diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb
index d5c71670ff..1f15ac2d2d 100644
--- a/activestorage/lib/active_storage/engine.rb
+++ b/activestorage/lib/active_storage/engine.rb
@@ -18,6 +18,16 @@ module ActiveStorage
config.active_storage.analyzers = [ ActiveStorage::Analyzer::ImageAnalyzer, ActiveStorage::Analyzer::VideoAnalyzer ]
config.active_storage.paths = ActiveSupport::OrderedOptions.new
config.active_storage.variable_content_types = [ "image/png", "image/gif", "image/jpg", "image/jpeg", "image/vnd.adobe.photoshop" ]
+ config.active_storage.content_types_to_serve_as_binary = [
+ "text/html",
+ "text/javascript",
+ "image/svg+xml",
+ "application/postscript",
+ "application/x-shockwave-flash",
+ "text/xml",
+ "application/xml",
+ "application/xhtml+xml"
+ ]
config.eager_load_namespaces << ActiveStorage
@@ -29,6 +39,7 @@ module ActiveStorage
ActiveStorage.analyzers = app.config.active_storage.analyzers || []
ActiveStorage.paths = app.config.active_storage.paths || {}
ActiveStorage.variable_content_types = app.config.active_storage.variable_content_types || []
+ ActiveStorage.content_types_to_serve_as_binary = app.config.active_storage.content_types_to_serve_as_binary || []
end
end