47 lines
739 B
Plaintext
47 lines
739 B
Plaintext
include::../description.adoc[]
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
function (req, res) {
|
|
const url = req.query.url; // user controlled input
|
|
|
|
res.redirect(url); // Noncompliant
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
Validate the URL with an allowlist:
|
|
|
|
----
|
|
function isValidUrl(url) {
|
|
if(url.startsWith("https://www.safe.com/")) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
function (req, res) {
|
|
const url = req.query.url; // user controlled input
|
|
|
|
if(isValidUrl(url)) {
|
|
res.redirect(url); // Compliant
|
|
}
|
|
}
|
|
----
|
|
|
|
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[]
|