diff --git a/config/routes.rb b/config/routes.rb index f2c13854bc..6ed86fa3fa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -190,4 +190,12 @@ def matches?(request) match "*path", to: "application#handle_unwanted_requests", via: :all, constraints: lambda { |req| req.path =~ %r{^/(wordpress|wp)}i } + + # 404 - misc head requests + match "*path", to: "application#handle_unwanted_requests", via: :head, constraints: lambda { |req| + req.path =~ %r{^/(backup|bc|bk|home|main|new|old)}i + } + + # 404 - root requests + options "/", to: "application#handle_unwanted_requests" end diff --git a/spec/routes/routes_spec.rb b/spec/routes/routes_spec.rb index ee44e37a7f..29e88ab5fb 100644 --- a/spec/routes/routes_spec.rb +++ b/spec/routes/routes_spec.rb @@ -97,5 +97,27 @@ end end end + + context "misc head requests" do + it "returns a 404" do + %w[ + backup + bc + bk + home + main + new + old + ].each do |path| + expect(head: path).to route_to(controller: "application", action: "handle_unwanted_requests", path: path) + end + end + end + + context "root requests" do + it "returns a 404" do + expect(options: "/").to route_to(controller: "application", action: "handle_unwanted_requests") + end + end end end