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[]
