Block IFrames JS Code

General discussion about the NoScript extension for Firefox
Post Reply
sacharja
Posts: 2
Joined: Fri Jun 03, 2011 10:26 pm

Block IFrames JS Code

Post by sacharja »

Hello,

I've read about NoScript's ability to block IFrames. I desperately try to do this for Opera, however I want to filter them, based on the URL. However, I couldn't find a way to block the IFrame before it opens the specified source URL. Is NoScript able to do this? Could someone tell me where I can find the code for that in NoScript, or has an idea how to do this in JS? I only want to block external IFrames, that match these RegExp:

Code: Select all

"[?*&=,~-]http(?::|%3A)(?:\/|%2F)(?:\/|%2F)"
.

Currently I edit websites with Proxomitron, where I can block non-scripted IFrames. Then I tried to edit all JS methods, that can create IFrames (I replaced document.write, rewrote XMLHttpRequests, DOMNodeInserted...), but these may lead to further problems. If someone has a direct solution to block IFrames in JS, please help me.
Opera/9.80 (Windows NT 5.1; U; en) Presto/2.8.131 Version/11.11
User avatar
Giorgio Maone
Site Admin
Posts: 9524
Joined: Wed Mar 18, 2009 11:22 pm
Location: Palermo - Italy
Contact:

Re: Block IFrames JS Code

Post by Giorgio Maone »

You can't: there are simply countless ways for a script to insert and manipulate a DOM element (obfuscation aside), therefore a proxy cannot prevent iframes from being created. You need in-browser support for that.
Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
sacharja
Posts: 2
Joined: Fri Jun 03, 2011 10:26 pm

Re: Block IFrames JS Code

Post by sacharja »

Thanks for the info. Then I have to disable IFrame creation. I use a code to overwrite XMLHttprequests (and to filter them). Maybe this is an additional feature for NoScript, so I post it here:

Code: Select all

XMLHttpRequest.prototype.oldOpen = XMLHttpRequest.prototype.open;

	var newOpen = function(method, url, async, user, password) {
		if (method=='GET' && url.lastIndexOf('http')<8) {this.oldOpen(method, url, async, user, password);}
	}

XMLHttpRequest.prototype.open = newOpen;
This can be extended with a blacklist/whitelist. However there is a problem with the new Google search. It's very slow. Even if you only use "this.oldOpen(method, url, async, user, password);" instead of the if loop. Typing is no longer possible in realtime in the google search box.
Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Post Reply