Skip to content
HALOWERK

Bildwerk

svg sanitize

Parses the SVG with a strict, namespace-aware XML parser (saxes; DOCTYPE entities are refused, so no XXE or entity expansion) and rebuilds it from an allowlist of SVG elements and attributes, re-serialising with escaping so the result is safe both as a file and inline in HTML. Removed: script/handler elements, all on* attributes, foreignObject, non-SVG namespaces, href values other than local #fragments (links only with allow_links, raster data: images only with allow_data_images), url().

POST https://bild.halowerk.com/v1/svg-sanitize

Inputs

Fields of the published input schema
FieldTypeRequiredDescription
svgstringNoSVG markup.
svg_urlstringNoPublic URL of the SVG (at most 5 MB).
allow_linksbooleanNoKeep http(s), mailto and relative hyperlinks on <a>.
allow_data_imagesbooleanNoKeep <image> with base64 PNG/JPEG/GIF/WebP/AVIF data URIs.
optimizebooleanNoAlso drop metadata, editor data, empty groups and whitespace.
precisionintegerNoRound numbers in geometry attributes to this many decimals.
Show full input schema
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "svg": {
      "type": "string",
      "minLength": 10,
      "maxLength": 5000000,
      "description": "SVG markup."
    },
    "svg_url": {
      "type": "string",
      "format": "uri",
      "maxLength": 2048,
      "description": "Public URL of the SVG (at most 5 MB)."
    },
    "allow_links": {
      "type": "boolean",
      "default": false,
      "description": "Keep http(s), mailto and relative hyperlinks on <a>."
    },
    "allow_data_images": {
      "type": "boolean",
      "default": true,
      "description": "Keep <image> with base64 PNG/JPEG/GIF/WebP/AVIF data URIs."
    },
    "optimize": {
      "type": "boolean",
      "default": true,
      "description": "Also drop metadata, editor data, empty groups and whitespace."
    },
    "precision": {
      "type": "integer",
      "minimum": 0,
      "maximum": 6,
      "description": "Round numbers in geometry attributes to this many decimals."
    }
  }
}

Open original schema

Published input example

{
  "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" onload=\"alert(1)\" viewBox=\"0 0 10 10\"><script>alert(2)</script><rect width=\"10\" height=\"10\" fill=\"red\"/></svg>"
}

Result & documentation

Machine-readable documentation of this hub

Source of this page: the published HALOWERK catalog. Updated: 2026-11-17 UTC.

More endpoints in this hub

All endpoints in this hub →