rspec/rules/S2755/php/rule.adoc

81 lines
2.5 KiB
Plaintext
Raw Normal View History

include::../description.adoc[]
== Noncompliant Code Example
https://www.php.net/manual/fr/function.simplexml-load-string.php[SimpleXML] object:
2022-02-04 17:28:24 +01:00
[source,php]
----
$xml = file_get_contents("xxe.xml");
$doc = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOENT); // Noncompliant (LIBXML_NOENT enable external entities substitution)
----
https://www.php.net/manual/fr/class.domdocument.php[DOMDocument] object:
2022-02-04 17:28:24 +01:00
[source,php]
----
$doc = new DOMDocument();
$doc->load("xxe.xml", LIBXML_NOENT); // Noncompliant (LIBXML_NOENT enable external entities substitution)
----
https://www.php.net/manual/fr/xmlreader.xml.php[XMLReader] object:
2022-02-04 17:28:24 +01:00
[source,php]
----
$reader = new XMLReader();
$reader->open("xxe.xml");
$reader->setParserProperty(XMLReader::SUBST_ENTITIES, true); // Noncompliant (SUBST_ENTITIES enable external entities substitution)
----
== Compliant Solution
https://www.php.net/manual/fr/function.simplexml-load-string.php[SimpleXML] object:
2022-02-04 17:28:24 +01:00
[source,php]
----
$xml = file_get_contents("xxe.xml");
$doc = simplexml_load_string($xml, "SimpleXMLElement"); // Compliant (external entities substitution are disabled by default)
----
https://www.php.net/manual/fr/class.domdocument.php[DOMDocument] object:
2022-02-04 17:28:24 +01:00
[source,php]
----
$doc = new DOMDocument();
$doc->load("xxe.xml"); // Compliant (external entities substitution are disabled by default)
----
https://www.php.net/manual/fr/xmlreader.xml.php[XMLReader] object:
2022-02-04 17:28:24 +01:00
[source,php]
----
$reader = new XMLReader();
$reader->open("xxe.xml");
$reader->setParserProperty(XMLReader::SUBST_ENTITIES, false); // Compliant (SUBST_ENTITIES set to false)
----
== See
* https://owasp.org/Top10/A05_2021-Security_Misconfiguration/[OWASP Top 10 2021 Category A5] - Security Misconfiguration
* https://www.owasp.org/index.php/Top_10-2017_A4-XML_External_Entities_(XXE)[OWASP Top 10 2017 Category A4] - XML External Entities (XXE)
* https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html#php[OWASP XXE Prevention Cheat Sheet]
2021-10-28 10:07:16 +02:00
* https://cwe.mitre.org/data/definitions/611.html[MITRE, CWE-611] - Information Exposure Through XML External Entity Reference
* https://cwe.mitre.org/data/definitions/827.html[MITRE, CWE-827] - Improper Control of Document Type Definition
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]