In the current router DSL, using the +match+ DSL method will match all verbs for the path to the specified endpoint. In the vast majority of cases, people are currently using +match+ when they actually mean +get+. This introduces security implications. This commit disallows calling +match+ without an HTTP verb constraint by default. To explicitly match all verbs, this commit also adds a :via => :all option to +match+. Closes #5964
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -59,6 +59,16 @@ def initialize(set, scope, path, options) | ||
| @options = (@scope[:options] || {}).merge(options) | ||
| @path = normalize_path(path) | ||
| normalize_options! | ||
|
|
||
| via_all = @options.delete(:via) if @options[:via] == :all | ||
|
|
||
| if !via_all && request_method_condition.empty? | ||
| msg = "You should not use the `match` method in your router without specifying an HTTP method.\n" \ | ||
| "If you want to expose your action to GET, use `get` in the router:\n\n" \ | ||
| " Instead of: match \"controller#action\"\n" \ | ||
| " Do: get \"controller#action\"" | ||
| raise msg | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
steveklabnik
via email
Member
|
||
| end | ||
| end | ||
|
|
||
| def to_route | ||
| @@ -264,7 +274,7 @@ module Base | ||
| # of most Rails applications, this is beneficial. | ||
| def root(options = {}) | ||
| options = { :to => options } if options.is_a?(String) | ||
| match '/', { :as => :root }.merge(options) | ||
| match '/', { :as => :root, :via => :get }.merge(options) | ||
| end | ||
|
|
||
| # Matches a url pattern to one or more routes. Any symbols in a pattern | ||
| @@ -417,7 +427,7 @@ def mount(app, options = nil) | ||
|
|
||
| options[:as] ||= app_name(app) | ||
|
|
||
| match(path, options.merge(:to => app, :anchor => false, :format => false)) | ||
| match(path, options.merge(:to => app, :anchor => false, :format => false, :via => :all)) | ||
|
|
||
| define_generate_prefix(app, options[:as]) | ||
| self | ||
2 comments
on commit 56cdc81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kudos! Very appreciate your help!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
Unfortunately, I found someone using this in the wild. I'll file a ticket up stream, but should we make this a warning?