rspec/rules/S5335/php/rule.adoc

41 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
User-provided data such as URL parameters, POST data payloads or cookies should always be considered untrusted and tainted. Constructing include statements based on data supplied by the user could enable an attacker to control which files are included. If the attacker has the ability to upload files to the system, then arbitrary code could be executed. This could enable a wide range of serious attacks like accessing/modifying sensitive information or gain full system access.
2021-04-28 16:49:39 +02:00
The mitigation strategy should be based on whitelisting of allowed values or casting to safe types.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2021-04-28 16:49:39 +02:00
----
$filename = $_GET["filename"];
include $filename . ".php";
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2021-04-28 16:49:39 +02:00
----
$filename = $_GET["filename"];
if (in_array($filename, $whitelist)) {
include $filename . ".php";
}
----
2021-10-28 10:07:16 +02:00
include::see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]