Conversation
d4f048e to
460d738
Compare
|
Looks like the coveralls outage is ongoing. I'd like to wait until that's resolved to merge, but I think we can start code review in the meantime. |
JPrevost
left a comment
There was a problem hiding this comment.
Can you configure the PR build to have this feature enabled and functioning? I want to easily be able to confirm my normal user agent is not blocked from anything but if I change my user agent to a known bot I should be challenged and then be able to pass the challenge to continue.
| end | ||
|
|
||
| def bot_detection_enabled? | ||
| if defined?(Feature) |
There was a problem hiding this comment.
What is this check? If the feature is not enabled, why are we checking if the feature is enabled?
Wouldn't Feature.enabled?(:bot_detection) work for this entire method with no internal conditions?
There was a problem hiding this comment.
Hm, yeah, good point. It's excessively cautious, since we've gated feature validation elsewhere.
| head :not_found unless Feature.enabled?(:bot_detection) | ||
| end | ||
|
|
||
| def handle_forbidden |
There was a problem hiding this comment.
Can you add some docstrings to explain what is going on in this method (even though it is private)? It's unclear to me if this is the normal path a failed cloud flare turnstile takes or if it is a problem with our tokens, etc.
There was a problem hiding this comment.
I was envisioning an issue with the tokens -- will clarify.
| render :show, status: :unprocessable_entity | ||
| end | ||
|
|
||
| def safe_return_path |
There was a problem hiding this comment.
Can you add some docstrings to explain what is going on in this method (even though it is private)?
| private | ||
|
|
||
| def ensure_bot_detection_enabled | ||
| head :not_found unless Feature.enabled?(:bot_detection) |
There was a problem hiding this comment.
If we are assuming this should never happen, maybe we should log to Sentry if it does? My assumption is this is handling a case in which a user agent is requesting the turnstile route even though we have it disabled which should not happen under normal circumstances.
There was a problem hiding this comment.
That's the idea, but now I'm wondering if we even care whether user agents are requesting the turnstile route. I might just drop this for clarity's sake.
app/models/bot_detector.rb
Outdated
| detector = CrawlerDetect.new(ua) | ||
| detector.crawler? | ||
| rescue StandardError => e | ||
| Rails.logger.warn("BotDetector: crawler_detect failed for UA '#{ua}': #{e.message}") |
There was a problem hiding this comment.
I don't think warn is the right level here. I'd lean towards info or debug with a slight preference towards debug (i.e. I don't really want this in production logs, but if we want to keep them in for a bit until they get annoying I'm okay with info).
There was a problem hiding this comment.
I don't have a strong opinion on this. Happy to go with debug for now.
app/models/bot_detector.rb
Outdated
| # SearchController `results` action (path `/results`) and other search-related | ||
| # paths to be search result pages. This keeps the rule simple and conservative. | ||
| path = request.path.to_s | ||
| return true if path.start_with?('/search') || path.start_with?('/results') || path.include?('/search') |
There was a problem hiding this comment.
Can you check these routes? I don't believe /search is a route at all.
I feel like both /results and /record are the paths to block
There was a problem hiding this comment.
Protect all the routes, especially the shadow routes!
❌ 2 blocking issues (2 total)
|
Why these changes are being introduced: We need a preliminary solution to manage bot traffic in production. Relevant ticket(s): - https://mitlibraries.atlassian.net/browse/USE-410 How this addresses that need: - Implements a Bot Detector service that uses Crawler Detect to identify bots to refer to Cloudflare Turnstile. - Implements a Turnstile Controller using the `rails-cloudfire-turnstile` gem for verification challenges. Side effects of this change: The new form may need additional styling. For now, I just added our button styles.
76f6402 to
fb87d65
Compare
Pull Request Test Coverage Report for Build 22592486169Details
💛 - Coveralls |
fb87d65 to
97274a2
Compare
42b13a4 to
5c844c9
Compare
5c844c9 to
f04ae32
Compare
- Explicity require Feature model in initializer - Update CrawlerDetect method name - Remove trailing whitespace from Bot Detector test - Switch from OpenStruct to Struct - Update test assertions Test Turnstile root path fallback and fix typo in CrawlerDetect instantiation
f04ae32 to
bf6be71
Compare
|
@JPrevost I think this is ready for review again. I pushed two separate commits, one two respond to code review feedback, and the other for linting and cleanup. When I enabled the feature in the PR build, I learned that my method name for CrawlerDetect was wrong, so that's fixed. 🤦 I'd flipped the In any case, here's how I've tested the feature:
|
Why these changes are being introduced:
We need a preliminary solution to manage bot traffic in production.
Relevant ticket(s):
How this addresses that need:
rails-cloudfire-turnstilegem for verification challenges.Side effects of this change:
The new form may need additional styling. For now, I just added our button styles.
Developer
Accessibility
New ENV
Approval beyond code review
Additional context needed to review
This introduces
rails-cloudflare-turnstileandcrawler_detectas dependencies.Code Reviewer
Code
added technical debt.
Documentation
(not just this pull request message).
Testing