Order creation stores correct initial state
Why it matters
Orders created with the wrong initial state silently corrupt the state machine before a customer's first interaction. A guest checkout that creates orders as 'confirmed' and a webhook handler that creates them as 'processing' mean neither flow is correct — downstream transitions fire against the wrong base state, confirmation emails may trigger prematurely, inventory may decrement twice, and support staff see misleading history. CWE-841 (Improper Enforcement of Behavioral Workflow) applies directly: the system has an intended sequence, and this defect breaks it at step zero.
Severity rationale
Critical because an incorrect initial status corrupts every downstream state transition and notification, making order history unreliable from the moment of creation.
Remediation
Centralize all order creation behind a single function in lib/orders/create.ts that enforces the initial status via a named constant. Import it in every creation path — checkout route, webhook handler, admin creation — so the initial state can never diverge.
// lib/orders/constants.ts
export const ORDER_INITIAL_STATUS = 'pending' as const
// lib/orders/create.ts
import { ORDER_INITIAL_STATUS } from './constants'
export async function createOrder(data: CreateOrderInput) {
return db.orders.create({
data: { ...data, status: ORDER_INITIAL_STATUS },
})
}
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 Order Management Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-841 — Improper Enforcement of Behavioral Workflow
- iso-25010:2011 · functional-correctness — Functional Correctness
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ecommerce-order-management·automated