-
Notifications
You must be signed in to change notification settings - Fork 32
Use robots.txt and mitigate AI bots #460
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1832177
feat: implement multi-layer bot mitigation in nginx config
cycomachead 0119a40
Merge branch 'main' of github.com:snap-cloud/snapCloud into cycomache…
cycomachead bfa07ef
no sitemap
cycomachead 7da3d5e
stricter robots.txt
cycomachead 180756f
refactor: canonicalize project API routes to use /api/v1 prefix
cycomachead 284d969
Merge remote-tracking branch 'origin/cycomachead/ai/26/1' into cycoma…
cycomachead 02d1066
Set a filename
cycomachead 5f1b9a2
Fix openSAP course links
cycomachead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,16 @@ | ||
| User-agent: SiteimproveBot | ||
| Disallow: /versions | ||
| Disallow: /old_site | ||
|
|
||
| # General bots | ||
| # Note: Google does not respect Crawl-delay, but that's fine. | ||
| User-agent: * | ||
| Allow: / | ||
| Allow: /project/*/users/* | ||
| Disallow: /project/ | ||
| Disallow: /api/ | ||
| Crawl-delay: 10 | ||
|
|
||
| # AI crawlers — slower, same path rules duplicated | ||
| User-agent: GPTBot | ||
| User-agent: ClaudeBot | ||
| User-agent: PerplexityBot | ||
| Allow: /project/*/users/* | ||
| Disallow: /project/ | ||
| Disallow: /api/ | ||
| Crawl-delay: 30 |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Bot-mitigation directives that live in server{} context. Included from | ||
| # locations.conf so every server block (prod + staging, both hosts, plus | ||
| # dev) picks them up. The http-context map and limit_req_zone live in | ||
| # nginx.conf.d/snap-bot-mitigation.conf. | ||
|
|
||
| # Serve robots.txt as a static file from the repo. Host-independent — does | ||
| # not depend on the per-host static root or the Lapis app. | ||
| location = /robots.txt { | ||
| access_log off; | ||
| default_type text/plain; | ||
| root html; | ||
| } | ||
|
|
||
| # 403 any user-agent flagged by $snap_block_ua. `return` is one of the few | ||
| # directives that is safe to use inside `if`. | ||
| if ($snap_block_ua) { | ||
| return 403; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Bot-mitigation directives that must live in the http{} context. The | ||
| # matching server-context directives are in snap-bot-mitigation-server.conf, | ||
| # included from locations.conf. | ||
|
|
||
| # UA blocklist for SEO crawlers that ignore robots.txt. \b word-boundaries | ||
| # guard against substring false positives (e.g. "yeti" inside a longer UA). | ||
| map $http_user_agent $snap_block_ua { | ||
| default 0; | ||
| "~*ahrefsbot" 1; | ||
| "~*semrushbot" 1; | ||
| "~*\bdotbot\b" 1; | ||
| "~*mj12bot" 1; | ||
| "~*sleepbot" 1; | ||
| "~*\byeti\b" 1; | ||
| "~*blexbot" 1; | ||
| "~*petalbot" 1; | ||
| } | ||
|
|
||
| # Rate-limit zone for the raw XML at /project/<numeric_id>. The rate is | ||
| # deliberately generous because Snap! is used in classrooms where 20–40 | ||
| # students share one NAT IP; tighten only with evidence from error.log | ||
| # ("limiting requests" lines). | ||
| limit_req_zone $binary_remote_addr zone=snap_project:10m rate=60r/s; | ||
| limit_req_status 429; | ||
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These bots were pull from the user agents of actual request logs for a few days in may.