Content sanitization utilities for MCP content.
Experimental
Not part of the core stable Handler/DSL surface. Best-effort text sanitization only — not a full security sandbox.
Implemented
:html_escape/html_escape/1:strip_scripts/strip_scripts/1:normalize_unicode/normalize_unicode/1(Unicode NFC):limit_size(text truncation; binary content marked on overflow)sanitize_path/1,strip_sql_injection/1
Deprecated (not MCP/ACP requirements)
:remove_metadata/remove_metadata/1— EXIF stripping was never implemented; not required by MCP. Prefer app-level media pipelines if needed.:compress_media— no-op stub; planned for removal in 2.0.0
Summary
Types
Sanitization operation
Functions
Escapes HTML entities in text content.
Normalizes Unicode text to NFC form.
Removes potentially dangerous metadata from content.
Sanitizes content by applying a list of sanitization operations.
Sanitizes file paths to prevent directory traversal.
Sanitizes text content specifically.
Removes script tags and JavaScript from HTML content.
Removes SQL injection attempts from text.
Types
Functions
Escapes HTML entities in text content.
Normalizes Unicode text to NFC form.
Uses :unicode.characters_to_nfc_binary/1. This reduces some homograph
confusion but is not a complete security control by itself.
@spec remove_metadata(ExMCP.Content.Protocol.content()) :: ExMCP.Content.Protocol.content()
Removes potentially dangerous metadata from content.
Deprecated
Never implemented for real EXIF stripping. Not required by MCP/ACP.
Returns content unchanged (or clears a :metadata key when present).
Planned for removal in 2.0.0.
@spec sanitize(ExMCP.Content.Protocol.content(), [sanitization_op()]) :: ExMCP.Content.Protocol.content()
Sanitizes content by applying a list of sanitization operations.
Examples
safe_content = Sanitizer.sanitize(content, [
:html_escape,
:strip_scripts,
{:limit_size, 1_000_000}
])
Sanitizes file paths to prevent directory traversal.
@spec sanitize_text(String.t(), [sanitization_op()]) :: String.t()
Sanitizes text content specifically.
Removes script tags and JavaScript from HTML content.
Removes SQL injection attempts from text.