{"record":{"id":"9c41938c229faad4","repo":"666ghj/MiroFish","slug":"generated-svg-contains-a-foreign-namespace","errorCode":null,"errorMessage":"generated SVG contains a foreign namespace","messagePattern":"generated SVG contains a foreign namespace","errorType":"exception","errorClass":"StarHistoryError","httpStatus":null,"severity":"error","filePath":"scripts/star_history.py","lineNumber":1193,"sourceCode":"        \"in\": {\"SourceGraphic\"},\n        \"in2\": {\"noise\"},\n        \"xChannelSelector\": {\"R\"},\n        \"yChannelSelector\": {\"G\"},\n        \"baseFrequency\": {\"0.05\"},\n        \"scale\": {\"5\"},\n        \"fill-opacity\": {\"0.92\"},\n        \"stroke-linecap\": {\"round\"},\n        \"stroke-linejoin\": {\"round\"},\n        \"text-anchor\": {\"start\", \"middle\", \"end\"},\n        \"font-size\": {\"15\", \"16\", \"17\", \"20\"},\n        \"font-weight\": {\"700\"},\n        \"transform\": {\"rotate(-90 22 272)\"},\n    }\n    avatar_count = 0\n    watermark_count = 0\n    for element in root.iter():\n        if not isinstance(element.tag, str) or not element.tag.startswith(svg_namespace):\n            raise StarHistoryError(\"generated SVG contains a foreign namespace\")\n        local_name = element.tag[len(svg_namespace) :]\n        allowed_for_element = allowed_attributes.get(local_name)\n        if allowed_for_element is None:\n            raise StarHistoryError(\"generated SVG contains a forbidden element\")\n        if local_name == \"image\":\n            avatar_attributes = {\n                \"x\": \"316\",\n                \"y\": \"12\",\n                \"width\": \"22\",\n                \"height\": \"22\",\n                \"href\": OWNER_AVATAR_DATA_URI,\n                \"clip-path\": \"url(#clip-circle-title)\",\n            }\n            watermark_attributes = {\n                \"x\": \"635\",\n                \"y\": \"508.333\",\n                \"width\": \"20\",\n                \"height\": \"20\",","sourceCodeStart":1175,"sourceCodeEnd":1211,"githubUrl":"https://github.com/666ghj/MiroFish/blob/b5b53acc57189a4a42e44a23e149dc655c98fe82/scripts/star_history.py#L1175-L1211","documentation":"Raised by `_validate_svg`'s element walk (scripts/star_history.py:1193) when any element in the parsed tree does not belong to the SVG namespace `{http://www.w3.org/2000/svg}` — including namespaced foreign elements (e.g. `xlink:`-only or Adobe/Illustrator namespaces) and non-element nodes with non-string tags (comments/PIs already excluded earlier, but CDATA-style tags surface here). The published chart is a fixed, review-approved element set, so anything foreign is rejected.","triggerScenarios":"An element whose tag does not start with `{http://www.w3.org/2000/svg}` — commonly `xlink:href` ancestors rewritten as `<ns0:...>` by serializers, editor-added namespaces (Adobe `illustrator:`, Inkscape `sodipodi:`), or fork code appending foreign elements (e.g. `<foreignObject>` with HTML kids, `<iframe>`).","commonSituations":"Round-tripping the generated SVG through Inkscape/Illustrator and re-validating; forks using ElementTree's `register_namespace` incorrectly so tags serialize as `{ns}tag` with a foreign ns; embedding attempts that inject `<script>` or HTML.","solutions":["Regenerate the SVG from `render_svg` rather than editing it with vector tools.","In fork code, only append elements created with the SVG namespace: `ET.SubElement(parent, \"{http://www.w3.org/2000/svg}rect\")`.","If xlink is needed for `href`, note the validator expects plain `href` attributes — use SVG2-style `href`, not `xlink:href`.","Search the payload for namespace declarations (`xmlns:`) — every one beyond the default SVG namespace will trip this check."],"exampleFix":"# before: default ElementTree namespace -> {http://www.w3.org/2000/svg} mismatch or foreign ns\nel = ET.SubElement(root, \"rect\")  # serializes without svg ns / or wrong ns\n\n# after: create elements explicitly in the SVG namespace\nSVG_NS = \"http://www.w3.org/2000/svg\"\nel = ET.SubElement(root, f\"{SVG_NS}rect\")","handlingStrategy":"try-catch","validationCode":"import xml.etree.ElementTree as ET\nSVG_NS = \"http://www.w3.org/2000/svg\"\n\ndef only_svg_namespace(payload: bytes) -> bool:\n    root = ET.fromstring(payload)\n    return all(isinstance(el.tag, str) and el.tag.startswith(f\"{{{SVG_NS}}}\") for el in root.iter())","typeGuard":null,"tryCatchPattern":"try:\n    _validate_svg(payload)\nexcept StarHistoryError as exc:\n    if \"foreign namespace\" in str(exc):\n        raise ValueError(\"SVG contains non-SVG-namespace elements; regenerate from render_svg\") from exc\n    raise","preventionTips":["Create fork elements with ET tags in the SVG namespace; avoid xlink entirely (use plain href).","Do not round-trip the output through Inkscape/Illustrator — they inject editor namespaces.","Scan payloads for 'xmlns:' declarations as a quick pre-check in CI."],"tags":["svg","xml","namespace","self-check","security"],"backgroundTag":null,"analyzedSha":"b5b53acc57189a4a42e44a23e149dc655c98fe82","analyzedAt":"2026-08-14T22:29:33.146Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}