← PHP / Laravel · Contents

PHP-050 / Advanced

Allowing XML external entity parsing (XXE)

A05:2021 Security Misconfiguration · CWE-611 Improper Restriction of XML External Entity Reference

Why is this a problem?

Reading file:///etc/passwd and SSRF are possible.

How to fix it

php
libxml_set_external_entity_loader(fn() => null);   // PHP 8.x disables external entities by default; explicit configuration is recommended
$xml = simplexml_load_string($request->getContent(), 'SimpleXMLElement', LIBXML_NONET);

Further reading