Skip to content

fix(transport): Guard invalid XML in modTransportProvider - #16975

Open
Ibochkarev wants to merge 2 commits into
modxcms:3.xfrom
Ibochkarev:fix/16974-guard-invalid-xml-provider
Open

fix(transport): Guard invalid XML in modTransportProvider#16975
Ibochkarev wants to merge 2 commits into
modxcms:3.xfrom
Ibochkarev:fix/16974-guard-invalid-xml-provider

Conversation

@Ibochkarev

Copy link
Copy Markdown
Collaborator

What changed and why

Seven methods in modTransportProvider called simplexml_load_string() and used the result without checking for parse failure. When a transport provider returns empty, HTML, or truncated content, PHP 8 fatals on $xml->getName().

This PR adds the same guard already in the second branch of latest() (#16326) to repositories(), categories(), stats(), info(), latest() (package name branch), find(), and verify(). Failed parses log the raw body and return provider_err_invalid_xml. The connector keeps returning JSON, so the Package Browser grid no longer hits ExtJS decode errors.

How to test

Point a transport provider at a URL that returns HTML or an empty body, then open Manager → Extras → Installer. You should see a provider error message, not a PHP fatal. The error log should contain the raw response body.

Related issue(s)/PR(s)

Resolves #16974

Refs #16326

Compatibility notes

Universal. No config or platform dependency. Uses existing lexicon key provider_err_invalid_xml.

Breaking change assessment

No signature or return type changes. Methods that already returned error strings on provider <error> XML now also return a string on invalid XML. verify() can return the lexicon string instead of (bool)false when the response is non-XML; Create.php and Update.php already handle non-boolean results via is_bool($verified).

Test coverage

No automated tests added. Same pattern as #16326. Manual verification against a misconfigured provider URL is sufficient.

Contributors

@Ibochkarev

AI tool use

Cursor AI assisted with implementation and PR preparation.

When a transport provider returns non-XML, simplexml_load_string()
returns false and calling getName() fatals on PHP 8. Apply the same
guard as latest() (modxcms#16326) to find() and six other methods so the
Package Manager returns provider_err_invalid_xml instead of breaking
the connector JSON response.

Fixes modxcms#16974
Move repeated invalid-XML guard from eight call sites into a single
protected method. Behavior unchanged; error logging context is still
passed per caller.
@Ibochkarev
Ibochkarev marked this pull request as ready for review July 23, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Fatal error in modTransportProvider::find() when provider returns non-XML

1 participant