Repository navigation
Description
Problem Description
In production environments (sendEmailOnError = true), CFWheels sends an error email for every unhandled exception in onError.
When a production site is scanned by automated vulnerability bots (requesting hundreds of non-existent paths like /press/?rest_route=/, /wp/index.cfm, /admin.cfm, etc.) or when a recurring runtime error occurs under high traffic, CFWheels sends hundreds or thousands of error emails within minutes. This floods developer inboxes, can trigger SMTP rate limits / reputation blocks, and adds unnecessary load to the server.
Part 1: Feature Request — Error Email Rate-Limiting / Throttling
It would be great to have built-in rate-limiting / throttling for error emails in $runOnErrorSendEmail().
Proposed Behavior & Settings
Instead of sending an email on every single failure, CFWheels could throttle error emails using an in-memory counter in the application.wheels scope:
- Configurable limits, e.g.:
set(errorEmailRateLimit = 3)(maximum number of emails allowed within the time window;0= unlimited / current behavior)set(errorEmailRateWindowMinutes = 15)(or cooldown duration in minutes, e.g., 15–60 minutes)
- Per-Error Fingerprinting (Recommended) or Global Throttling:
- Ideally, throttling should be tracked per error signature (e.g. a hash of
exception.type+exception.message+ toptagContexttemplate/line), with an optional global cap. That way, a high-frequency error does not silence a completely unrelated critical exception occurring during the same window.
- Ideally, throttling should be tracked per error signature (e.g. a hash of
- Suppression Summary:
- Once the cooldown window expires and the error occurs again, include a short notice in the next email (e.g., "Note: 142 occurrences of this error were suppressed in the last 15 minutes.").
Part 2: Related Issue — Bot scans of non-existent .cfm files trigger onError (500) instead of onMissingTemplate (404)
While investigating why bot scans triggered error emails in the first place, we noticed how requests like GET /press/?rest_route=/ end up in onError:
- The web server resolves
/press/viaDirectoryIndex index.cfmto/press/index.cfmand forwards it to the CFML engine. - In
onRequestStart,$abortInvalidRequest()checks:In a flat root installation wherelocal.applicationPath = Replace(ExpandPath("/wheels/Global.cfc"), "\", "/", "all"); local.callingPath = Replace(GetBaseTemplatePath(), "\", "/", "all"); if ( !(GetFileFromPath(local.callingPath) == "runner.cfm") && ListLen(local.callingPath, "/") > ListLen(local.applicationPath, "/") )/wheelsis at/<webroot>/wheels/Global.cfc(depth: 4 segments), any request to a 1st-level subdirectory like/<webroot>/press/index.cfmalso has 4 segments (4 > 4isfalse), and any non-existent root file like/<webroot>/login.cfmhas 3 segments (3 > 4isfalse). - As a result,
$abortInvalidRequest()does not intercept the request, andonRequest()executes:which throwsinclude "#arguments.targetpage#";Page [/press/index.cfm] not found(missinginclude) insideonRequest(), triggeringonError(HTTP 500 + error email) instead ofonMissingTemplate(HTTP 404, no email).
If $abortInvalidRequest() (or onRequest()) also verified whether arguments.targetPage is an allowed entry point (index.cfm, rewrite.cfm, runner.cfm) or whether the target template actually exists before include, missing .cfm scans would cleanly route to onMissingTemplate (404) without triggering onError emails.
Activity
bpamiri commentedon Nov 14, 2026
Thanks for the detailed report — both parts are real, and they're separable.
Part 2 (bug) is reproducible on current develop. When a missing physical
.cfmreachesonRequest,$abortInvalidRequest()'s depth comparison doesn't catch it (/login.cfmand/press/index.cfmboth compare false against the framework path in a flat install), so the include throws andonErrorrenders the 500/fallback path — which is also what can send the email. The correct behavior is a 404 viaonMissingTemplate, with noonErrorand no email. The fix is to validate thattargetPageexists before the include (and set the 404 explicitly), while keeping real.cfmentry points working. I'm implementing that now with an HTTP-level regression test.Part 1 (throttling) is not covered by an existing setting or hook:
sendEmailOnErroris only on/off,onErrorCallbacksruns after the email, andexcludeFromErrorEmailonly redacts scopes. A backward-compatible opt-in looks feasible with per-fingerprint (type + message + first app stack frame) and global fixed-window caps defaulting to unlimited, a suppression count in the next email, and application-scope state under a lock. Two honest caveats: per-fingerprint caps alone won't stop unique bot paths (a global cap is needed), and application-scope state is per node, so exact caps on multi-server deployments need a shared store or provider-side limit.I'd like to land Part 2 as the bug fix, and treat Part 1 as a separate designed feature (settings names/defaults and multi-server semantics need a maintainer decision). I'll post the Part 2 PR here when it's green.
fix(application): 404 missing .cfm templates through onMissingTemplate (
bpamiri commentedon Nov 14, 2026
Part 2 is fixed and shipped in #4702 (
fdbae20e1): missing physical.cfmrequests now return 404 viaonMissingTemplate, with noonErrorfallback and no error email (the new HTTP-levelMissingTemplateSpecfails on the old code and passes now).Reopening because Part 1 — error-email rate limiting — is still a separate feature decision, not shipped. My earlier comment explains the feasible shape (opt-in per-fingerprint + global fixed-window caps, suppression count, application-scope lock; per-node caveat on multi-server). It needs a maintainer call on settings/defaults before implementation.
bpamiri commentedon Nov 20, 2026
Update: the decision-ready implementation brief is written (settings, fingerprint definition, state/locking, code-path shape, tests, docs, MVP slice) and is with the maintainer for a yes/no on the defaults. Part 2 shipped earlier in #4702. Nothing is blocked on reporters; I will post the PR here once the defaults are approved.
bpamiri commentedon Dec 1, 2026
Maintainer decision: the Part 1 settings and defaults are approved as specified.
errorEmailRateLimit0..10000errorEmailRateWindowMinutes1..144015errorEmailGlobalRateLimit0..100000This changes nothing until an app opts in
All three defaults preserve today's behaviour exactly. With both caps at
0the throttle is bypassed and every configured error email is sent as it is now — so merging the implementation is behaviourally inert for every existing app. "Rate limit" in the title invites the assumption that this is a behaviour change; it is an opt-in point. An app turns it on explicitly:The global cap stays in the design
errorEmailGlobalRateLimitis not redundant with the per-fingerprint cap, and it should not be cut later as duplication. The fingerprint istype + message + first application frame, so a bot walking unique paths produces a unique fingerprint per request — the per-fingerprint cap never fires. That is precisely the scenario in this issue. The global cap is the only thing that bounds it.The brief now lives in the repo
The implementation brief was written to
/tmp/issue-4694-throttle-brief.mdand was destroyed by a host restart. It has been recovered from the authoring session and committed as.ai/wheels/design/error-email-throttling.mdin #4719 — settings, fingerprint definition, state/locking, code-path shape, tests, docs and MVP slice, plus the approved status and the global-cap rationale above. Build from that file, not from a scratch path.Implementation will follow as its own PR against that brief. Part 2 (missing
.cfm→ 404 with noonErrorand no email) already shipped in #4702.docs(ai): add error-email throttling implementation brief (#4694) (#4719
fix(events): log the throttle lock warning once and reject a 0-minute…
fix(events): log the throttle lock warning once and reject a 0-minute…
feat(events): throttle error emails per fingerprint and globally (#4694…
bpamiri commentedon Dec 1, 2026
Part 1 implemented in #4721, merged as
c6fb3afe8aaad0dc76407fa416ba66a54f6f837c.What shipped
The three approved settings, with the approved defaults — so an app that does nothing behaves exactly as before:
errorEmailRateLimit(per-fingerprint cap)0..10000errorEmailRateWindowMinutes1..144015errorEmailGlobalRateLimit(global cap)0..100000type|message|first-application-frame, built from the root cause, skippingvendor/wheelsframes, withno-framefallback. Only the hash is stored.application.wheels.errorEmailThrottleunder a named exclusive lock, fixed window, 512-fingerprint cap with eviction — and fail-open: if the lock fails the email is still sent, because insideonErrorsuppressing the email would be worse than the flood.wheels/infosettings list, the CLI settings inventory, the app template'sconfig/settings.cfmas a commented example, consumer docs, and a changelog fragment.Verification
local.writes incatch, nofinallyloops, no function members onapplication, no closures) — which matters here because this code runs insideonError.application.wheels;errorEmailRateWindowMinutesnow rejects0with a warning instead of silently clamping, while both caps still treat0as unlimited.One honest gap, tracked
r2 found that the "warn once" spec asserts the flag but does not count log lines, so a regression that keeps the flag and removes the early return would still pass. The code is correct by inspection; the spec is a partial proof. That is being fixed separately rather than left as a claim of coverage.
What this does not do
Nothing is enabled by default, and there is no on/off switch — opting in is
set(errorEmailRateLimit = …). A per-node deployment gets approximate global caps (stated, not solved). Part 2 (missing.cfm→ 404 with noonErrorand no email) shipped earlier in #4702.