Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(lead): reject non-string email inputs (#2854)

Qiu2761a7f20fe0
diff --git a/.github/scripts/functions-lead-test.mjs b/.github/scripts/functions-lead-test.mjs
index 56ddcdbef..0ea2af241 100644
--- a/.github/scripts/functions-lead-test.mjs
+++ b/.github/scripts/functions-lead-test.mjs
@@ -44,6 +44,10 @@ const invalid = [
['boolean email', '{"email":true}'],
['object email', '{"email":{}}'],
['empty email array', '{"email":[]}'],
+ ['single-address email array', '{"email":["[email protected]"]}'],
+ ['multiple-address email array', '{"email":["[email protected]","[email protected]"]}'],
+ ['email object with null toString', '{"email":{"toString":null}}'],
+ ['email object with string toString', '{"email":{"toString":"[email protected]"}}'],
];
for (const [name, raw] of invalid) {
test(`${name} returns 400 without writing`, async () => {
diff --git a/CHANGELOG.md b/CHANGELOG.md
index df8e65277..78b7e3466 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -116,6 +116,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- `/lead` rejects non-string email values with HTTP 400 before storage.
+ Arrays no longer become accepted addresses through string coercion, and
+ objects with a non-callable `toString` no longer cause HTTP 500.
+
- `xerj autoindex` now records Dart `extension` and `extension type`
declarations as `class` definitions, so `xerj def <ExtensionName>` finds
them. Methods inside an extension were already indexed; the extension's own
diff --git a/functions/README.md b/functions/README.md
index 5425309dc..a02fdc3b1 100644
--- a/functions/README.md
+++ b/functions/README.md
@@ -12,6 +12,13 @@ asset handler shadows it. Bindings live in [`../wrangler.toml`](../wrangler.toml
| `lead.js` | `/lead` | capture a work email | R2 `LEADS` |
| `api/field-report.js` | `/api/field-report` | **fallback** agent field-report intake | KV `FIELD_REPORTS` |
+## `/lead` — email validation
+
+`POST /lead` requires a string `email`, trimmed and lowercased before
+validation and storage. Non-string values, including arrays and objects,
+return `400 { ok:false, error:"invalid email" }` without writing to R2.
+An R2 write failure for a valid email still returns `500`.
+
## `/api/field-report` — agent field-report fallback
**The canonical path to file a field report is a GitHub PR** (`xerj feedback
diff --git a/functions/lead.js b/functions/lead.js
index 1a0f03997..fca7e93a1 100644
--- a/functions/lead.js
+++ b/functions/lead.js
@@ -10,7 +10,9 @@ const JSON_HEADERS = { 'content-type': 'application/json', 'cache-control': 'no-
export async function onRequestPost({ request, env }) {
try {
const body = (await request.json().catch(() => ({}))) ?? {};
- const email = String(body.email || '').trim().toLowerCase();
+ const email = typeof body.email === 'string'
+ ? body.email.trim().toLowerCase()
+ : '';
if (!email || !email.includes('@') || email.length > 254) {
return new Response(JSON.stringify({ ok: false, error: 'invalid email' }), { status: 400, headers: JSON_HEADERS });
}