veewee/xml
veewee/xml provides a type-safe, declarative API for working with XML in PHP, covering DOM, encoding, error handling, memory-safe readers and writers, XSD schemas, and XSLT. It handles errors for you and supports spec compliance on PHP 8.4+.
Strengths:
disallow_doctype() configurator aligns with modern security best practices by preventing XML DOCTYPE declarations, mitigating XXE (XML External Entity) attacks—a critical feature for APIs handling untrusted XML input.disallow_doctype() for Writer) reduces risk.Gaps:
disallow_doctype() is a step forward, adoption may require auditing existing XML parsing logic for DOCTYPE usage (potential breaking change in behavior).disallow_doctype() in middleware to sanitize XML requests (e.g., XmlRequestMiddleware), and use libxml issue detection to reject malformed XML early in the pipeline.XmlSchemaValidator::disallowDoctype()), surfacing libxml issues as validation messages.XmlSanitized events post-DOCTYPE removal for audit logging; add XmlLibxmlIssueDetected events for observability.Xml facade to include security methods (e.g., Xml::writer()->disallowDoctype()).Writer with disallow_doctype() for secure XML exports (e.g., Model::toXml()->disallowDoctype()); the in-memory write speedup directly improves batch export throughput.XmlReader::validate()->disallowDoctype()) and libxml issue detection to short-circuit invalid payloads.disallow_doctype() adds minimal overhead; v4.14.0’s faster in-memory writes are a net performance win for write-heavy flows, but benchmark to confirm no regression on read paths.spatie/xml-to-array (no DOCTYPE support) or custom DOMDocument filters for DOCTYPE removal.Xml::disallowDoctypeGlobally())?XmlWriterInterface with disallow_doctype() as a default config (e.g., config['xml.writer.doctype_allowed'] = false).Xml facade to include security methods:
Xml::writer()->disallowDoctype(); // Global setting
Xml::writer()->write()->disallowDoctype(); // Per-operation
AppServiceProvider to enforce DOCTYPE policies globally, and register libxml issue reporting into the logging channel.XmlDoctypeSanitizerMiddleware to parse, sanitize, and detect libxml issues in incoming XML:
public function handle(Request $request, Closure $next) {
$xml = $request->xml();
$xml->disallowDoctype()->validate();
if ($xml->hasLibxmlIssues()) {
throw new XmlValidationException($xml->getLibxmlIssues());
}
return $next($request);
}
Validator::extend('no_doctype', function ($attribute, $value, $parameters) {
return XmlReader::fromString($value)->disallowDoctype()->isValid();
});
php artisan xml:export models --no-doctype
disallow_doctype() and libxml issue detection in a non-critical XML endpoint (e.g., internal tool).allow_doctype() (if exists) in favor of explicit disallow_doctype().SimpleXMLElement/DOMDocument in favor of veewee/xml for all XML handling.disallow_doctype() or libxml issue detection).ext-dom/ext-xmlwriter, but ensure ext-xml is enabled.composer require veewee/xml:^4.14).disallow_doctype globally or per-service.disallow_doctype() in XmlWriter for all new XML generation.disallow_doctype() behavior (e.g., throws on DOCTYPE, allows clean XML) and libxml issue detection.disallow_doctype) ease adoption.XmlDoctypeBlocked events) and libxml issues surfaced by v4.14.0.disallow_doctype() adds negligible overhead; v4.14.0 improves write throughput via faster in-memory writes—benchmark in high-throughput scenarios.XmlReader).Writer/Reader components scale horizontally.| Scenario | Impact | Mitigation |
|---|---|---|
| DOCTYPE in trusted XML | False positives, rejected data | Whitelist trusted sources; per-service opt-out |
| libxml issue detection misfires | Spurious rejections in middleware | Log-then-enforce rollout; sample inputs |
| In-memory write regression | Throughput degradation on exports | Benchmark vs. 4.12.0; fall back to streaming |
| PHP 8.4+ requirement unmet | Cannot adopt 4.14.0 | Remain on v3.x or schedule PHP upgrade |
How can I help you explore Laravel packages today?