ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor - P4
    • 5.12.0
    • Affects Version/s: None
    • None
    • 3
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Defense-in-depth hardening from SECBUG-4404.

      When loading a polymorphic morphTo relation, the stored *_type value is resolved via getActualClassNameForMorph() and passed to new $class() before any check that the class is an Eloquent model. If the stored type has been tampered with (which requires prior write access to the database), the constructor of an arbitrary zero-argument class runs, followed by a fatal Error.

      The root cause is in Laravel core: getActualClassNameForMorph() falls back to the raw class string on read, and requireMorphMap() is only enforced on the write side (getMorphClass()). The real fix therefore belongs upstream. As defense-in-depth in this package, add a guard that verifies the resolved class is_a(..., Illuminate\Database\Eloquent\Model::class) before instantiating, and throws otherwise, on both paths:

      • HybridRelations::morphTo() at src/Eloquent/HybridRelations.php:245-247 (lazy access)
      • an override of createModelByType() in src/Relations/MorphTo.php (eager loading)

      Add a test with a poisoned morph-type value asserting an exception is thrown before instantiation.

      Severity: low (hardening).

              Assignee:
              Pauline Vos
              Reporter:
              Jérôme Tamarelle
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: