Lock Firefox 6 Prefs (Also versions 3, 4, & 5)

In a corporate environment, it's often important to enforce Internet proxy settings for all users. Setting those options automatically is often difficult. Making them locked and immutable is even more difficult and poorly documented. Today we'll learn the basics, and from there you can customize Firefox as much or as little as you like.

The first thing to understand is how Firefox preferences work. In your browser, type the address "about:config" and press enter. After agreeing to their warning message, you should see a whole list of configuration options listed with their current settings. These settings are for your user only, but it should help you get the notion for just how many settings are possible to set.

If you're comfortable with the command line, the steps we're going to go over are quicker and easier with a terminal window, but we're going to show the GUI way so as not to exclude anyone. (If you are comfortable on the command line, you'll know how to follow the directions below without any problems)

I'm using Ubuntu 11.04 for this demonstration, but most distributions have similar setups. You might have to search a little for where preference files are stored, but the procedure will be similar. First we need to open a Nautilus window with superuser privileges. To do that, press ALT-F2, then type: gksudo nautilus and press enter.

Just click run!

Next we need to navigate the file system to the /etc/firefox directory. Depending on your version of Firefox, and your distribution, this folder and its contents might vary a bit. This is what it looks like with Ubuntu 11.04 and Firefox 6:

This might look different, you might have to edit a different file

The file we want to edit is that syspref.js file. This file might not be here for different versions, in which case you can try editing whatever .js file you find. Also files inside the pref folder are usually parsed, so you could create a .js file in there and it will probably work. Unfortunately, you'll just need to try it and see if it works.

Double click on the file, and it should open (with superuser privileges) in a text editor. You'll see this file was designed for adding custom preferences. Unfortunately, you can't lock preferences in here. Anything added to this file will be the default for new users, but you can't lock any preferences for all users. What we'll do is add a directive for another config file. In that one, we can lock prefs. You'll want to add the following to the bottom of the syspref.js file:

pref("general.config.obscure_value", 0);
pref("general.config.filename", "firefox.cfg");

Here's what my file looks like:

Anything else added will be defaults, but not immutable

Close that window and save the file. Next we need to make the firefox.cfg file we referenced. It would make sense that we'd put the file in the same folder, but sadly that's not the case. The file firefox.cfg with our locked preference settings needs to go in the /usr/lib/firefox-$VERSION/ folder. We need to replace $VERSION with the currently installed version of Firefox. That's where it gets a little confusing. If Firefox gets updated, we have to remember to move the firefox.cfg file to the new firefox-$VERSION folder. To do that, look in /usr/lib for the firefox folders that exist, and pick your current version. Here I've highlighted my current version, which is /usr/lib/firefox-6.0.

This is the most confusing part, but once you understand, it's not too bad

Once inside that folder, we need to create the lock file, which must be named whatever we called it back in the syspref.js file. In our case, we need to create a file called firefox.cfg.

Name the file firefox.cfg

Make sure to name the file "firefox.cfg" when you create it. Then double-click on the file, and we'll add our custom configuration. The preferences I'm most concerned with are Homepage Settings and Proxy Settings. Here's what goes into my firefox.cfg:

// Lock specific preferences in Firefox so that users cannot edit them
lockPref("app.update.enabled", false);
lockPref("network.proxy.http", "192.168.1.100");
lockPref("network.proxy.http_port", 3128);
lockPref("network.proxy.ssl", "192.168.1.100");
lockPref("network.proxy.ssl_port", 3128);
lockPref("network.proxy.type", 1);
lockPref("network.proxy.no_proxies_on", "localhost, 127.0.0.1, 192.168.1.0/24");
lockPref("browser.startup.homepage", "http://www.linuxjournal.com");

Note the lockPref directive. It differs from what we put in the syspref.js file, and as you'd expect, it locks the given preference. Here's what it looks like on my system:

You can lock any preference here

All that is left is to save that file, and close the Nautilus window. (Remember, you're running Nautilus as root -- that's not something you want to do willy nilly) Now, when users start Firefox, it will use the preferences you set, regardless of any setting they might have already set. For example, if a user tries to edit the proxy settings on my system, the fields I specified are not even available to change!

Why no, you can't change your proxy setting... :)

Hopefully this tutorial can be adapted to meet your Firefox needs. The ability to lock preferences is vital in a large network. I wish the procedure was better documented, but at least it's possible. Have fun!

Shawn is Associate Editor here at Linux Journal, and has been around Linux since the beginning. He has a passion for open source, and he loves to teach. He also drinks too much coffee, which often shows in his writing.

Load Disqus comments