Schema validation on ingest
Why it matters
Inserting unvalidated contact data — malformed emails, missing required provenance fields, incorrect data types — violates GDPR Art. 5(1)(d), which requires that personal data be accurate and kept up to date. OWASP A03 (Injection) and CWE-20 (Improper Input Validation) both apply when untrusted external data is written directly to the database without a validation gate. A single batch import with no schema check can flood your contacts table with garbage records that are expensive to identify and remove retroactively.
Severity rationale
High because unvalidated ingestion paths allow malformed records — invalid emails, null provenance fields, wrong types — to corrupt the contacts table and undermine every downstream process that depends on data quality.
Remediation
Add a Zod validation schema that every ingestion path must pass before calling any database insert. Failed validation should route to quarantine, not discard.
// src/lib/ingestion/schema.ts
import { z } from 'zod'
import isEmail from 'validator/lib/isEmail'
export const contactIngestSchema = z.object({
email: z.string().refine(isEmail, 'Invalid email format'),
source_type: z.enum(['scraper', 'api', 'purchased', 'form', 'referral']),
source_id: z.string().min(1),
acquired_at: z.string().datetime(),
first_name: z.string().optional(),
last_name: z.string().optional(),
})
export async function ingestContact(raw: unknown) {
const result = contactIngestSchema.safeParse(raw)
if (!result.success) {
await quarantine(raw, result.error.flatten().fieldErrors)
return
}
await db.contacts.create({ data: result.data })
}
This schema enforces all three required provenance fields (source_type, source_id, acquired_at) as mandatory, so a missing provenance field is caught at ingest rather than at compliance audit.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Data Sourcing & Provenance Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-20 — Improper Input Validation
- owasp:2021 · A03 — Injection — unvalidated input reaching storage layer
- gdpr · Art. 5(1)(d) — Accuracy — schema validation ensures only accurate data is persisted
Taxons
History
- 2026-04-18·v1.0.0·Initial import from data-sourcing-provenance·automated