2021-04-26 17:29:13 +02:00
|
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
|
[source,javascript]
|
2021-04-26 17:29:13 +02:00
|
|
|
|
----
|
|
|
|
|
const request = require('request');
|
|
|
|
|
|
|
|
|
|
function ssrf(req, res) {
|
|
|
|
|
const url = req.query.url;
|
|
|
|
|
|
|
|
|
|
request(url, callback); // Noncompliant
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
|
|
Validate the url with an allowlist:
|
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
|
[source,javascript]
|
2021-04-26 17:29:13 +02:00
|
|
|
|
----
|
|
|
|
|
const request = require('request');
|
|
|
|
|
|
|
|
|
|
function ssrf(req, res) {
|
2022-01-17 17:57:50 +01:00
|
|
|
|
const white_list = [ "www.example.com", "example.com" ]
|
|
|
|
|
|
|
|
|
|
const url = (new URL(req.query.url));
|
|
|
|
|
const remote_hostname = url.hostname;
|
2021-04-26 17:29:13 +02:00
|
|
|
|
|
2022-01-17 17:57:50 +01:00
|
|
|
|
if (white_list.includes(remote_hostname)) {
|
|
|
|
|
request(url, callback);
|
2021-04-26 17:29:13 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
== Implementation Specification
|
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
|
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|