Sample code:
function winLoad() {
var sessionId = '';
if (window.location == window.top.location) {
var semicolonIndex = window.location.href.indexOf(';');
if (semicolonIndex != -1) {
var questionMarkIndex = window.location.href.indexOf('?');
if (questionMarkIndex != -1) {
sessionId = window.location.href.substr(semicolonIndex, questionMarkIndex - semicolonIndex);
} else {
sessionId = window.location.href.substr(semicolonIndex);
}
}
}
};
Is it possible to inject arbitrary Javascript commands with the URL like this: https://example.com;';alert(document.domain);'
? The input does not get reflected on the site and I've been trying to figure out how to close the string and add arbitrary commands right after it using browser consoles:
- not a malicious payload
https://example.com/foo;bar
->";bar"
in FF and';bar'
in Chrome - malicious payload
https://example.com/foo;';alert(document.domain);'
->";';alert(document.domain);'"
, input get surrounded by double quotes - malicious payload
https://example.com/foo;";alert(document.domain);"
->";%22;alert(document.domain);%22"
, double quotes get encoded
I've also been trying to look up if the location.href
method encodes double quotes only in some parts of the URL (path /foo/
, query ?foo=bar
and hash #foo
) but so far it seems that they always get encoded.
sessionId = ";foo";alert(1);""
which I thought would cause a popup. But guessing from your answer I assume this doesn't work and you need some sort of a sink function that takes the payload as input?a = "alert(1)"
should execute this text?a = ""
and then after my input it will look like thisa = "";alert(1);""
, where my input is";alert(1);"
. Maybe I'm under the wrong impression that this would close the double quotes ofa
, insert thealert(1)
function and then add another double quote for the hanging double quote. So I would be left witha = "";
followed byalert(1);
followed by""
. Soalert(1)
would not be part of the string.