Stopping Mass Assignment with additionalProperties: false & ReadOnly Fields
Close OWASP API3:2023 Broken Object Property Level Authorization (BOPLA) and Mass Assignment gaps by enforcing additionalProperties: false, readOnly server attributes, and strict request DTOs.
# OpenAPI OWASP API Top 10 & MCP Readiness PR Checklist — User & Billing Profile API
- **Score:** 85/100 (Grade B) — **HARDENED — OWASP & MCP READY**
- **Target Standard:** OpenAPI 3.1.0
- **Endpoints Modeled:** 16 ops (~2,832 MCP pre-prompt tokens/turn · $12.74/mo at 50 turns/day on $3/1M)
- **Reclaimable MCP Schema Diet:** 992 tokens/turn ($4.46/mo saved)
## Security & Schema Review Checklist
- [x] **API2-AUTH (OWASP API2:2023)** — Explicit components.securitySchemes (Bearer JWT / OAuth2 scopes) + global/op security
- Bearer JWT / OAuth2 securitySchemes and security[] requirements are enforced.
- [x] **API1-BOLA (OWASP API1:2023)** — Object-ID routes ({id}) enforce explicit 401/403 responses & tenant ownership scopes
- Parameterized {id} endpoints verify tenant ownership and document 401/403 status codes.
- [ ] **API3-BOPLA (OWASP API3:2023)** — additionalProperties: false + readOnly: true on server-owned fields (role, id, plan)
- Unbounded object schemas allow attackers to inject role, plan, or tenantId fields (OWASP API3 Mass Assignment / BOPLA).
- [x] **API4-BOUNDS (OWASP API4:2023)** — maxLength, maxItems, maximum & bounded pagination (limit <= 100 / cursor) on inputs
- Strings, arrays, and pagination limits define strict maxLength, maxItems, and maximum bounds.
- [x] **API8-TLS (OWASP API8:2023)** — HTTPS-only servers[] URLs (zero http:// prod) + strict CORS allowlist & headers
- Production servers[] enforce HTTPS-only URLs and strict origin allowlist CORS.
- [x] **API4-429 (OWASP API4 / API8)** — Explicit 401, 403 & 429 Too Many Requests responses with Retry-After / X-RateLimit-*
- 401, 403, and 429 Too Many Requests responses include Retry-After / X-RateLimit-* headers.
- [x] **API9-INV (OWASP API9:2023)** — Versioned base paths + deprecated: true ops declare Sunset header & replacement path
- Deprecated endpoints publish Sunset headers and migration paths; zero shadow APIs.
- [x] **MCP-TOKEN (AI / MCP Readiness)** — Concise tool descriptions (<= 120 tok/op) & OpenAPI 3.1 type arrays (no nullable: true)
- Operation descriptions stay lean (~47 tok/op) and OpenAPI 3.1.0 avoids nullable drift.
## Automated Verification & Done-For-You Remediation
- Free Zero-Upload OpenAPI Diff & OWASP Audit: https://spec.runglab.dev
- $49 Done-For-You OpenAPI & MCP Remediation PR (Creem): https://www.creem.io/product/prod_4KoVJW4YEAf6XjjuSK44lp
- RapidAPI Live Endpoint (`POST /v1/openapi/audit`): https://hub.runglab.dev
- Remote MCP Tool (`audit_openapi_spec`): https://mcp-server.runglab.dev/
- Apify Cloud PPE Actor: https://apify.com/runglab/openapi-spec-diff-auditor
Zero-Upload SpecDiff$49 Remediation PR
Audit Full OpenAPI Specs or Ship a Hardened PR Today
Run a 100% browser-side breaking-change diff, OWASP API Top 10 scan & SARIF 2.1.0 export on SpecDiff (https://spec.runglab.dev), order a $49 Done-For-You OpenAPI & MCP Remediation PR on Creem, or automate via POST /v1/openapi/audit (API Hub), remote MCP tool audit_openapi_spec, and Apify Cloud PPE.
// Zod (TypeScript / Node): always use z.strictObject() instead of z.object()
import { z } from "zod";
export const AccountUpdateSchema = z.strictObject({
displayName: z.string().min(1).max(80).optional(),
timezone: z.string().max(64).optional()
}); // Rejects { role: "admin" } with HTTP 400 before touching ORM!
Key Engineering Takeaways
JSON Schema defaults `additionalProperties` to `true`, meaning any OpenAPI requestBody object without `additionalProperties: false` silently permits extra keys (`role`, `isAdmin`, `subscriptionCredits`).
In RungLab's 100-server live MCP study (/research/mcp-100-servers-context-tax/), 54.5% of servers omitted `additionalProperties: false` — letting LLMs hallucinate unexpected parameters or overwrite server state.
Combining separate `Request` DTOs with `readOnly: true` annotations guarantees both runtime request validators and OpenAPI code generators block forbidden properties.
Common Contract Pitfalls to Avoid
Reusing a single `User` ORM model for `GET` responses and `PATCH /users/{id}` request bodies.
Unwrapping Zod `.shape` or Pydantic defaults with `extra='allow'` instead of `extra='forbid'` / `z.strictObject()`.
Returning sensitive PII (`passwordHash`, `stripeCustomerSecret`, internal `adminNotes`) in shared response schemas without field-level `writeOnly` or split DTOs.
How to detect Broken Object Level Authorization (OWASP API1:2023) blindspots across {id} routes in OpenAPI 3.0/3.1 specs using explicit security scopes, tenant path bindings, and mandatory 401/403 contracts.
Does additionalProperties: false work cleanly with allOf inheritance in OpenAPI 3.0?
Be careful: in JSON Schema / OpenAPI 3.0, placing `additionalProperties: false` inside one branch of `allOf` rejects properties defined in sibling `allOf` subschemas. Use flat composed DTOs or JSON Schema 2020-12 `unevaluatedProperties: false` in OpenAPI 3.1.
Why does OWASP API3:2023 combine Excessive Data Exposure and Mass Assignment?
Both stem from missing property-level authorization (BOPLA): exposing unauthorized fields in responses and accepting unauthorized fields in payloads.
How can I scan my OpenAPI schemas for missing additionalProperties: false?
Use the interactive scorer above, paste your spec into https://spec.runglab.dev, or run `audit_openapi_spec` via dev.runglab/devtools MCP.