Public Forms (/v/form/:slug)
Public forms allow external partners, customers, and unauthenticated field reporters to submit requests, orders, incident reports, or service tickets at /v/form/:slug through the dxosForms resource (public-forms.js and public-form-html.js) in @latticedx/plugin-lattice-foundation. The intake pipeline enforces Zero-PII isolation: anonymous clients never receive organizationId, internal defaults, or target collection names, and direct CRUD access to form metadata or submission tables is blocked.
Every valid submission runs inside a tenant-scoped PostgreSQL RLS transaction (withTenantRlsContext), inserts the target business record, stores an audit receipt in latticePublicFormSubmissions, and emits a public_form.submitted CloudEvent to the Event Bus.
latticePublicFormsGuard and Routing Boundary
The registerPublicFormsGuard middleware (tagged latticePublicFormsGuard, mounted after: 'acl') blocks direct non-root CRUD or charts:queryData requests against:
latticePublicFormslatticePublicFormSubmissions
Blocked requests fail with HTTP 403 (PUBLIC_FORM_DIRECT_ACCESS_FORBIDDEN), forcing all interactions through dxosForms. At the Nginx edge (10-lattice-public-routes.sh), /v/form proxies directly to the application upstream and /form issues a 302 redirect to /v/form.
dxosForms API Reference
dxosForms exposes 3 public actions and 7 loggedIn administrative actions guarded by resolveAdminContext. Two inspection actions (listSubmissions and downloadAttachment) also permit business managers (ldx_manager, ldx_admin, admin).
Public Actions (public ACL)
/api/dxosForms:meta?slug=partner-intake/api/dxosForms:submit?slug=partner-intake/api/dxosForms:status?slug=partner-intake&submissionCode=LDX-FRM-...&token=ldx_frm_...Administrative Actions (loggedIn ACL)
/api/dxosForms:list?limit=50/api/dxosForms:get?id=1/api/dxosForms:save/api/dxosForms:delete/api/dxosForms:rotateToken/api/dxosForms:listSubmissions?slug=partner-intake&page=1&pageSize=20/api/dxosForms:downloadAttachment?submissionCode=LDX-FRM-...&fieldName=attachmentSlug Rules, Allowlisted Collections, and Field Schema
Every form definition passes validatePublicFormDefinition before persistence:
| Parameter | Type | Default | Description |
|---|---|---|---|
slugrequired | string | — | Matches /^[a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])$/ (3 to 63 chars) and is excluded from the 15 RESERVED_FORM_SLUGS. |
titlerequired | string | — | Public form title (1 to 180 characters). |
targetCollectionrequired | string | — | Must be in PUBLIC_FORM_ALLOWLIST_COLLECTIONS or match ^latticeCustom[A-Z][A-Za-z0-9]{1,40}$. |
allowedFieldsJsonrequired | FieldSpec[] | — | 1 to 50 input field descriptors restricted to the 9 ALLOWED_FIELD_TYPES. |
defaultValuesJson | object | — | Primitive default values applied server-side on target creation; rejects BLOCKED_TARGET_FIELDS. |
honeypotField | string | _hp_website | Hidden bot-trap field name matching /^[a-zA-Z_][a-zA-Z0-9_]{1,63}$/. |
rateLimitPerMinute | integer | 20 | Per-IP per-slug submission cap per minute (1..300). |
requireAccessToken | boolean | false | Enforces ldx_ftok_* bearer or header token verification on submit. |
workflowRuleKey | string | — | Optional workflow key attached to the emitted public_form.submitted CloudEvent. |
active | boolean | true | Enables or disables public metadata and submissions. |
Target Collection Allowlist (PUBLIC_FORM_ALLOWLIST_COLLECTIONS)
Forms may only write to 8 built-in collections or custom collections matching ^latticeCustom[A-Z][A-Za-z0-9]{1,40}$:
| Target Collection | Typical Intake Use Case | Initialized Fields |
|---|---|---|
latticeRequests | Purchase or partner intake requests | status: 'submitted', version: 1, amendmentNo: 0 |
latticeOrders | External order or shipment requests | status: 'submitted', version: 1, amendmentNo: 0 |
latticeServiceTickets | Customer support and service tickets | status: 'submitted', version: 1, amendmentNo: 0 |
latticeIncidentCases | Field cold-chain incident reports | status: 'submitted' |
latticeParaDocuments | External knowledge vault submissions | status: 'submitted' |
latticeAgentProposals | Queued operational proposals | status: 'submitted' |
latticeLocations | Partner site or drop-off registration | active: true |
latticeAssets | Asset and equipment onboarding | active: true |
Reserved Slugs and Supported Field Types
| Rule | Values |
|---|---|
RESERVED_FORM_SLUGS (15) | admin, api, signin, signup, mobile, track, form, v, p, static, storage, files, lattice, health, settings |
ALLOWED_FIELD_TYPES (9) | string, text, number, integer, boolean, date, email, select, file |
| Field length & regex bounds | DEFAULT_MAX_FIELD_LENGTH = 2000 (MAX_FIELD_LENGTH_CAP = 10000), regex pattern <= 120 chars with nested quantifier rejection to prevent ReDoS. |
Security Controls, Anti-Spam, and Rate Limiting
Zero-PII, Prototype Guards, and BLOCKED_TARGET_FIELDS
serializePublicMeta
Public metadata responses return only slug, title, description, fields, honeypotField, requireAccessToken, and active, omitting organizationId, targetCollection, accessTokenHash, createdByUserId, and defaultValuesJson.
Prototype & depth guard (assertNoPrototypePollution)
Rejects payloads nested deeper than 20 levels (maxDepth = 20) or containing __proto__, constructor, or prototype. Supplying organizationId in submit requests fails immediately with 400 FORM_ORG_OVERRIDE_FORBIDDEN.
BLOCKED_TARGET_FIELDS
Blocks exposure or client override of 29 system, lifecycle, and security keys:
id, organizationId, createdAt, updatedAt, createdById, updatedById,
status, version, amendedFromId, amendmentNo, requesterId, assigneeId,
submittedBy, cancelledBy, cancelReason, cancelledAt, submittedAt,
userId, identitySubject, password, secret, token, apiKey, privateKey,
accessTokenHash, statusTokenHash, __proto__, constructor, prototypeAny field name matching SENSITIVE_FIELD_NAME_RE (password|secret|token|apikey|api_key|privatekey|private_key|hash|salt) is also rejected across form schemas, defaults, and hydrated submission listings.
_hp_website Honeypot and 20 / 60 / 300 Rate Limits
- Bot honeypot (
_hp_website): If any request bag (body,params,values) supplies a non-empty value for the configuredhoneypotFieldor_hp_website, the submission is rejected with400 FORM_BOT_DETECTED. - 60-second sliding-window rate limiter (
createSlidingWindowRateLimiter):
| Scope | Constant | Default Limit / Min | Counter Key |
|---|---|---|---|
| Pre-lookup IP flood protection | PRE_LOOKUP_IP_FLOOD_LIMIT | 300 | ${clientIp}:__flood__ |
Form submission (dxosForms:submit) | DEFAULT_RATE_LIMIT_PER_MIN | 20 (configurable 1..300) | ${clientIp}:${slug} |
Status lookup (dxosForms:status) | STATUS_RATE_LIMIT_PER_MIN | 60 | ${clientIp}:status:${slug} |
Exceeded windows return HTTP 429 RATE_LIMIT_EXCEEDED with a Retry-After header.
Token Model: ldx_ftok_ and ldx_frm_
- Form access token (
ldx_ftok_<48 hex>): WhenrequireAccessTokenis enabled,dxosForms:rotateTokengenerates a 24-byte random token prefixed withldx_ftok_and persists only its SHA-256 digest (accessTokenHash). Clients supply the token via body (token/accessToken), query, orx-form-tokenheader; validation executes constant-timetimingSafeEqualHex(usingDUMMY_HASH_HEXwhen the form does not exist to prevent timing side-channels). - Submission status token (
ldx_frm_<48 hex>): Every accepted submission generates a uniquesubmissionCode(LDX-FRM-<8 hex>) and a one-timestatusToken(ldx_frm_...), storing only its SHA-256statusTokenHashfor subsequentdxosForms:statuschecks.
File Upload Magic-Byte Verification and public_form.submitted CloudEvent
The sanitizeFileFieldValue handler caps uploads at MAX_FILE_UPLOAD_BYTES = 2MB (2,097,152 bytes), blocks path-traversal characters (.., /, \, control bytes), hashes content with SHA-256, and verifies binary file signatures across the 5 ALLOWED_FILE_MIME_TYPES:
| MIME Type | Magic-Byte / Content Verification |
|---|---|
application/pdf | Leading 5 bytes match %PDF- |
image/png | Leading 8 bytes match 89 50 4E 47 0D 0A 1A 0A |
image/jpeg | Leading 3 bytes match FF D8 FF |
image/webp | Bytes 0..3 equal RIFF and bytes 8..11 equal WEBP |
text/plain | Zero 0x00 null bytes and does not start with <script, <svg, <html, <?xml, <!doctype, <!--, <iframe, <object, or <embed |
After committing both the target record and the latticePublicFormSubmissions receipt, dxosForms:submit emits the public_form.submitted CloudEvent (source: 'dxosForms', subject: submissionCode) carrying { slug, submissionCode, targetCollection, targetRecordId, workflowRuleKey } to trigger downstream LatticeFlow v2 rules or Event Bus webhooks.
curl -X POST https://localhost:8443/api/dxosForms:save \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"slug": "coldchain-incident",
"title": "Cold-Chain Incident Intake",
"targetCollection": "latticeIncidentCases",
"rateLimitPerMinute": 20,
"allowedFieldsJson": [
{ "name": "name", "label": "Incident Summary", "type": "string", "required": true, "maxLength": 160 },
{ "name": "severity", "label": "Severity", "type": "select", "required": true, "options": ["low", "medium", "high", "critical"] },
{ "name": "evidence", "label": "Site Photo", "type": "file", "required": false }
]
}'