2020-12-21 15:38:52 +01:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
2021-02-08 16:21:28 +01:00
|
|
|
Example of dom open-redirect vulnerability (\http://vulnerable/page.html#https://www.attacker.com/):
|
2020-12-21 15:38:52 +01:00
|
|
|
|
|
|
|
----
|
|
|
|
document.location = document.location.hash.slice(1);
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
The url can be validated with an allowlist:
|
|
|
|
|
|
|
|
----
|
|
|
|
function isValidUrl(url) {
|
|
|
|
if(url.startsWith("https://www.example.com/")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isValidUrl(document.location.hash.slice(1))) {
|
|
|
|
document.location = document.location.hash.slice(1);
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|