fix(miniflare): local send_email accepts more than 50 recipients

Open Beginner friendly
#17,175 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
backend, testing

Research direction

Read packages/miniflare/src/workers/email/send_email.worker.ts, especially validateMessageBuilder and the message recording path cited in the report. Compare the local validation with the Workers API's 50-recipient limit, then run the supplied reproduction against a local Wrangler session. Done means 1 and 50 recipients still succeed, 51 rejects, and Local Explorer records only the successful sends.

Written by the indexing model from the issue text.

Description

What versions & operating system are you using?

Linux x86_64, Node.js 26.12.0, npm-published Wrangler 4.168.0 with Miniflare 5.20261123.1-beta and workerd 1.20261123.1. Source inspected on current main.

Please provide a link to a minimal reproduction

The complete reproduction is inline under Steps to reproduce.

Describe the Bug
Summary

A structured send through an unrestricted send_email binding in local Wrangler succeeds and writes a Local Explorer record for 51 recipients across to, cc, and bcc. This lets local integration tests accept a request the documented Workers API rejects.

Steps to reproduce
  1. Save the Worker and configuration below in a fresh directory, then start Wrangler in local mode:
npx [email protected] dev --local --ip 127.0.0.1 --port 0

Save this configuration as wrangler.json.

Reproduction script: wrangler.json
{"name":"email-recipient-count","main":"worker.mjs","compatibility_date":"2026-11-25","send_email":[{"name":"EMAIL"}]}

Save this Worker as worker.mjs. It exercises the binding from a local HTTP handler and returns either the message ID or the binding error.

Reproduction script: worker.mjs
export default {
  async fetch(request, env) {
    const { to, cc, bcc } = await request.json();
    try {
      const sent = await env.EMAIL.send({
        from: "[email protected]", to, cc, bcc,
        subject: "Recipient count probe", text: "Local simulation",
      });
      return Response.json(sent);
    } catch (error) {
      return Response.json({ code: error.code, message: error.message }, { status: 400 });
    }
  },
};
  1. Save the probe below as reproduce.mjs and pass it the loopback URL from Wrangler's Ready on line, replacing PORT with the printed port. It exercises 1, 50, and 51 distinct placeholder addresses, reports the handler status, and verifies any returned message ID and recipient count against the Local Explorer capture. It requires Node.js and a running local development session.
node reproduce.mjs http://127.0.0.1:PORT
Reproduction script: reproduce.mjs
import assert from "node:assert/strict";

const base = new URL(process.argv[2]);
assert.equal(base.hostname, "127.0.0.1");

const addresses = (prefix, count) =>
  Array.from({ length: count }, (_, index) => `${prefix}${index}@example.com`);

for (const [expected, to, cc, bcc] of [
  [1, addresses("to", 1), [], []],
  [50, addresses("to", 20), addresses("cc", 20), addresses("bcc", 10)],
  [51, addresses("to", 21), addresses("cc", 20), addresses("bcc", 10)],
]) {
  const response = await fetch(base, {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({ to, cc, bcc }),
  });
  const result = await response.json();
  if (!response.ok) {
    console.log(expected, response.status, result.code ?? result.message);
    continue;
  }
  const lookup = new URL("/cdn-cgi/local/explorer/api/local/email/sending", base);
  lookup.searchParams.set("email_id", result.messageId);
  const record = await fetch(lookup);
  assert.equal(record.status, 200);
  const { result: stored } = await record.json();
  assert.equal(stored.messageId, result.messageId);
  const count = (stored.to?.length ?? 0) + (stored.cc?.length ?? 0) + (stored.bcc?.length ?? 0);
  assert.equal(count, expected);
  console.log(expected, response.status, "stored recipients", count);
}
Expected behavior

The structured Workers API limits the sum of to, cc, and bcc to 50 and documents E_TOO_MANY_RECIPIENTS above that limit. A local test at 51 should observe the validation failure before it gets a successful send or a captured message. The local simulator guide does not list a recipient-count exception.

Actual behavior

The local handler returned a message ID at 51, and Local Explorer returned a record with the same ID and all 51 addresses. The 1- and 50-recipient controls also succeeded. This was a loopback-only test with no remote binding or delivery.

1 200 stored recipients 1
50 200 stored recipients 50
51 200 stored recipients 51
Evidence
  • Expected source: Email Sending Workers API, including E_TOO_MANY_RECIPIENTS under Error codes, and the local sending guide.
  • Failure source: The local probe and Local Explorer capture above. The current default-branch source listed below validates configured sender and recipient restrictions in validateMessageBuilder and then records the message without comparing the combined recipient count to 50.
  • Evidence provenance: observed
  • Local verification: reproduced
  • Reproduction completeness: complete

Miniflare's overview invites reports for undocumented differences from the deployed environment. Production error behavior here is from the published contract.

Restoration check

Run the probe in a fresh local session. The 1- and 50-recipient controls still return IDs and the 51-recipient case rejects with the recipient-limit signal. Then list sent messages at /cdn-cgi/local/explorer/api/local/email/sending in that session and verify that only the two controls were captured.

References
Triage assessment
  • Impact level: P2
  • Assessment status: supported
  • Impact basis: Local integration tests that count on the binding to reject an oversized recipient list can pass incorrectly. The effect is confined to local simulation of this boundary and does not establish any live sending failure.
  • Workaround status: unverified
  • Workaround basis: A remote binding should expose the documented service-side validation, but the probe used only the local simulator and did not verify that route.
Dominant language
TypeScript
Stars
4.7k
Forks
1.7k
Avg merge
1d 22h
Merged PRs (30d)
282

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/workers-sdk

All issues in cloudflare/workers-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.