File tree 3 files changed +31
-0
lines changed
3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ To get going clone this repository and perform the following steps:
27
27
* [ New Relic] ( https://newrelic.com ) is pre configured in ` config/newrelic.yml ` ,
28
28
but you need to comment in the environment variables for it work on Heroku
29
29
(lines 10 and 17).
30
+
31
+ ## Configuration options
32
+
33
+ | Option | Comment |
34
+ | --- | --- |
35
+ | Disable HTTP TRACE method | Set BLOCK_HTTP_TRACE env var to true/t/1 |
30
36
31
37
## Contents
32
38
Original file line number Diff line number Diff line change 2
2
3
3
require 'rails/all'
4
4
5
+ require_relative '../lib/rack/reject_methods'
6
+
5
7
# Require the gems listed in Gemfile, including any gems
6
8
# you've limited to :test, :development, or :production.
7
9
Bundler . require ( *Rails . groups )
@@ -31,6 +33,10 @@ class Application < Rails::Application
31
33
g . javascripts false
32
34
g . stylesheets false
33
35
g . view_specs false
36
+
37
+ if ENV [ 'BLOCK_HTTP_TRACE' ] . in? ( %w( true t 1 ) )
38
+ config . middleware . use Rack ::RejectMethods
39
+ end
34
40
end
35
41
end
36
42
end
Original file line number Diff line number Diff line change
1
+ module Rack
2
+ class RejectMethods
3
+ METHOD_BLACKLIST = %w( TRACE ) . freeze
4
+
5
+ def initialize ( app )
6
+ @app = app
7
+ @blacklist = blacklist
8
+ end
9
+
10
+ def call ( env )
11
+ return @app . call ( env ) unless @blacklist . include? ( env [ 'REQUEST_METHOD' ] )
12
+ [ 405 , { } , [ "TRACE requests not allowed!\n " ] ]
13
+ end
14
+
15
+ private def blacklist
16
+ ENV . fetch ( 'HTTP_METHOD_BLACKLIST' . split ( ',' ) ) { METHOD_BLACKLIST }
17
+ end
18
+ end
19
+ end
You can’t perform that action at this time.
0 commit comments