Repository navigation
fix(middleware): make crawler detection work and isolate bot traffic - #949
Draft
thostetler wants to merge 2 commits into
Draft
thostetler wants to merge 2 commits into
thostetler wants to merge 2 commits into
Conversation
Crawler user agents were matched by exact map lookup against the whole UA string, so no real crawler ever matched. Fixing that exposed three more defects: IP checks compared bare addresses instead of CIDR ranges, reverse DNS accepted any host with a PTR record, and classification was discarded by a second iron-session write. Verified-tier classification now requires TRUSTED_CLIENT_IP_HEADER, since X-Forwarded-For's leftmost entry is client-supplied. Without that header, matched crawlers are capped at the unverifiable tier instead of getting an elevated-quota token.
Bundle sizeShared by all pages: 627.8 kB (-0.0 kB) ⚪ No route changed by more than 1 kB. ✅ First load = polyfills + shared |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #949 +/- ##
========================================
+ Coverage 55.1% 55.8% +0.7%
========================================
Files 374 381 +7
Lines 11462 11729 +267
Branches 2514 2575 +61
========================================
+ Hits 6307 6535 +228
- Misses 4524 4559 +35
- Partials 631 635 +4
🚀 New features to boost your workflow:
|
/api/isBot sits outside the middleware matcher, so it was reachable unauthenticated and would drive up to six resolver lookups per request on a caller-supplied IP. The hop is now signed with an HMAC over the timestamp, IP and user agent, keyed on COOKIE_SECRET, and the handler rejects anything unsigned, stale or altered before touching DNS. The response status is checked too, so a rejected hop no longer reads a 403 body as a HUMAN verdict. A successful bootstrap also clears session.bot. Without it a session that was once classified as a bot kept the flag after its token expired and was replaced by a human one, and isUserIdentifiedAsBot then skipped the apiCookieHash comparison for the rest of that token's life.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Crawler user agents were matched by exact map lookup against the whole UA string, which was probably making some bots not match