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)
| 13773 | |
| 13774 | |
| 13775 | def _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 | |
| 13793 | def extract_lazarus_package(path: Path) -> dict: |
no outgoing calls
no test coverage detected