# Three gates at the website edge: blocking scan paths, limiting password attempts, and adding headers

> Using one firewall rule on Cloudflare's free plan to block scans for .env and .git, one rate-limiting rule to block brute-force password guessing, and then adding HSTS and anti-embedding headers. Each item comes with console steps, and each has a control check: what should be blocked is blocked, and normal requests are not blocked by mistake.

Published 2026-11-22 · Updated 2026-11-22 · URL https://wizerdbache.com/en/notes/site-security-edge-rules/


Accounts ([chapter 2](https://wizerdbache.com/en/notes/site-security-google-login-2fa/)) and domains ([chapter 3](https://wizerdbache.com/en/notes/site-security-domain-email-spoofing/)) are done; the website itself comes last. The first two gates are rules at Cloudflare's edge, where requests are handled before they ever reach the website; the third is the response headers the website itself sends.

For each gate I run two kinds of checks:

- **Positive control**: what should be blocked actually is.
- **Negative control**: normal pages are not blocked by mistake. When a rule is written wrongly, this is the first thing to break, so it matters as much as the positive control.

## Gate 1: blocking scan paths

The `.env` scans mentioned in [chapter 1](https://wizerdbache.com/en/notes/site-security-what-attackers-want/) are bots that go site by site trying a fixed set of paths. My site never had these files (every test returns 404), but blocking them at the edge has two benefits: firewall rules run before the Worker, so blocked requests should not count against the Worker's daily free quota (this is my inference from the order of execution); and when I later look at the firewall logs, I can see that someone has been trying.

My rule: if the path, converted to lowercase, contains any of `/.env`, `/.git`, `/.aws`, `/.ssh`, `/.dev.vars`, `/.ds_store`, `/wp-`, or ends with `.php`, it is blocked. My site has no PHP or WordPress at all, so no normal reader will ever reach these paths.

**Steps**

1. In the Cloudflare console, select your domain → the **Security rules** page.
2. **Create rule** → **Custom rules**, and give **Rule name** a readable name, for example `Block secret-file and CMS scan paths`.
3. Next to **Expression Preview**, select **Edit expression**, and paste:

```text
(lower(http.request.uri.path) contains "/.env") or
(lower(http.request.uri.path) contains "/.git") or
(lower(http.request.uri.path) contains "/.aws") or
(lower(http.request.uri.path) contains "/.ssh") or
(lower(http.request.uri.path) contains "/.dev.vars") or
(lower(http.request.uri.path) contains "/.ds_store") or
(lower(http.request.uri.path) contains "/wp-") or
(ends_with(lower(http.request.uri.path), ".php"))
```

4. Choose **Block** under **Then take action**, and click **Deploy**.

If you are unsure whether it will cause false blocks, Cloudflare's official advice is to use **Managed Challenge** on the free plan first (the visitor passes a verification step), check what has been caught on the security events page, and switch to Block once you are confident there are no problems.

**If your site uses WordPress or PHP, do not copy this rule as is**: `/wp-` and `.php` would block your own site. Also note that the rule is “path contains”: `/.git` would also block paths starting with `/.github/`, and `/wp-` would block any article whose URL happens to contain `/wp-`; avoid these when you write your URLs later.

**Verification** (replace `example.com` with your domain):

```powershell
foreach ($p in "/.env", "/.git/config", "/wp-login.php") { "$p " + (curl.exe -s -o NUL -w "%{http_code}" "https://example.com$p") }
```

```powershell
foreach ($p in "/", "/robots.txt") { "$p " + (curl.exe -s -o NUL -w "%{http_code}" "https://example.com$p") }
```

In the first command, all three should return `403` (positive control); in the second, you should get `200`, not `403` (negative control).

## Gate 2: limiting password attempts

I have two password-protected subdomains, and the unlock page checks the password on the server side after receiving it. The comparison itself is fine, but **there is no attempt limit**: in theory, someone can keep guessing.

My rule: if the same IP sends more than 5 requests to the unlock page `/__unlock` within 10 seconds, that IP is blocked for 10 seconds.

The free plan's rate limiting can do only so much: it allows just 1 rule, the counting period and block duration can each only be set to 10 seconds, and counting is by IP only. That is enough to block password brute-forcing: at most 5 tries every 10 seconds, which does not get far in a day.

**Steps**

1. On the same **Security rules** page → **Create rule** → **Rate limiting rules**.
2. **Rule name**, for example `Throttle password unlock attempts`.
3. Set the condition to path (**Path**, which may appear as URI Path) equals `/__unlock` (replace it with the path of your own unlock page). On the free plan, the only conditions available are path and Verified Bot; you cannot specify POST.
4. **With the same characteristics**: IP (the free plan only allows this).
5. **When rate exceeds**: Requests `5`, Period `10 seconds`.
6. **Then take action**: **Block**; **Duration** `10 seconds`, then click **Deploy**.

**Verification**: send a dozen or so wrong passwords to the unlock page in a row; the first few should return `401` (wrong password), and after that `429` (rate limited) should appear.

One thing to note: in my tests, the counting was not that precise. On the first test, 429 started on the 6th attempt; on another test the same day, it started on the 8th. So my automated check sends at most 15 requests and looks for a 429, rather than requiring that the 6th request is always blocked; otherwise it would treat normal variation as a broken rule. If you happen to be signing in yourself during testing, you will also be blocked for 10 seconds.

## Gate 3: adding two headers

My site sets its response headers through a `_headers` file. [Chapter 7 of the website-building series](https://wizerdbache.com/en/notes/personal-site-security/) already set `nosniff` and a few others; this time I added two more:

| Header | Value I set | Purpose |
|---|---|---|
| `Strict-Transport-Security` (HSTS) | `max-age=15552000` (6 months) | The browser remembers that this site may only be used over https; after that, typing an http address goes straight to https. On a first visit, or after the memory expires, the browser may still go over http once (to avoid even that, you need preload) |
| `X-Frame-Options` | `DENY` | Stops other sites from embedding my pages in their frames, which prevents clickjacking |

**Steps**: in the `_headers` file in the site’s root directory (mine is at `public/_headers`), add two lines under `/*`:

```text
/*
  X-Frame-Options: DENY
  Strict-Transport-Security: max-age=15552000
```

After deploying, use `curl.exe -sI https://example.com/` to check whether the two lines appear in the response. Check the live response, not just what the config file says.

**Why HSTS is set to 6 months and not `preload`**: once a browser has remembered HSTS, revoking it requires sending `max-age=0`, and it only takes effect after each visitor’s browser connects over https again; `preload` means submitting the domain to the list built into browsers, and revoking that takes several weeks. Until I am sure the site will only ever use https in the long term, I will stay conservative. I also did not add `includeSubDomains`.

**My own exception**: some pages on the site embed my own slide PDFs, and `DENY` would block even those. For those paths, I changed it to allow embedding only from the same site (`frame-ancestors 'self'`). After setting up anti-embedding, remember to check whether your own pages embed other pages.

## What I deliberately did not do

- **Bot Fight Mode**: the free plan cannot make exceptions, so it may also block AI crawlers that I have decided to allow.
- **The old web-based admin page**: it loads code from an external CDN, which is exactly the route where the launcher from chapter 1 went wrong, and I no longer use it. I removed it outright, and that address now returns 404.

## Free-plan limits

| Item | Free-plan limit | What I used |
|---|---|---|
| Custom firewall rules | 5 rules | 1 rule |
| Rate limiting rules | 1 rule, with the period and block duration only settable to 10 seconds | 1 rule |

A single custom rule can combine many conditions using `or`, so 5 rules is plenty for a personal site.

## Sources

- [Cloudflare WAF: Create a custom rule in the dashboard](https://developers.cloudflare.com/waf/custom-rules/create-dashboard/) (Official)
- [Cloudflare WAF: Custom rules (number of rules per plan)](https://developers.cloudflare.com/waf/custom-rules/) (Official)
- [Cloudflare WAF: Rate limiting rules (capabilities per plan)](https://developers.cloudflare.com/waf/rate-limiting-rules/) (Official)
- [Cloudflare WAF: Create a rate limiting rule in the dashboard](https://developers.cloudflare.com/waf/rate-limiting-rules/create-zone-dashboard/) (Official)
- [Workers static assets: Headers (_headers file)](https://developers.cloudflare.com/workers/static-assets/headers/) (Official)
- [MDN: Strict-Transport-Security](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/Strict-Transport-Security) (MDN)
- [HSTS Preload List: Removal](https://hstspreload.org/removal/) (Official)
- [MDN: X-Frame-Options](https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/X-Frame-Options) (MDN)
