-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analytics: don't record page views for PR previews (#11065)
* Analytics: don't record page views for PR previews * Tests * Fix log * Comments
- Loading branch information
Showing
6 changed files
with
109 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import structlog | ||
|
||
log = structlog.get_logger(__name__) # noqa | ||
|
||
|
||
def is_suspicious_request(request) -> bool: | ||
""" | ||
Returns True if the request is suspicious. | ||
This function is used to detect bots and spammers, | ||
we use Cloudflare to detect them. | ||
""" | ||
# This header is set from Cloudflare, | ||
# it goes from 0 to 100, 0 being low risk, | ||
# and values above 10 are bots/spammers. | ||
# https://developers.cloudflare.com/ruleset-engine/rules-language/fields/#dynamic-fields. | ||
threat_score = int(request.headers.get("X-Cloudflare-Threat-Score", 0)) | ||
if threat_score > 10: | ||
log.info( | ||
"Suspicious threat score", | ||
threat_score=threat_score, | ||
) | ||
return True | ||
return False |
This file contains 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
This file contains 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