r/webdev • • 16h ago

Discussion I am getting cooked by bot traffic.

Post image

why this is happening. Is this normal? I’m using Cloudflare and have already blocked several countries. My application is built with Next.js. What should I do to get rid of bot problem. Or it's inevitable.

25 Upvotes

19 comments sorted by

22

u/ReiOokami 16h ago edited 12h ago

Robots.txt, captcha, rate limit, login wall, paywall, cache, cdn, lots of things you can do to help.

Unfortunately nothing you can do to stop it esp in this ai agent data scraping world these days.

5

u/fullbl-_- 16h ago

Search for patterns in logs and set up fail2ban!

3

u/malwaremel 15h ago

Before changing anything, check Cloudflare analytics for which paths, user agents and ASNs the traffic is hitting. If it's concentrated on a few URLs, a rate limit rule on just those is cheap and effective. Blocking countries rarely helps much since scrapers mostly run from cloud IPs everywhere, so a managed challenge on the hot paths usually does more.

3

u/armin3d 14h ago

Getting scraped that hard is fairly normal once a site is live, so the practical goal is keeping the bots out of your numbers rather than stopping them entirely.

A few things that help:

  • Check what they are actually hitting first (paths, user agents, ASNs) instead of blocking whole countries. Headless scrapers often come from residential or cloud IPs, so country blocks will not touch them.
  • If the traffic concentrates on a few URLs, rate-limit or JS-challenge only those paths. Legitimate visitors never notice, and it filters most automated scraping.
  • Watch how your analytics counts them. Many tools log a 0s-visit headless browser the same as a human, which is exactly why a site can look "cooked". If your tool can separate real visitors from bots in the report, your engagement and conversion numbers stay usable while you tune the blocking.

(I work on Hitsteps, a web analytics tool that separates real visitors from bots in its reports - happy to explain the approach if it helps.)

2

u/virtualgeek15 16h ago

Umami is awful at blocking bots from reporting, too.

2

u/ramirex 11h ago

unless you’re on some free vps I wouldn’t call 2k visits getting cooked

1

u/leechdemon 16h ago

Try to find out what URLs are being visited; are they legit ones, or weird url variable ones? (Page.html?var=sjejajdufne)

If they're legit, many hosts have ways to force redirects for bots. If they're fake, figure out how you got hacked. 🫤

1

u/Agent360dk 15h ago

Cloudflare plus country blocks usually doesn't do much against this kind of traffic since most of it comes from residential or cloud IPs anyway. First thing I'd do is look at what they're actually hitting. If it's mostly your Next.js API routes or /_next/image, put a rate limit rule on those paths in Cloudflare and turn on Bot Fight Mode (or a managed challenge for requests with no cookies and weird user agents). Also check you're caching static and ISR pages at the edge, because uncached SSR hits are what actually cost you. A lot of the AI scrapers now run real headless Chrome so robots.txt and UA checks won't stop them, only rate limits and challenges do.

1

u/Late-Coast6973 15h ago

0s visits with a 99% bounce that Umami still counts means these clients run your JavaScript, so they're headless browsers, not simple scrapers. On my own site most of those turned out to be crawlers. Blocking countries misses them because they come from cloud IPs; check the ASN in Cloudflare's security events and challenge the hosting ASNs with a WAF rule.

1

u/brat_generatorpro 14h ago

That 0s visit / 99% bounce pattern is a strong tell — real visitors rarely behave that uniformly. Checking which paths, user agents and ASNs dominate in Cloudflare, as others suggested, is probably the quickest way to separate scrapers from real traffic before adding heavier blocks.

1

u/Aide_Sea 13h ago

Honestly the first question is whether it's actually costing you anything. If it's just ugly numbers in Umami, that's every public site lol. If your bill or server load is climbing, then it's worth chasing..

1

u/Gremlation 3h ago

What should I do to get rid of bot problem.

What problem? Your stats max out at about 500 views per hour. This is a tiny amount of traffic even a low powered server can handle with ease. What do you mean you're "getting cooked"? What do you think "cooked" means?

1

u/mcmron 1h ago

Did you enable the CF option to disable traffics from AI bots?

•

u/codescaptainTr 23m ago

Country blocks rarely help: most scraper traffic comes from US/EU datacenter ranges, not from the countries people block. Before adding more rules, sort the Cloudflare analytics by path and user agent instead of by country. The pattern is usually one of three: API or data endpoints being hammered, query-param variations of the same URL (?page=9999, tracking params), or old URLs that now 404.

Then the fixes line up with what you see:

  1. Cloudflare's "block AI bots" toggle plus a managed challenge on anything that isn't a plain GET to a known page. Cheap, no false positives for real users.
  2. Rate limiting per IP on the API routes (Cloudflare rules, or Vercel's firewall if you deploy there). Scrapers back off quickly on 429s.
  3. Return 410 for dead URLs instead of letting them render a 404 page through Next, and reject junk query params early in middleware.
  4. Make the hits that get through cheap: edge-cache the HTML for anonymous visitors so a bot request never reaches a DB.
  5. An honest robots.txt; the polite crawlers do read it, and they are a bigger share than the chart suggests.

You won't get it to zero, and that's fine. The metric to watch isn't request count, it's requests that reach compute or your database. Once those are flat, the rest is just a chart.

1

u/quantable_analytics 15h ago

If it's not behind a login, it's going to get scraped constantly. Robots.txt does stop a lot of the crawling by the legitimate services, but not everyone. I'd suggest a full robots.txt block and then only whitelist the crawlers you actually want. As far as keeping it out of your analytics, I will say that Rybbit or Plausible do a better job with bot filtering than Umami but still they will miss a lot of things that don't declare themselves. If you are dedicated to identifying and/or rooting it out then a bot service like mine can help but if you're a small site with Cloudflare already that might not be worth it for you unless it's really breaking things.

1

u/michaelbelgium full-stack 11h ago

Don't use cloudflare. They're specificly getting targetted.

(Source: my websites don't have cloudflare and never get attacked)

0

u/Vegetable-Capital-54 16h ago edited 15h ago

How does "getting cooked" manifest, and what makes you worry about "bot problem"?

Personally, I run many websites, some for 20+ years, and I have never done anything to block bots. So far I have not noticed any negative effects from it. Aside from the very mild annoyance of making the stats graphs look less smooth on smallest sites, they don't really affect me in any way. It costs me nothing, it has no effect on real users, so why should I put in effort trying to block them? To me blocking whole countries just to have slightly cleaner logs seems like a crazy overreaction.