30 lines
557 B
Plaintext
Raw Normal View History

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/):
----
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[]