Join our Newsletter — 33% off our NHI Course
Home› Glossary› Cyber Security› Sanitisation
Cyber Security

Sanitisation

← Back to Glossary
By NHI Mgmt Group Updated October 31, 2026 Domain: Cyber Security

Sanitisation is the process of transforming or constraining input so it can be used safely. In application security, this usually means validating structure, escaping dangerous characters, or otherwise neutralising untrusted data before it reaches a sensitive operation. Effective sanitisation must match the context of the sink.

What Sanitisation Actually Does

Sanitisation makes untrusted input safe for a specific use, but it is not a single universal transformation. The exact operation depends on the sink: HTML, SQL, shell commands, file paths, LDAP queries, log entries, or downstream APIs all require different handling. The goal is to preserve intended meaning while removing the characters or structure that would change behaviour.

Good sanitisation is therefore context-aware, not cosmetic. A string that is safe in one output context can still be dangerous in another, which is why application security treats sanitisation as part of a larger input-handling design rather than a one-step filter.

Why Context Matters

The main failure mode is using the wrong protection for the wrong sink. Escaping HTML does not make a value safe for SQL, and stripping a few symbols does not make a path safe if the application still accepts traversal patterns or unsafe encodings. Sanitisation only works when the protection matches the parser, syntax rules, and trust boundary that will consume the data.

This is why security teams separate input validation, output encoding, and contextual escaping. Validation checks whether the data is structurally acceptable, while sanitisation constrains or neutralises content that would otherwise be interpreted as code, markup, or a command. Mixing those ideas usually leads to gaps.

Where Sanitisation Breaks Down

Sanitisation fails when the application assumes one representation but the runtime or backend interprets another. Double encoding, canonicalisation differences, Unicode edge cases, and inconsistent decoding between layers can all let hostile input survive the first pass and reappear later in a dangerous form.

It also breaks down when sanitisation is applied too early in the flow. If data is transformed before all parsing and normalisation steps are complete, later components may reinterpret it in a way the original filter did not anticipate. That is especially common in multi-step web applications, log pipelines, and systems that pass data between services.

Designing Safer Input Handling

Robust sanitisation starts with explicit trust boundaries and a clear model of the sink. Teams should define which fields are allowed, which characters are acceptable, how encoding is handled, and where escaping must happen so that every sensitive operation receives data in the correct form.

Security verification should test the full path, not just the validation function. For application teams, that means checking how input behaves after parsing, storage, retrieval, rendering, and integration with downstream systems, because the dangerous interpretation often happens later than the initial request.

Risk and Threat Considerations

Unsanitised or poorly sanitised input is a classic pathway to injection, data corruption, and trust-boundary abuse. The security impact depends on the sink, but the common theme is that attacker-controlled data is interpreted as instructions instead of content.

Failure mechanism: The application applies incomplete, generic, or incorrectly ordered filtering, allowing crafted input to survive decoding, parsing, or templating and reach a sensitive operation in executable form.

Impact: This can lead to script execution, query manipulation, command execution, file path abuse, log poisoning, or corrupted output that undermines both security controls and downstream decisions.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP ASVSV1 — Encoding and SanitizationSanitisation is a core application security verification concern for untrusted input handling.
V2 — Validation and Business LogicSafe sanitisation depends on validating structure before data reaches sensitive logic.
V15 — Secure Coding and ArchitectureContext-specific sanitisation is an architectural safeguard against injection and parser confusion.
Recommendation — Verify context-aware encoding and sanitisation for every sink that processes untrusted input. Enforce input validation rules that constrain structure before data is consumed by business logic. Design input flows so each sink receives the correct escaping, validation and canonicalisation.
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationThis control directly addresses validating and constraining untrusted input before processing.
SI-16 — Memory ProtectionInput handling flaws can create downstream exploitation conditions when data is misinterpreted or corrupted.
SC-28 — Protection of Information at RestSanitisation can prevent unsafe persistence of tainted data into stored records and logs.
Recommendation — Apply SI-10 to validate, reject or constrain malformed input before it reaches sensitive operations. Use SI-16 alongside input controls to reduce exploitation impact from malformed or hostile data. Protect stored data by sanitising untrusted content before it is written to durable repositories.
CIS Controls v8CIS-16 — Application Software SecuritySanitisation is a foundational application security safeguard for preventing injection and unsafe parsing.
Recommendation — Build and test application input handling so untrusted data cannot alter execution or output contexts.

Practitioner Guidance

Why practitioners should care: Sanitisation is not a single control, it is a set of context-specific protections that must match each sink. If a team treats it as one reusable helper, they often end up with false confidence and a broken assumption about safety.

What to watch for: Review whether the application uses allowlists for structure, context-aware escaping for output, and canonicalisation before enforcement. If sanitisation logic is shared across multiple sinks, verify that the same function is not being reused where the syntax rules differ.

Practitioner takeaway: The safest pattern is to validate structure first, sanitise for the exact destination second, and verify the full end-to-end path with adversarial test cases.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 31, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org