I have a xulrunner application that uses browser component to display HTML content. For security reasons I would like to restrict that browser to be able to only access a certain url mask.
I would like to restrict any networking to intranet only, something like “*.company.com”. But not only page navigation, XHR, CSS, script and all the netwoking.
Does any body know how to implement this? Any XPCOM components that I could use for it?
The easiest way to do this would be through a proxy auto-configuration file (assuming that your application doesn’t actually need to use a proxy). So you would set
network.proxy.typepreference to 2 (use PAC file) andnetwork.proxy.autoconfig_urltochrome://.../proxy.js. Withproxy.jsbeing something along the lines of:So any requests to
*.company.comwon’t use a proxy whereas requests to other hosts will be directed to a localhost port which is hopefully closed – so these requests will not succeed. This is a hack of course but one that is simple enough and works well in most scenarios.The proper (but more complicated) way of doing this would be using content policies. You need to implement nsIContentPolicy in an XPCOM component and register that component in the
content-policycategory. This will make sure that theshouldLoad()method of your component will be called for each URL to be loaded – you can returnCi.nsIContentPolicy.REJECT_REQUESTto block the load.