Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let allow_browser allow bots #52531

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Allow bots to ignore `allow_browser`.

*Matthew Nguyen*

* Deprecate drawing routes with hash key paths to make routing faster.

```ruby
Expand Down
6 changes: 5 additions & 1 deletion actionpack/lib/action_controller/metal/allow_browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ def user_agent_version_reported?
end

def unsupported_browser?
version_guarded_browser? && version_below_minimum_required?
version_guarded_browser? && version_below_minimum_required? && !bot?
end

def version_guarded_browser?
minimum_browser_version_for_browser != nil
end

def bot?
parsed_user_agent.bot?
end

def version_below_minimum_required?
if minimum_browser_version_for_browser
parsed_user_agent.version < UserAgent::Version.new(minimum_browser_version_for_browser.to_s)
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/controller/allow_browser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AllowBrowserTest < ActionController::TestCase
FIREFOX_114 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0"
IE_11 = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
OPERA_106 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 OPR/106.0.0.0"
GOOGLE_BOT = "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/W.X.Y.Z Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

test "blocked browser below version limit" do
get_with_agent :hello, FIREFOX_114
Expand Down Expand Up @@ -59,6 +60,14 @@ class AllowBrowserTest < ActionController::TestCase
assert_response :ok
end

test "bots" do
get_with_agent :hello, GOOGLE_BOT
assert_response :ok

get_with_agent :modern, GOOGLE_BOT
assert_response :ok
end

private
def get_with_agent(action, agent)
@request.headers["User-Agent"] = agent
Expand Down