47 lines
1003 B
Plaintext
Raw Normal View History

DOM open redirect vulnerabilities occur when user-controlled data like the ``++document.location.hash++`` property is directly used to perform redirections.
User-controlled data should always be considered untrusted and validated before being used to modify the DOM.
== Noncompliant Code Example
Example of DOM open redirect vulnerability (``++http://vulnerable/page.html#https://www.attacker.com/++``):
2022-02-04 17:28:24 +01:00
[source,javascript]
----
document.location = document.location.hash.slice(1);
----
== Compliant Solution
The URL can be validated with an allowlist:
2022-02-04 17:28:24 +01:00
[source,javascript]
----
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);
}
----
2021-10-28 10:07:16 +02:00
include::see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
endif::env-github,rspecator-view[]