Shun clients that probe for missing paths, and log response statuses #22

Merged
james merged 2 commits from recon-404 into main 2026-10-27 16:38:17 +00:00
Owner

Centinela had no way to recognise scanners. Over the last 7 days, 777 WordPress/PHP
probes hit the Ghost blog (/wp-login.php, /xmlrpc.php, /.env.php, …):

  • 132 were let through without a model call (CRS scores them 0).
  • The model allowed another 109 (r2's recon score stayed under 0.5).

Ghost answered all of them with 404.

In proxy mode Centinela forwards each request to the app and sees the response. This PR
uses that: a client that keeps asking for paths that don't exist is scanning.

Changes

Response status in the decision log. In proxy mode each decision line now waits
for the response headers and includes status: the code the client got (the upstream's,
or Centinela's own 403/429).

  • Websockets and streaming responses are logged when their headers go out, not when
    they close.
  • ms is still the time to the decision.
  • Forward-auth and /v1/inspect lines are unchanged.

404 recon detection. CENTINELA_RECON_404_AFTER (default 0, off) shuns a client
for CENTINELA_SHUN_TTL once that many distinct paths it asked for came back 404 or 410
within CENTINELA_RECON_404_WINDOW (default 1m).

  • Each shun is logged as client shunned with reason=recon, and counted in the
    centinela_recon_shuns metric.
  • Not counted:
    • requests Centinela refused, and repeats of a path already counted;
    • paths browsers and crawlers request on their own (favicon*, robots.txt,
      /.well-known/, sitemaps, …);
    • page subresources (Sec-Fetch-Dest other than document/iframe/frame), so a
      post with broken images can't get a reader shunned;
    • CENTINELA_RATE_LIMIT_EXEMPT networks.
  • With CENTINELA_STATE_URL, the counts are a Valkey set per client, so misses on every
    replica add up. POST /unshun clears them.

Training log ID. Training log entries now use the request's id, the same as its
decision log line, so a model input can be matched to its outcome and, later, to a
reviewer's label. This is the first step of the labeling plan.

Docs. README sections on the decision log, client checks, training log, settings
and planned work are updated.

Testing

  • Engine: shuns at the threshold; repeats don't count; refused requests don't count;
    every exclusion (routine paths, subresources, exempt networks); off by default; two
    replicas sharing counts through Valkey; unshun clears misses; the status is logged
    exactly once.
  • Proxy, end to end through the reverse proxy: statuses 200/404/404, then 403 once the
    client is shunned. The status is logged while a streaming response is still open.
  • Breaking the counter or the subresource check on purpose makes the tests fail.
  • go vet, go test ./... and go test -race (engine, proxy) pass.

Rollout

Merging changes nothing until gitops sets CENTINELA_RECON_404_AFTER (suggested: 10)
along with the new image. Watch for reason=recon shuns in the logs after enabling it.

Centinela had no way to recognise scanners. Over the last 7 days, 777 WordPress/PHP probes hit the Ghost blog (`/wp-login.php`, `/xmlrpc.php`, `/.env.php`, …): - 132 were let through without a model call (CRS scores them 0). - The model allowed another 109 (r2's recon score stayed under 0.5). Ghost answered all of them with 404. In proxy mode Centinela forwards each request to the app and sees the response. This PR uses that: a client that keeps asking for paths that don't exist is scanning. ## Changes **Response status in the decision log.** In proxy mode each `decision` line now waits for the response headers and includes `status`: the code the client got (the upstream's, or Centinela's own 403/429). - Websockets and streaming responses are logged when their headers go out, not when they close. - `ms` is still the time to the decision. - Forward-auth and `/v1/inspect` lines are unchanged. **404 recon detection.** `CENTINELA_RECON_404_AFTER` (default `0`, off) shuns a client for `CENTINELA_SHUN_TTL` once that many distinct paths it asked for came back 404 or 410 within `CENTINELA_RECON_404_WINDOW` (default `1m`). - Each shun is logged as `client shunned` with `reason=recon`, and counted in the `centinela_recon_shuns` metric. - Not counted: - requests Centinela refused, and repeats of a path already counted; - paths browsers and crawlers request on their own (`favicon*`, `robots.txt`, `/.well-known/`, sitemaps, …); - page subresources (`Sec-Fetch-Dest` other than `document`/`iframe`/`frame`), so a post with broken images can't get a reader shunned; - `CENTINELA_RATE_LIMIT_EXEMPT` networks. - With `CENTINELA_STATE_URL`, the counts are a Valkey set per client, so misses on every replica add up. `POST /unshun` clears them. **Training log ID.** Training log entries now use the request's `id`, the same as its decision log line, so a model input can be matched to its outcome and, later, to a reviewer's label. This is the first step of the labeling plan. **Docs.** README sections on the decision log, client checks, training log, settings and planned work are updated. ## Testing - Engine: shuns at the threshold; repeats don't count; refused requests don't count; every exclusion (routine paths, subresources, exempt networks); off by default; two replicas sharing counts through Valkey; unshun clears misses; the status is logged exactly once. - Proxy, end to end through the reverse proxy: statuses 200/404/404, then 403 once the client is shunned. The status is logged while a streaming response is still open. - Breaking the counter or the subresource check on purpose makes the tests fail. - `go vet`, `go test ./...` and `go test -race` (engine, proxy) pass. ## Rollout Merging changes nothing until gitops sets `CENTINELA_RECON_404_AFTER` (suggested: `10`) along with the new image. Watch for `reason=recon` shuns in the logs after enabling it.
In proxy mode the decision log line now waits for the response headers
and carries the status the client got. A websocket or streaming response
is logged when its headers go out, not when it closes. ms is still the
time to the decision.

CENTINELA_RECON_404_AFTER (default 0, off) shuns a client once that many
distinct paths it asked for came back 404 or 410 within
CENTINELA_RECON_404_WINDOW (default 1m). Scanners probing for
/wp-login.php, /.env and the like on sites that have none of them get
shut out without a rule per site or a model call. Not counted:

- refused requests, and repeats of a path already counted;
- paths browsers and crawlers ask for unprompted (favicon, robots.txt,
  /.well-known/, sitemaps, ...);
- requests a browser marks as page subresources with Sec-Fetch-Dest, so a
  post with broken images cannot get its reader shunned;
- CENTINELA_RATE_LIMIT_EXEMPT networks.

With shared state the distinct paths are a Valkey set per client, so
misses on every replica add up, and unshun clears them.

Training log samples now carry the request's id, the same one as its
decision log line, so a sample can be matched to its outcome.
Document recon detection and response statuses
All checks were successful
test / laya (pull_request) Successful in 4s
security-scan / security-scan (pull_request) Successful in 1m16s
test / go (pull_request) Successful in 1m49s
4215611e85

🔎 ojo scan results

Severity Count
🟠 HIGH 1
Details (1)
Type Severity ID/Rule Location Description
sast 🟠 HIGH go-ssrf internal/proxy/recon_test.go:102 http.Get URL argument is built via Sprintf/concatenation, or is a local variable derived from request/env input, rather than a validated/allowlisted URL
<!-- ojo-scan-summary --> ### 🔎 ojo scan results | Severity | Count | |---|---| | 🟠 HIGH | 1 | <details><summary>Details (1)</summary> | Type | Severity | ID/Rule | Location | Description | |---|---|---|---|---| | sast | 🟠 HIGH | go-ssrf | <a href="https://git.colibrisec.org/ColibriSec/centinela/src/commit/4215611e85e958e450ed54bd41076fc20c1b253e/internal/proxy/recon_test.go#L102" target="_blank" rel="noopener noreferrer">internal/proxy/recon_test.go:102</a> | http.Get URL argument is built via Sprintf/concatenation, or is a local variable derived from request/env input, rather than a validated/allowlisted URL | </details>
james merged commit 8de833a987 into main 2026-10-27 16:38:17 +00:00
james deleted branch recon-404 2026-10-27 16:38:17 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ColibriSec/centinela!22
No description provided.