Commit ebad3620 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Render 404 to crawlers instead of redirecting

The login page is protected by Cloudflare's WAF and it is causing issues
with search engine crawlers because Cloudflare returns a 503 when doing
a browser check
parent 8db8c419
...@@ -121,7 +121,7 @@ class ApplicationController < ActionController::Base ...@@ -121,7 +121,7 @@ class ApplicationController < ActionController::Base
end end
def route_not_found def route_not_found
if current_user if current_user || browser.bot.search_engine?
not_found not_found
else else
store_location_for(:user, request.fullpath) unless request.xhr? store_location_for(:user, request.fullpath) unless request.xhr?
......
---
title: Render 404 to search engine crawlers instead of redirecting to login
merge_request: 45552
author:
type: changed
...@@ -171,6 +171,8 @@ RSpec.describe ApplicationController do ...@@ -171,6 +171,8 @@ RSpec.describe ApplicationController do
describe '#route_not_found' do describe '#route_not_found' do
controller(described_class) do controller(described_class) do
skip_before_action :authenticate_user!, only: :index
def index def index
route_not_found route_not_found
end end
...@@ -184,6 +186,14 @@ RSpec.describe ApplicationController do ...@@ -184,6 +186,14 @@ RSpec.describe ApplicationController do
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'renders 404 if client is a search engine crawler' do
request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
get :index
expect(response).to have_gitlab_http_status(:not_found)
end
it 'redirects to login page if not authenticated' do it 'redirects to login page if not authenticated' do
get :index get :index
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment