]> source.dussan.org Git - redmine.git/commitdiff
Fix robots.txt route to enforce .txt format (#40208).
authorGo MAEDA <maeda@farend.jp>
Fri, 9 Feb 2024 04:46:13 +0000 (04:46 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 9 Feb 2024 04:46:13 +0000 (04:46 +0000)
Contributed by Liane Hampe (@liane_hampe).

git-svn-id: https://svn.redmine.org/redmine/trunk@22698 e93f8b46-1217-0410-a6f0-8f06a7374b81

config/routes.rb
test/integration/welcome_test.rb

index 540f3d0af651aa30c15dc5dc78cc806dbd7820e2..421bf9b28ceb32c880e5e989d5f74abe05eb921b 100644 (file)
@@ -405,7 +405,7 @@ Rails.application.routes.draw do
 
   match 'uploads', :to => 'attachments#upload', :via => :post
 
-  get 'robots', :to => 'welcome#robots'
+  get 'robots.:format', :to => 'welcome#robots', :constraints => {:format => 'txt'}
 
   Redmine::Plugin.directory.glob("*/config/routes.rb").sort.each do |plugin_routes_path|
     instance_eval(plugin_routes_path.read, plugin_routes_path.to_s)
index d1b0c888956cb0a74aac1d2181f48dbb02c55f84..4fff2827c8c55d9ec59e28686a40ed6e3acad725 100644 (file)
@@ -54,4 +54,11 @@ class WelcomeTest < Redmine::IntegrationTest
       assert @response.body.match(%r{^Disallow: /\r?$})
     end
   end
+
+  def test_robots_should_not_respond_to_formats_other_than_txt
+    %w(robots.json robots).each do |file|
+      get "/#{file}"
+      assert_response :not_found
+    end
+  end
 end