# `ExMCP.Content.Sanitizer`
[🔗](https://github.com/azmaveth/ex_mcp/blob/v1.0.0/lib/ex_mcp/content/sanitizer.ex#L1)

Content sanitization utilities for MCP content.

> #### Experimental {: .warning}
>
> 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

# `sanitization_op`

```elixir
@type sanitization_op() ::
  :html_escape
  | :strip_scripts
  | :normalize_unicode
  | :limit_size
  | :remove_metadata
  | :compress_media
  | {:custom, function()}
  | atom()
```

Sanitization operation

# `html_escape`

```elixir
@spec html_escape(String.t()) :: String.t()
```

Escapes HTML entities in text content.

# `normalize_unicode`

```elixir
@spec normalize_unicode(String.t()) :: String.t()
```

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.

# `remove_metadata`

> This function is deprecated. Not implemented for EXIF; not an MCP requirement. Planned for removal in 2.0.0..

```elixir
@spec remove_metadata(ExMCP.Content.Protocol.content()) ::
  ExMCP.Content.Protocol.content()
```

Removes potentially dangerous metadata from content.

> #### Deprecated {: .warning}
> 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.

# `sanitize`

```elixir
@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}
    ])

# `sanitize_path`

```elixir
@spec sanitize_path(String.t()) :: String.t()
```

Sanitizes file paths to prevent directory traversal.

# `sanitize_text`

```elixir
@spec sanitize_text(String.t(), [sanitization_op()]) :: String.t()
```

Sanitizes text content specifically.

# `strip_scripts`

```elixir
@spec strip_scripts(String.t()) :: String.t()
```

Removes script tags and JavaScript from HTML content.

# `strip_sql_injection`

```elixir
@spec strip_sql_injection(String.t()) :: String.t()
```

Removes SQL injection attempts from text.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
