Skip to content
Read everything about Raspberry Pi 5 and other single board Pi PCs, Pi microcontrollers and other news and updates about Pi accessories.
AI Article · 8 min read

Keep Forgejo Public by Locking Only Its Heavy Pages

Why AI crawlers load up public Forgejo servers, how robots.txt, user-agent lists, rate limits and challenge pages fare against crawlers that ignore the rules, and why I would ask for a login only on the heavy pages and switch off archive do...

A small server box with its side open showing a hard drive, a blue network cable and glowing lights on a dusty wooden shelf.

Eighteen months after Jade Ellis described scrapers filling a Forgejo server's disk, Arthur Brugière reported his own Forgejo server under crawler load. His Forgejo container, capped at 512 MB, ran at 118% CPU while bots hit the server at 5 to 10 requests a second. He reported those figures from that one server. His final Caddy setup brought Forgejo back to its normal 0.3%. I think the best way to keep a public forge up is to require a login only for the heavy pages, meaning old commits, blame views and source archives, and to leave the rest open. In my view that beats robots.txt, user-agent lists, rate limits and challenge pages against crawlers that ignore the rules.

Why do crawlers hammer a public Git server?

A forge turns a repository's whole history into links. Every commit, every file at every commit, every blame view and every auto-generated source archive has its own URL, so a crawler that follows links finds far more to fetch than a blog would offer.

A small blog has a few hundred pages. A forge with a handful of repositories has a page for every file at every commit, a diff for every commit and a blame view for every file, and each of those pages links to more of them. A person browsing the code opens only a few of those pages, but a crawler that follows links keeps finding new ones, so the history views pile up quickly.

Archives are the heaviest of these. Jade Ellis found that bots had found the links to auto-generated source archives and were pulling them at up to 100 Mb/s, which filled the disk. A slow page is a nuisance, but a full disk can stop the whole server. I think that makes the archive links the first thing to deal with, ahead of the commit and blame views.

The numbers from Brugière's machine show how little room a small server has. It runs an Intel Atom N2800, and the Forgejo container is capped at 512 MB. His post reports memory use at 416 MiB before his final setup and 274 MiB after it, which left under 100 MiB spare before the change. It also reports cached archives at 2.7 GB before that setup and 9.5 MB after it.

Will robots.txt and user-agent blocks do anything?

They turn away crawlers that follow the rules and name themselves honestly. Against crawlers that ignore robots.txt or arrive through home connections, they do little.

The quickest step is a blocklist. The ai.robots.txt project keeps a list of AI crawlers and ships a Caddyfile with a header regex matcher group for their user agents. You can copy that group into your own Caddyfile or import it, and requests that match are rejected with abort. Because the list takes in AI-related crawlers of all types, regardless of purpose, it can also turn away bots that some owners would rather let through.

Both tools depend on the crawler playing along. The bots that hit Ellis's server ignored robots.txt, although Google respected it. Brugière's crawlers came through residential proxy networks, which rent bandwidth on ordinary home and mobile connections, so the traffic looked like regular people and his IP bans did nothing. A user-agent list can only catch a crawler that tells the truth about its name.

Robots.txt and the ai.robots.txt matcher are quick to set up and keep the well-behaved bots away from the heavy pages, and I would still add both. But they leave the decision with the crawler, and a small forge has to survive the crawler that decides badly. Ellis also tried CrowdSec blocklists, which had little effect, so I would not lean on shared lists to fill that gap either.

Per-IP rate limits only stop a single noisy client

A per-IP limit catches one noisy address, but crawlers on residential proxies arrive from many addresses, and a limit tight enough to bite starts hurting real users and tools.

The caddy-ratelimit module is a third-party module that needs xcaddy, and its repository says it is not an official repository of the Caddy Web Server organization. You build a custom Caddy binary with the module compiled in, then set your limits in the Caddyfile. Clients that go over a limit get a 429 response with a Retry-After header telling them when to try again.

xcaddy build --with github.com/mholt/caddy-ratelimit

Limits can be keyed on the client's IP address, which handles one crawler hammering you from one address. Brugière's IP bans did nothing against residential proxies, and a per-IP limit is keyed on the same thing a ban is. On IPv6, caddy-ratelimit puts all addresses within the same /64 into a single rate limit bucket. A loose limit still stops one runaway script, and I would keep one for that.

But a tighter limit has its own cost. Ellis found that tight rate limits caused issues for automated tools and legitimate users, and those are exactly the visitors a public forge exists to serve. I think that leaves per-IP limiting as a backstop for the single noisy client, sitting behind whatever actually decides which pages a stranger can load. It should not be the main defence on any public instance.

Are challenge pages worth the wait?

Cookie checks stop only simple scripts. Proof-of-work gates can do more, but they put a step in front of every visitor, so I would keep them off a public forge.

The cheapest challenge is a cookie. Yann Esposito checks every request for a specific cookie, and visitors without it get a JavaScript page that sets it, so his check requires JavaScript in the browser. He says openly that it would be easy to bypass. In Brugière's experience the trick filters only the simplest scrapers, and headless browsers, which run JavaScript like any other browser, get straight through it.

Proof-of-work tools go further. Anubis warns in its own documentation that a site using it will be blocked from smaller scrapers and that good bots may be blocked too. Jade Ellis put the go-away challenge proxy in front of Forgejo, and it dropped bot requests. Users reported no other issues with it, and by that account it is nearly invisible during normal usage.

Brugière looked at Anubis and turned it down for the wait it adds: "I don’t want a proof-of-work loading screen between me and my own stuff." Go-away's record shows a challenge can stay mostly out of the way. Even so, every request still passes through a gate that guesses who is human, on a site that exists so people can read and clone code. I think that guess belongs on far fewer pages.

What should the Caddy setup in front of Forgejo look like?

In my view, it should ask for a Forgejo login only on the heavy pages, pass everything else straight through, and work alongside Forgejo's own switch for archive downloads.

The shape I would aim for is narrow. A path matcher in Caddy picks out commit, history, blame, compare and archive URLs, and Caddy's forward_auth directive sends those requests to an authentication check before they reach Forgejo. Everything else, Git cloning included, goes straight through to Forgejo. That is more work than one line in app.ini, but it leaves the rest of the forge open to strangers.

Write that matcher against a setup that has already faced real crawlers. Brugière's post walks through the final Caddy setup that took his Forgejo from 118% CPU back to its normal 0.3%, so compare against it before you deploy anything of your own. His aim was plain: "Anyone should be able to read and clone the open stuff." Any gate you add should leave that intact.

Switch archives off in Forgejo itself as well. Forgejo has a repository setting that stops source archive files being downloaded from the UI, and it is off by default. Add it to app.ini and restart Forgejo. Given what archive downloads did to Ellis's disk, I would set this before any Caddy work, and keep the archive path in the matcher as a second layer.

[repository]
DISABLE_DOWNLOAD_SOURCE_ARCHIVES = true

The blunt alternative is REQUIRE_SIGNIN_VIEW, which is also off by default. It is a single setting, and it forces users to log in to view any page or to use the API, so a crawler without an account gets nothing at all. But it makes the instance non-public, which is the opposite of what this setup is for. Gating only the heavy paths is a much narrower change, and I think the right one.

Against crawlers that ignore the rules, robots.txt was honoured by Google and ignored by the bots that hit Ellis's server. User-agent lists catch only the crawlers that name themselves. Per-IP rate limits miss traffic spread over residential proxies, and tight ones hurt real users and their tools. Cookie checks stop simple scripts and let headless browsers through, which leaves them as a filter for the crudest bots only.

Proof-of-work gates can work, and go-away stayed nearly invisible for one forge's users, but Anubis warns it can block smaller scrapers and good bots, and every visitor meets the challenge. In my view, login-gating the heavy pages does better than all of them, because it asks for an account instead of guessing who is human, and it leaves cloning and the rest of the forge open.

I would give up anonymous browsing of old commits, archives and blame views in the web interface to keep a public Forgejo instance that stays up.

Written by Peter Njoroge

Peter Njoroge writes about artificial intelligence and what the latest AI news actually means.

14 articles →