Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zendxml Laravel Package

zendframework/zendxml

ZendXml provides secure XML scanning/loading for PHP to help prevent XXE and XML entity expansion (XEE) attacks. It disables external entity loading and rejects documents using ENTITY declarations, returning SimpleXMLElement or DOMDocument. Repository abandoned; moved to laminas/laminas-xml.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Improved Fit for HTML/XML Hybrid Use Cases: The new Security::scanHtml() method expands the package’s utility beyond generic XML to include HTML-specific security scanning, making it viable for projects requiring:
    • Legacy HTML-to-XML conversion (e.g., scraping, migration tools).
    • Security hardening of user-generated HTML content (e.g., CMS rich-text fields stored as XML).
    • SOAP APIs with HTML fragments (e.g., error messages embedded in XML responses).
  • Laravel-Specific Gaps Persist:
    • Still lacks native integration with Laravel’s Blade templating, API resources, or validation rules for HTML/XML hybrid content.
    • No support for Laravel’s HTTP middleware to auto-sanitize HTML/XML payloads (e.g., SanitizeHtmlMiddleware).
    • Async/queue integration remains unsupported for security scanning tasks.

Integration Feasibility

  • Low-Medium Effort (Unchanged):
    • New Feature: The scanHtml() method can be wrapped in a Laravel service class (e.g., HtmlSanitizer::secure($html)) and integrated into:
      • Form requests (e.g., SanitizesHtml trait for Illuminate\Foundation\Http\FormRequest).
      • Middleware to sanitize HTML before XML serialization (e.g., app/Http/Middleware/SanitizeHtmlPayload).
    • Dependencies:
      • Requires ext-dom and ext-libxml (enabled by default in Laravel).
      • No breaking changes to existing XML parsing/generation workflows.
    • Validation: Can be paired with Laravel’s Illuminate\Validation\Rule to add HTML-specific rules (e.g., Rule::custom('secure_html')).

Technical Risk

  • Reduced Risk for HTML Use Cases:
    • Security: The scanHtml() method mitigates risks like XSS in XML-embedded HTML (e.g., SOAP fault messages).
    • Compatibility: No PHP 8.1+ breaking changes; method signatures align with Laravel’s type-hinting conventions.
  • Ongoing Risks:
    • Stale Codebase: Still no updates since 2019; no PHP 8.2+ support (e.g., no readonly property handling).
    • Maintenance Overhead: Custom error handling required for DOMException/SimpleXMLElement edge cases.
    • Testing Gap: No Laravel-specific test suite; manual QA needed for HTML/XML hybrid scenarios.
  • Mitigation:
    • Use composer’s replace to alias the package and isolate it from core dependencies.
    • Combine with modern libraries:
      • masterminds/html5 for HTML5-specific sanitization.
      • spatie/laravel-html for Laravel-native HTML handling.

Key Questions

  1. HTML/XML Hybrid Needs: Is this package being adopted for HTML sanitization, XML parsing, or both? Prioritize accordingly.
  2. Security Scope: Will scanHtml() replace existing XSS protections (e.g., Purifier, HTMLPurifier)? Audit overlap.
  3. Performance: How often will scanHtml() run? Large HTML fragments may impact memory (test with memory_get_usage()).
  4. Team Skills: Does the team have experience with DOM/LibXML security? Plan training if needed.
  5. Alternatives:
    • For HTML-only: Use spatie/laravel-html or masterminds/html5.
    • For XML-only: Evaluate php-xml (Symfony) or ext-simplexml for modern PHP support.

Integration Approach

Stack Fit

  • Laravel Core:
    • Request/Response: Use middleware to auto-sanitize HTML/XML payloads:
      // app/Http/Middleware/SanitizePayload.php
      public function handle($request, Closure $next) {
          if ($request->isHtml()) {
              $request->merge(['sanitized_html' => Security::scanHtml($request->html)]);
          }
          return $next($request);
      }
      
    • Validation: Add a custom rule:
      // app/Rules/SecureHtml.php
      public function passes($attribute, $value) {
          return is_bool(Security::scanHtml($value));
      }
      
    • API Resources: Extend JsonResource to sanitize HTML fields before XML serialization.
  • Frontend:
    • If serving sanitized HTML in XML responses, use Laravel Mix to polyfill XML/HTML handling in SPAs.
    • Deprecate innerHTML in favor of textContent for security.
  • Queue Jobs:
    • Wrap Security::scanHtml() in a SanitizeHtmlJob for async processing of large payloads.

Migration Path

  1. Phase 1: HTML Sanitization Proof of Concept
    • Isolate Security::scanHtml() in a Laravel service (e.g., app/Services/HtmlSanitizer).
    • Test with a single HTML field (e.g., CMS content stored as XML).
  2. Phase 2: XML/HTML Hybrid Integration
    • Add middleware to sanitize HTML before XML parsing/generation.
    • Extend XmlParser to use scanHtml() for HTML fragments in XML.
  3. Phase 3: Full Security Overhaul
    • Replace ad-hoc XSS protections with scanHtml().
    • Deprecate legacy HTML handling (e.g., strip_tags() calls).

Compatibility

  • PHP 8.1+:
    • No Breaking Changes: scanHtml() uses scalar types (string, int) compatible with PHP 8.1+.
    • Attribute Support: If using PHP 8.0+, consider adding attributes to configure libXmlConstants (e.g., [Attribute] public int $flags).
  • Laravel 9+:
    • No Conflicts: Method signatures avoid Symfony/Laravel-specific types (e.g., Stringable).
    • Testing: Verify DOMDocument/SimpleXMLElement return types align with Laravel’s type system.
  • Database:
    • Store sanitized HTML in LONGTEXT columns with doctrine/dbal for migrations.
    • Use spatie/laravel-activitylog to audit HTML/XML changes.

Sequencing

Step Task Dependencies
1 Audit HTML/XML usage Identify all HTML fields in XML payloads.
2 Create HtmlSanitizer service None
3 Add middleware for request sanitization Route groups.
4 Integrate with XML parsing/generation XmlParser/XmlGenerator classes.
5 Test with malicious HTML payloads Fuzz testing (e.g., <script>alert(1)</script>).
6 Deprecate legacy sanitization methods API versioning.
7 Monitor performance Laravel Debugbar.

Operational Impact

Maintenance

  • Effort: Medium-High
    • New Feature: scanHtml() reduces XSS risks but adds new attack surface (e.g., libXmlConstants misconfiguration).
    • Custom Code: Middleware, services, and validators require updates for Laravel minor versions.
    • Security Patches: Manual monitoring for:
      • LibXML vulnerabilities (e.g., CVE-2023-XXXX).
      • False positives in scanHtml() (e.g., legitimate <script> tags in XML comments).
  • Tooling:
    • Use roave/security-advisories to scan for LibXML risks.
    • Add phpstan/extension-installer to analyze DOMDocument usage.

Support

  • Debugging:
    • Log libxml_get_errors() for scanHtml() failures.
    • Document common pitfalls (e.g., "False negatives with SVG tags").
  • Documentation:
    • Runbooks for:
      • scanHtml() false positives/negatives.
      • Large HTML performance tuning (e.g., chunked processing).
    • Example: "How to whitelist <img> tags in XML-embedded HTML."

Scaling

  • Performance:
    • Bottlenecks: scanHtml() can be slow for large HTML (>1MB). Mitigate with:
      • Caching: Cache sanitized results (e.g., Redis::remember('sanitized-html-$hash', ...)).
      • Streaming: Use SimpleXMLElement for lightweight parsing.
    • Concurrency: Queue scanHtml() jobs for high-throughput APIs.
  • Concurrency:
    • Avoid locking issues with Illuminate\Cache\Lock for shared sanitization tasks.

Failure Modes

Scenario Impact Mitigation
Malicious HTML XSS in XML responses Use scanHtml() with LIBXML_NOENT flag.
Large HTML OOM killer, timeouts Stream-process with `Simple
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor