From a068e30e1d0114a75c9c809852084819b91c00bf Mon Sep 17 00:00:00 2001 From: anupamme Date: Wed, 26 Aug 2026 13:42:21 +0000 Subject: [PATCH] fix: gitlab.bandit.B313.B314.B315.B316.B318.B319.B320.B405.B406.B407.B408.B409.B410 security vulnerability Automated security fix generated by OrbisAI Security --- .github/scripts/generate_sitemap.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/scripts/generate_sitemap.py b/.github/scripts/generate_sitemap.py index fe47d52c..9eb980b2 100644 --- a/.github/scripts/generate_sitemap.py +++ b/.github/scripts/generate_sitemap.py @@ -1,10 +1,13 @@ import os -from lxml import etree +import defusedxml.ElementTree as ET REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')) BASE_URL = "https://onsdigital.github.io/Charts/" SITEMAP_PATH = os.path.join(REPO_ROOT, "sitemap.xml") +NS = "http://www.sitemaps.org/schemas/sitemap/0.9" +ET.register_namespace('', NS) + # List of folders to include (those with index.html) folders = [ d for d in os.listdir(REPO_ROOT) @@ -18,14 +21,16 @@ urls.append(BASE_URL + folder + "/index.html") # Create XML -urlset = etree.Element("urlset", xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") +urlset = ET.Element(f"{{{NS}}}urlset") for url in urls: - url_elem = etree.SubElement(urlset, "url") - loc = etree.SubElement(url_elem, "loc") + url_elem = ET.SubElement(urlset, f"{{{NS}}}url") + loc = ET.SubElement(url_elem, f"{{{NS}}}loc") loc.text = url # Write to file +ET.indent(urlset) +tree = ET.ElementTree(urlset) with open(SITEMAP_PATH, "wb") as f: - f.write(etree.tostring(urlset, pretty_print=True, xml_declaration=True, encoding="UTF-8")) + tree.write(f, xml_declaration=True, encoding="UTF-8") print(f"Sitemap generated at {SITEMAP_PATH}")