2023-10-25 09:38:17 +02:00
|
|
|
File access functions in PHP are typically used to open local files. They are
|
|
|
|
also capable of reading files from remote servers using protocols such as HTTP,
|
|
|
|
HTTPS and FTP.
|
|
|
|
|
|
|
|
This behavior is controlled by the `allow_url_fopen` and `allow_url_include`
|
|
|
|
settings.
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
Most applications do not require or expect the file access functions to download
|
|
|
|
remotely accessible files. However, attackers can abuse these remote file access
|
|
|
|
features while exploiting other vulnerabilities, such as path traversal issues.
|
|
|
|
|
|
|
|
=== What is the potential impact?
|
|
|
|
|
|
|
|
While activating these settings does not pose a direct threat to the
|
|
|
|
application's security, they can make the exploitation of other vulnerabilities
|
|
|
|
easier and more severe.
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
If an attacker can control a file location while `allow_url_fopen` is set
|
|
|
|
to `1`, they can use this ability to perform a Server-Side Request Forgery
|
|
|
|
exploit. This allows the attacker to affect more than just the local application
|
|
|
|
and they may be able to laterally attack other assets on the local network.
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
If `allow_url_include` is set to `1`, the attacker will also have the ability to
|
|
|
|
download and execute arbitrary PHP code.
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
== How to fix it
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
`allow_url_fopen` and `allow_url_include` should be deactivated in the main PHP
|
|
|
|
configuration file. Note that `allow_url_include` is disabled by default while
|
|
|
|
`allow_url_fopen` is not and must be explicitly disabled.
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
=== Code examples
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
|
|
|
|
|
|
|
[source,php,diff-id=1,diff-type=noncompliant]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
2023-10-25 09:38:17 +02:00
|
|
|
; php.ini Noncompliant; allow_url_fopen is enabled by default
|
2021-04-28 16:49:39 +02:00
|
|
|
allow_url_include=1 ; Noncompliant
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
==== Compliant solution
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
[source,php,diff-id=1,diff-type=compliant]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
; php.ini
|
|
|
|
allow_url_fopen=0
|
|
|
|
allow_url_include=0
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
== Resources
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-10-25 09:38:17 +02:00
|
|
|
=== Standards
|
|
|
|
|
|
|
|
* OWASP - https://owasp.org/Top10/A05_2021-Security_Misconfiguration/[Top 10 2021 Category A5 - Security Misconfiguration]
|
|
|
|
* OWASP - https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration[Top 10 2017 Category A6 - Security Misconfiguration]
|
|
|
|
* CWE - https://cwe.mitre.org/data/definitions/829[CWE-16 - Inclusion of Functionality from Untrusted Control Sphere]
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
* Disable "xxx".
|
|
|
|
* Disable "allow_url_fopen" explicitly; it is enabled by default.
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== on 1 Sep 2015, 07:42:52 Linda Martin wrote:
|
|
|
|
LGTM!
|
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|