FIX: move crawler blocking into anon cache

This refinement of previous fix moves the crawler blocking into
anonymous cache

This ensures we never poison the cache incorrectly when blocking crawlers
This commit is contained in:
Sam
2018-07-04 11:14:43 +10:00
parent 7f98ed69cd
commit e72fd7ae4e
4 changed files with 99 additions and 81 deletions

View File

@ -40,7 +40,6 @@ class ApplicationController < ActionController::Base
end
end
before_action :block_crawlers
before_action :check_readonly_mode
before_action :handle_theme
before_action :set_current_user_for_logs
@ -465,19 +464,6 @@ class ApplicationController < ActionController::Base
private
def block_crawlers
if (
request.get? &&
!request.xhr? &&
!request.path.ends_with?('robots.txt') &&
CrawlerDetection.is_blocked_crawler?(request.env['HTTP_USER_AGENT'])
)
request.env["discourse.request_tracker.skip"] = true
raise Discourse::InvalidAccess, 'Crawler not allowed'
end
end
def check_readonly_mode
@readonly_mode = Discourse.readonly_mode?
end