Implementing allowlist-based input validation and canonicalisation
Implementing allowlist-based input validation and canonicalisation connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding allowlist-based input validation and canonicalisation helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Input validation defines the structures, sizes and meanings an application expects to receive. It must happen before information influences a sensitive operation. Validation does not replace safe interpreter APIs, output encoding or permission checks, because those controls address different boundaries.
Input validation checks whether data meets an application's requirements before the application uses it. It reduces the risk of malformed data, invalid business operations, and excessive resource consumption. OWASP's Proactive Control C3 distinguishes validation from the additional defenses needed when using that data:
Validate both syntax (the expected type and format) and semantics (whether the value makes sense for the operation). For example, a booking needs valid dates and an end date after its start date. CWE-20 describes these checks, including consistency between related fields.
Why it matters
Consider a realistic failure: a loosely defined input accepts unexpected types, duplicate values or encodings that change later interpretation.
Untrusted input can change application behaviour, consume excessive resources or reach data and execution paths outside the intended feature. The practical result depends on where the value is used and which privileges are available there.
Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.
How penetration testers check for it
Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.
- Trace input from every relevant entry point to its use.
- Check types, lengths, ranges and ambiguous representations.
- Compare parsing across components and alternate request formats.
- Use controlled invalid inputs to establish effects rather than assumptions.
How to fix it
Use the appropriate maintained mechanisms and verify the result in the actual production configuration.
- Use parameterized queries for SQL and context-aware output encoding to prevent cross-site scripting (XSS).
- Check authorisation separately: a valid account identifier does not mean the caller may access that account.
- Use a maintained parser for the expected format, handle parsing failures, and validate the resulting values before business processing or storage. Configure parsers for untrusted input; see XML External Entity Prevention and Deserialisation. Converting text to an integer only establishes a type: it does not establish an acceptable quantity.
- Use your framework's validators or a schema validator to enforce field rules. For JSON, explicitly configure required and additional properties; listing a property alone neither requires it nor rejects unknown fields. Apply schemas to nested objects and use item schemas and array length limits. Keep business checks, such as date ordering, alongside these structural checks.
- Reject unexpected structures before sensitive processing.
- Apply resource bounds and predictable failure handling.
Blocking a few known attack strings is not a complete validation strategy. The intended data model and downstream interpretation determine which protections are needed.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Auditing application input validation and canonicalisation
- Implementing structured Java input validation
- Implementing authentication and validation in FastAPI
Read about our methodology or contact pentested.com to discuss secure development and code review.