veewee/xml
Type-safe, declarative XML toolkit for PHP. Includes DOM helpers, safe error handling, memory-safe reader/writer, XML encode/decode, plus XSD and XSLT utilities. Spec-compliance ready for PHP 8.4+, with maintained v3 for older PHP.
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).XmlSchemaValidator::disallowDoctype()).XmlSanitized events post-DOCTYPE removal for audit logging.Xml facade to include security methods (e.g., Xml::writer()->disallowDoctype()).Writer with disallow_doctype() for secure XML exports (e.g., Model::toXml()->disallowDoctype()).XmlReader::validate()->disallowDoctype()).disallow_doctype() adds minimal overhead; benchmark to ensure no regression in large-file scenarios.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.XmlDoctypeSanitizerMiddleware to parse and sanitize incoming XML:
public function handle(Request $request, Closure $next) {
$xml = $request->xml();
$xml->disallowDoctype()->validate();
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() 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()).ext-dom/ext-xmlwriter, but ensure ext-xml is enabled.composer require veewee/xml:^4.12).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).disallow_doctype) ease adoption.XmlDoctypeBlocked events).disallow_doctype() adds negligible overhead; benchmark in high-throughput scenarios.XmlReader).Writer/Reader components scale horizontally.| Scenario | Impact | Mitigation |
|---|---|---|
| DOCTYPE in trusted XML | False positives, rejected data |
How can I help you explore Laravel packages today?