2021-04-28 16:49:39 +02:00

27 lines
510 B
Plaintext

== Noncompliant Code Example
Example of DOM open redirect vulnerability (``++http://vulnerable/page.html#\https://www.attacker.com/++``):
----
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);
}
----