Skip to content

Harden Rack::Attack and pagination against aggressive web crawlers - #4772

Open
CloCkWeRX wants to merge 2 commits into
devfrom
harden-rack-attack-crawlers-2674394950484400196
Open

Harden Rack::Attack and pagination against aggressive web crawlers#4772
CloCkWeRX wants to merge 2 commits into
devfrom
harden-rack-attack-crawlers-2674394950484400196

Conversation

@CloCkWeRX

Copy link
Copy Markdown
Collaborator

This change hardens the Rack::Attack configuration against abusive web crawlers:

  1. Daily Page Crawl Rate Limit: Configured Allow2Ban in config/initializers/rack_attack.rb to ban IPs that request more than 500 pages in a 24-hour period for 1 week (7 days).
  2. Honeypot Ban Route: Disallowed /dont-crawl-me in public/robots.txt and config/robots.txt, created the GET route in config/routes.rb, and configured Fail2Ban in Rack::Attack to ban any IP visiting /dont-crawl-me for 7 days upon 1 hit.
  3. Out-Of-Bounds Pagination Handling: Updated PhotosController#index to raise ActiveRecord::RecordNotFound when @photos.out_of_bounds? (e.g. requesting page=105 when fewer pages exist), returning HTTP 404 Not Found to stop crawlers from endlessly probing invalid page numbers.
  4. Automated Specs: Added spec/requests/rack_attack_spec.rb and updated spec/controllers/photos_controller_spec.rb to verify honeypot banning, rate limit banning, and 404 pagination responses.

PR created automatically by Jules for task 2674394950484400196 started by @CloCkWeRX

- Configure Allow2Ban in Rack::Attack to ban IPs requesting >500 pages per day for 1 week (7 days).
- Add honeypot route /dont-crawl-me disallowed in robots.txt and configure Fail2Ban in Rack::Attack to ban IPs visiting it for 7 days upon 1 hit.
- Update PhotosController#index to raise ActiveRecord::RecordNotFound when page parameter is out of bounds, returning 404 Not Found to crawlers instead of 200 OK.
- Add request and controller specs for Rack::Attack rules and pagination 404 responses.

Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Remove error handling from index_everything method.
@CloCkWeRX

Copy link
Copy Markdown
Collaborator Author

@cesy what do you reckon with this?

Production logs are all useless crawlers galore (semrush and clones), and a fair few end up on abuse lists.
This adds an explicit don't crawl page which bans you if you do, not linked to from anywhere. Bit nuclear, but it should cut down non human traffic that ignores robots.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant