Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix(security): remove polynomial ReDoS regex in _detect_format (py/polynomial-redos)
KaifAhmad1070b36902ba7
diff --git a/semantica/explorer/routes/ontology.py b/semantica/explorer/routes/ontology.pyindex 58d20f2c..22b35ca4 100644--- a/semantica/explorer/routes/ontology.py+++ b/semantica/explorer/routes/ontology.py@@ -5,7 +5,6 @@ Ontology Hub routes: registry, URL/file loading, preview, creation, entity searcimport asyncioimport ipaddressimport logging-import reimport socketimport uuidfrom datetime import UTC, datetime@@ -267,7 +266,11 @@ def _detect_format(content: str) -> str:return "xml"if "@prefix" in stripped or "@base" in stripped:return "turtle"- if re.match(r"_:\w+|<[^>]+>\s+<[^>]+>", stripped):+ # N-Triples blank-node subject: "_:word <predicate-uri> ..."+ # URI-subject N-Triples ("<uri> <uri>") are already caught by the XML+ # branch above, so only the blank-node form needs to be checked here.+ # Plain string ops avoid the polynomial regex that CodeQL flags (py/polynomial-redos).+ if stripped.startswith("_:") and " <" in stripped:return "nt"return "turtle"