Skip to content

[ENG-4579] Make firewall log lines match what the guard did - #503

Merged
daniloradovic merged 1 commit into
mainfrom
danilo/eng-4579-firewall-log-entries-do-not-match-the
Nov 20, 2026
Merged

daniloradovic merged 1 commit into
mainfrom
danilo/eng-4579-firewall-log-entries-do-not-match-the

Conversation

@daniloradovic

Copy link
Copy Markdown
Contributor

Closes ENG-4579

What changed

  • fetchGuard (used by the Next.js middleware and other fetch-style templates) hands a queued detection report to the host's waitUntil when one exists, as fetch already does. Without one, delivery is unchanged.
  • A match that did not block is described as "Matched by …" instead of "Blocked by …" in the message passed to onDetect and the console line. Block responses are unchanged.
  • Rules with no category are logged as category=custom instead of category=?.

Why

On hosts that freeze the function after the response (Vercel), a detect-only report waited for a timer or a later request that never came, so detections went missing from the dashboard. Detect-only lines also claimed something was blocked.

Not done, on purpose

Duplicate entries when both the middleware and the route handler screen one request. On Vercel those run as separate invocations, so there is no unforgeable marker to share, and a client-settable header would let an attacker merge away their own detections. Left for a separate design.

How it was verified

  • New test: a detect-only rule under a Vercel request context calls waitUntil, posts the report, and logs DETECT / category=custom / "Matched by". It fails on main.
  • npm run typecheck, npm run build, npm run test:bundled, npx vitest run (4751 passed, 7 skipped).

  • I reviewed the code, comments, fixtures, commit messages, generated output, and PR description for private Patchstack or customer information.
  • Nothing here is third-party confidential or proprietary material. The Vercel behaviour relied on is from Vercel's public docs (vercel.com/docs/deployments/vercel-ignore, vercel.com/docs/cli/env).

Three fixes to the guard's detection reporting and its console line.

A detect-only match on the `fetchGuard` path (the Next.js middleware, and
the other templates that call it) was queued and left for a timer or a
later request to send. On a host that freezes the function after the
response, such as Vercel, neither runs, so the detection never reached
the dashboard. `fetchGuard` now hands the queued report to the host's
`waitUntil` when one is available, as `fetch` already does. Without one,
delivery is unchanged.

A match that did not block was logged as "Blocked by Patchstack WAF rule",
because the engine's default message is written before the rule's mode is
known. The message given to `onDetect`, and so the console line, now says
"Matched by" when the mode is not block. Block responses are unchanged.

Rules with no category, which is how the site's own rules arrive, were
logged as `category=?`. They are now logged as `category=custom`.

Amp-Thread-ID: https://ampcode.com/threads/T-2e659ca3-7bd0-4d70-b3d3-09638251060b
Co-authored-by: Danilo Radovic <danilo@patchstack.com>
@coderbuds

coderbuds Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🎯 Elite quality (97%) — Targeted fix routes fetchGuard detect-only reports through waitUntil and corrects misleading log wording.

📦 Small

🤖 Written by Amp — going by its own attribution. Unknown whether a person read it; agents can report that with the report-ai-usage-tool tool.

🟢 Low risk — 26 lines of code, and nothing that needs a person.

✅ Reviewed — approved by @mariojgt.

See how your team is trending →

Copy link
Copy Markdown
Contributor Author

/review

@daniloradovic
daniloradovic merged commit eefcbe1 into main Nov 20, 2026
28 checks passed
@daniloradovic
daniloradovic deleted the danilo/eng-4579-firewall-log-entries-do-not-match-the branch November 20, 2026 08:38
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.

3 participants