blocking filesystem access in firefox > 3.5

OK, I had this situation: I had to turn firefox 8 into a kiosk browser.

With addons like public fox, reset kiosk, r-kiosk and custom geometry/ff fullscreen the most part was done. Except, you could still enter file:// in the url bar and then see filesystem files.

To block that proved to be very very difficult. Most tutorials, hints and everything else seem to deal with browser.jar respectively browser.js inside that. Buut, firefox >= 4.0 has omni.jar, replacing browser.jar.

OK, after figuring that out, I found out that mozilla “optimized” jar. Normally, jar files are simple zip files, so either renaming them or having a proper tool will unpack them. It seems, Win7 explorer or WinZip are capable of unpacking. unzip under linux also managed to unpack it – but I doubted that simply zipping it would work too good.

After yet another round of googling I found this tool: http://hg.mozilla.org/mozilla-central/file/f7016571b472/config/optimizejars.py. Nice path, hmm? And, sure enough, documentation on how to use it is also scarce. To make a long googling short: python optimizejars.py --deoptimize ./ ./ ./ (in the path where omni.jar is).

The output of that will look something like this:

./omni.jar: startup data ends at byte 1338505
Deoptimized 199/1342 in ./omni.jar

Now you can open the jar file with e.g. mc, navigate to chrome/browser/content/browser/ inside and edit (F4) urlbarBindings.xml.

Find something similar to this inside:

[url, postData, mayInheritPrincipal] = this._canonizeURL(aTriggeringEvent);
if (!url)
return;

Right after the return; (before the closing bracket }), insert this:

if (url.match(/^file:/) || url.match(/^\//) || url.match(/^resource:/) || url.match(/^about:/)) {
alert("Access denied.");
exit
}

Save the file (F10), close mc and now “optimize” the file again: python optimizejars.py --optimize ./ ./ ./

This yields this output:

./omni.jar: startup data ends at byte 1338705
Ordered 199/1342 in ./omni.jar

Now that omni.jar can be copied back to it’s original place and firefox should start with it.

Test the function of the added code by typing “file://” in the address bar. It should show an “access denied” in the browser window.

Credits:

Definitely NO credits to mozilla.org or their coders for the > 100Mio. $ they spend each year. Their docs and examples are useless – and besides: how about integrating everything into firefox to enable a “-kiosk” switch, like opera has? If opera could handle motion jpeg files, I’d stick with that…