Allowlist Validation

Allowlist validation accepts input only when it matches an explicitly permitted set of values or patterns. It is a restrictive approach to input validation that rejects unexpected input by default.

An allowlist defines what input is valid instead of trying to enumerate everything that could be dangerous. For example, an API field that accepts a sort direction can permit only `"asc"` and `"desc"`.

For fixed choices, validate membership directly with a set or similar structure. For structured input, use a narrowly defined pattern that describes the accepted format, such as a regular expression for a known identifier syntax.

Validation should happen at the application boundary, before the value reaches code that interprets it. If validation fails, return an appropriate error rather than silently changing the value to something else.

Allowlists are especially useful for security-sensitive inputs such as operation names, file extensions, enum-like parameters, and configuration choices. They reduce ambiguity because newly introduced or unexpected values remain invalid until explicitly permitted.

Key points

Interview questions

What is allowlist validation, and why would you use it?

Allowlist validation means defining the inputs an application accepts and rejecting values outside that definition. For a field with a small fixed vocabulary, this can be as simple as checking membership in a set. It is useful because unexpected values do not become valid merely because they were not recognized as malicious.

How would you validate an API parameter that accepts only a few operations?

I would represent the permitted operations as a set or enum and check the request value against it. If the value is absent or not a member, I would return a client-validation error before dispatching the operation. This keeps the dispatch logic from having to handle arbitrary operation names.

Why can a denylist be weaker than an allowlist for security-sensitive input?

A denylist depends on knowing the unwanted cases in advance. New or unexpected representations can remain acceptable if they were not included in the blocked set. An allowlist instead defines the intended input space, so unrelated values are rejected by default.

What should you consider when validating structured input with a regular expression?

The expression should describe the complete format the application actually expects, rather than merely searching for a permitted substring. I would define boundaries and allowed characters carefully and consider length limits as separate constraints. I would also test malformed, boundary, and unexpectedly large inputs.