AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
fix(security): allowlist SVG elements in the preview sanitizer and reject foreign Host/Origin on local servers
hugohe32784f7a1907b
diff --git a/skills/ppt-master/scripts/confirm_ui/server.py b/skills/ppt-master/scripts/confirm_ui/server.pyindex 26680465..48705956 100644--- a/skills/ppt-master/scripts/confirm_ui/server.py+++ b/skills/ppt-master/scripts/confirm_ui/server.py@@ -44,6 +44,7 @@ import sysimport threadingimport timeimport urllib.error+import urllib.parseimport urllib.requestimport webbrowserfrom pathlib import Path@@ -2526,6 +2527,20 @@ def create_app(@app.before_requestdef _update_activity():+ allowed_hosts = {PUBLIC_HOST, 'localhost', '::1', '[::1]'}+ host = request.headers.get('Host', '').lower()+ if host.startswith('[') or host.count(':') == 1:+ host = re.sub(r':\d+$', '', host)+ if host not in allowed_hosts:+ return jsonify({'error': 'Forbidden Host header'}), 403+ origin = request.headers.get('Origin')+ if origin is not None:+ try:+ origin_host = urllib.parse.urlsplit(origin).hostname+ except ValueError:+ origin_host = None+ if origin_host not in allowed_hosts:+ return jsonify({'error': 'Forbidden Origin header'}), 403app.config['LAST_REQUEST_TIME'] = time.time()def _exit_with_lock_release(code: int = 0) -> None:diff --git a/skills/ppt-master/scripts/svg_editor/server.py b/skills/ppt-master/scripts/svg_editor/server.pyindex 54bb96a9..56956d6c 100644--- a/skills/ppt-master/scripts/svg_editor/server.py+++ b/skills/ppt-master/scripts/svg_editor/server.py@@ -30,6 +30,7 @@ import sysimport threadingimport timeimport urllib.error+import urllib.parseimport urllib.requestimport webbrowserimport xml.etree.ElementTree as ET@@ -455,6 +456,20 @@ def create_app(@app.before_requestdef _update_activity():+ allowed_hosts = {PUBLIC_HOST, 'localhost', '::1', '[::1]'}+ host = request.headers.get('Host', '').lower()+ if host.startswith('[') or host.count(':') == 1:+ host = re.sub(r':\d+$', '', host)+ if host not in allowed_hosts:+ return jsonify({'error': 'Forbidden Host header'}), 403+ origin = request.headers.get('Origin')+ if origin is not None:+ try:+ origin_host = urllib.parse.urlsplit(origin).hostname+ except ValueError:+ origin_host = None+ if origin_host not in allowed_hosts:+ return jsonify({'error': 'Forbidden Origin header'}), 403app.config['LAST_REQUEST_TIME'] = time.time()def _exit_with_lock_release(code: int = 0) -> None:diff --git a/skills/ppt-master/scripts/svg_editor/static/app.js b/skills/ppt-master/scripts/svg_editor/static/app.jsindex e13226d0..7de44028 100644--- a/skills/ppt-master/scripts/svg_editor/static/app.js+++ b/skills/ppt-master/scripts/svg_editor/static/app.js@@ -1848,18 +1848,32 @@// ================================================================// Utility// ================================================================+ var SVG_NS = "http://www.w3.org/2000/svg";+ var SVG_ALLOWED_ELEMENTS = new Set([+ "svg", "g", "defs", "symbol", "use", "path", "rect", "circle", "ellipse",+ "line", "polyline", "polygon", "text", "tspan", "textpath", "image",+ "clippath", "mask", "pattern", "marker", "lineargradient", "radialgradient",+ "stop", "filter", "feblend", "fecolormatrix", "fecomponenttransfer",+ "fecomposite", "feconvolvematrix", "fediffuselighting", "fedisplacementmap",+ "fedistantlight", "fedropshadow", "feflood", "fefunca", "fefuncb", "fefuncg",+ "fefuncr", "fegaussianblur", "feimage", "femerge", "femergenode",+ "femorphology", "feoffset", "fepointlight", "fespecularlighting",+ "fespotlight", "fetile", "feturbulence", "style", "title", "desc", "metadata",+ "a", "switch", "view", "animate", "animatecolor", "animatetransform",+ "animatemotion", "set", "mpath"+ ]);+function sanitizeSvg(svgString) {var doc = new DOMParser().parseFromString(svgString, "image/svg+xml");if (doc.getElementsByTagName("parsererror").length ||- !doc.documentElement || doc.documentElement.localName.toLowerCase() !== "svg") {+ !doc.documentElement || doc.documentElement.localName.toLowerCase() !== "svg" ||+ doc.documentElement.namespaceURI !== SVG_NS) {throw new Error(t("err_empty_svg"));}doc.querySelectorAll("*").forEach(function (el) {// XML preserves case; the innerHTML sink normalizes HTML/SVG names.var tag = el.localName.toLowerCase();- if (tag === "script" || tag === "foreignobject" ||- (el.namespaceURI && el.namespaceURI !== "http://www.w3.org/2000/svg" &&- el.namespaceURI !== "http://www.w3.org/1999/xlink")) {+ if (!SVG_ALLOWED_ELEMENTS.has(tag) || el.namespaceURI !== SVG_NS) {el.remove();return;}@@ -1871,10 +1885,11 @@return;}// Strip dangerous URI protocols from href/xlink:href+ var value = attr.value.replace(/[\t\r\n]/g, "").replace(/^[\x00-\x20]+/, "");if (local === "href" &&- (/^\s*javascript\s*:/i.test(attr.value) ||- /^\s*vbscript\s*:/i.test(attr.value) ||- /^\s*data\s*:/i.test(attr.value))) {+ (/^\s*javascript\s*:/i.test(value) ||+ /^\s*vbscript\s*:/i.test(value) ||+ /^\s*data\s*:/i.test(value))) {el.removeAttributeNode(attr);}});diff --git a/skills/ppt-master/scripts/tests/test_local_server_security.py b/skills/ppt-master/scripts/tests/test_local_server_security.pynew file mode 100644index 00000000..ec201e55--- /dev/null+++ b/skills/ppt-master/scripts/tests/test_local_server_security.py@@ -0,0 +1,85 @@+#!/usr/bin/env python3+"""PPT Master - Local Server Security Tests++Exercise both Flask request guards without creating project files or servers.++Usage:+ python3 -m unittest discover -s skills/ppt-master/scripts/tests -p test_local_server_security.py++Dependencies:+ flask+"""++import sys+import unittest+from pathlib import Path+from unittest.mock import patch++SCRIPTS_DIR = Path(__file__).resolve().parents[1]+if str(SCRIPTS_DIR) not in sys.path:+ sys.path.insert(0, str(SCRIPTS_DIR))++from confirm_ui import server as confirm_server # noqa: E402+from svg_editor import server as editor_server # noqa: E402+++class LocalServerSecurityTests(unittest.TestCase):+ def setUp(self) -> None:+ self.servers = []+ for server in (editor_server, confirm_server):+ with patch.object(server.threading.Thread, 'start'):+ app = server.create_app(str(SCRIPTS_DIR / '__security_test_project__'), idle_timeout=0)+ app.config['TESTING'] = True+ self.servers.append((server, app, app.test_client()))++ def test_loopback_hosts_are_accepted(self) -> None:+ for server, _, client in self.servers:+ for host in ('127.0.0.1', '127.0.0.1:6060', 'localhost', 'localhost:6060',+ 'LOCALHOST:6060', '::1', '[::1]', '[::1]:6060'):+ with self.subTest(server=server.__name__, host=host):+ response = client.get('/api/health', headers={'Host': host})+ self.assertEqual(response.status_code, 200)++ def test_other_hosts_are_rejected_before_activity_update(self) -> None:+ for server, app, client in self.servers:+ for host in ('evil.example:6060', '127.0.0.1.evil.example', 'localhost.evil.example',+ '192.168.1.1', '[::2]:6060', '::1:6060', 'evil@localhost:6060', ''):+ with self.subTest(server=server.__name__, host=host):+ app.config['LAST_REQUEST_TIME'] = 0+ response = client.get('/api/health', headers={'Host': host})+ self.assertEqual(response.status_code, 403)+ self.assertEqual(app.config['LAST_REQUEST_TIME'], 0)++ def test_loopback_origins_and_missing_origin_are_accepted(self) -> None:+ for server, _, client in self.servers:+ for origin in (None, 'http://127.0.0.1:6060', 'http://localhost',+ 'https://LOCALHOST:6060', 'http://[::1]', 'http://[::1]:6060'):+ with self.subTest(server=server.__name__, origin=origin):+ headers = {} if origin is None else {'Origin': origin}+ self.assertEqual(client.get('/api/health', headers=headers).status_code, 200)++ def test_other_or_malformed_origins_are_rejected(self) -> None:+ for server, app, client in self.servers:+ for origin in ('http://evil.example', 'http://127.0.0.1.evil.example',+ 'http://[email protected]', 'http://[::2]',+ 'http://[::1', 'null', ''):+ with self.subTest(server=server.__name__, origin=origin):+ app.config['LAST_REQUEST_TIME'] = 0+ response = client.get('/api/health', headers={'Origin': origin})+ self.assertEqual(response.status_code, 403)+ self.assertEqual(app.config['LAST_REQUEST_TIME'], 0)++ def test_internal_readiness_url_is_accepted(self) -> None:+ for server, _, client in self.servers:+ with self.subTest(server=server.__name__):+ response = client.get(server._server_url(6060, '/api/health'))+ self.assertEqual(response.status_code, 200)++ def test_guard_also_blocks_shutdown_posts(self) -> None:+ for server, _, client in self.servers:+ for headers in ({'Host': 'evil.example:6060'}, {'Origin': 'http://evil.example'}):+ with self.subTest(server=server.__name__, headers=headers):+ with patch.object(server.threading.Thread, 'start') as start:+ response = client.post('/api/shutdown', json={}, headers=headers)+ self.assertEqual(response.status_code, 403)+ start.assert_not_called()