MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _project_xml_is_safe

Function _project_xml_is_safe

graphify/extract.py:13775–13790  ·  view source on GitHub ↗

Reject XML that declares DTDs or entities. Stdlib ``xml.etree.ElementTree`` does not cap entity expansion, so a crafted project file could trigger a billion-laughs style DoS. External entity resolution is already disabled by pyexpat defaults, but rejecting ``<!DOCTYPE`` / ``<!ENTITY

(src: bytes)

Source from the content-addressed store, hash-verified

13773
13774
13775def _project_xml_is_safe(src: bytes) -> bool:
13776 """Reject XML that declares DTDs or entities.
13777
13778 Stdlib ``xml.etree.ElementTree`` does not cap entity expansion, so a
13779 crafted project file could trigger a billion-laughs style DoS. External
13780 entity resolution is already disabled by pyexpat defaults, but rejecting
13781 ``<!DOCTYPE`` / ``<!ENTITY`` outright is defense in depth.
13782
13783 Legitimate MSBuild and Lazarus package files never contain a DOCTYPE
13784 or ENTITY declaration, so this is a zero-false-positive screen.
13785 """
13786 # Only the prolog can hold a DTD/internal subset, but be conservative
13787 # and scan the full byte range -- these formats use ASCII tags so a
13788 # case-insensitive substring match is sufficient.
13789 lowered = src.lower()
13790 return b"<!doctype" not in lowered and b"<!entity" not in lowered
13791
13792
13793def extract_lazarus_package(path: Path) -> dict:

Callers 4

extract_lazarus_packageFunction · 0.85
extract_slnxFunction · 0.85
extract_csprojFunction · 0.85
extract_xamlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected