mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
7bd3986b21
We have a couple of site setting, `slow_down_crawler_user_agents` and `slow_down_crawler_rate`, that are meant to allow site owners to signal to specific crawlers that they're crawling the site too aggressively and that they should slow down. When a crawler is added to the `slow_down_crawler_user_agents` setting, Discourse currently adds a `Crawl-delay` directive for that crawler in `/robots.txt`. Unfortunately, many crawlers don't support the `Crawl-delay` directive in `/robots.txt` which leaves the site owners no options if a crawler is crawling the site too aggressively. This PR replaces the `Crawl-delay` directive with proper rate limiting for crawlers added to the `slow_down_crawler_user_agents` list. On every request made by a non-logged in user, Discourse will check the User Agent string and if it contains one of the values of the `slow_down_crawler_user_agents` list, Discourse will only allow 1 request every N seconds for that User Agent (N is the value of the `slow_down_crawler_rate` setting) and the rest of requests made within the same interval will get a 429 response. The `slow_down_crawler_user_agents` setting becomes quite dangerous with this PR since it could rate limit lots if not all of anonymous traffic if the setting is not used appropriately. So to protect against this scenario, we've added a couple of new validations to the setting when it's changed: 1) each value added to setting must 3 characters or longer 2) each value cannot be a substring of tokens found in popular browser User Agent. The current list of prohibited values is: apple, windows, linux, ubuntu, gecko, firefox, chrome, safari, applewebkit, webkit, mozilla, macintosh, khtml, intel, osx, os x, iphone, ipad and mac. |
||
---|---|---|
.. | ||
backup_restore | ||
compression | ||
content_security_policy | ||
i18n | ||
imap/providers | ||
onebox | ||
seed_data | ||
site_settings | ||
topic_query | ||
validators | ||
webauthn | ||
bookmark_manager_spec.rb | ||
bookmark_query_spec.rb | ||
bookmark_reminder_notification_handler_spec.rb | ||
browser_detection_spec.rb | ||
content_security_policy_spec.rb | ||
db_helper_spec.rb | ||
discourse_js_processor_spec.rb | ||
encodings_spec.rb | ||
introduction_updater_spec.rb | ||
mini_sql_multisite_connection_spec.rb | ||
onebox_spec.rb | ||
post_jobs_enqueuer_spec.rb | ||
s3_cors_rulesets_spec.rb | ||
search_spec.rb | ||
shrink_uploaded_image_spec.rb | ||
theme_flag_modifier_spec.rb | ||
theme_javascript_compiler_spec.rb | ||
topic_upload_security_manager_spec.rb | ||
upload_creator_spec.rb | ||
upload_recovery_spec.rb | ||
upload_security_spec.rb |