Loris S cd03a1dd3d
Modify S5144&S6547: Improve fixes (#2912)
## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
2023-08-21 10:51:21 +02:00

36 lines
809 B
Plaintext

== How to fix it in Core PHP
=== Code examples
The following code is vulnerable to SSRF as it opens a URL defined by untrusted data.
==== Noncompliant code example
[source,php,diff-id=1,diff-type=noncompliant]
----
$host = $_GET['host'];
$url = "https://$host/.well-known/openid-configuration";
$ch = curl_init($url); // Noncompliant
curl_exec($ch);
----
==== Compliant solution
[source,php,diff-id=1,diff-type=compliant]
----
$allowedHosts = ["trusted1" => "trusted1.example.com", "trusted2" => "trusted2.example.com"];
$host = $allowedHosts[$_GET['host']];
$url = "https://$host/.well-known/openid-configuration";
$ch = curl_init($url);
curl_exec($ch);
----
=== How does this work?
include::../../common/fix/pre-approved-list.adoc[]
=== Pitfalls
include::../../common/pitfalls/starts-with.adoc[]