-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for Host Authorization middleware
The Host Authorization middleware protects against DNS rebinding. This middleware is primarily targeted at the development environment: > It is included in the development environment by default ... In other environments Rails.application.config.hosts is empty and no Host header checks will be done. rails/rails#33145 If someone decides to call `config.hosts.clear` because it's "only development", we should warn them they are vulnerable to DNS rebinding.
- Loading branch information
Showing
4 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Brakeman::CheckHosts < Brakeman::BaseCheck | ||
Brakeman::Checks.add_optional self | ||
|
||
@description = "Check that hosts setting is not empty in development" | ||
|
||
def run_check | ||
return if tracker.config.rails.empty? or tracker.config.rails_version.nil? | ||
return if tracker.config.rails_version < "6" | ||
|
||
hosts = tracker.config.rails[:hosts] | ||
|
||
if hosts.nil? || hosts.empty? | ||
line = if sexp? hosts | ||
hosts.line | ||
else | ||
1 | ||
end | ||
|
||
warn :warning_type => "DNS rebinding", | ||
:warning_code => :hosts_empty, | ||
:message => msg("The application does not guard against DNS rebinding: ", msg_code("config.hosts"), " is empty"), | ||
:confidence => :high, | ||
:file => "config/environments/development.rb", | ||
:line => line | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters