Sunday, November 24, 2013

Securing Your Firefox

While its popularity suffers from a decline in the past year or two, Firefox is still a great browser which has a lot of things to offer. One of those things is the ability to control whether a plug-in will start automatically when the relevant content is being loaded, or should the browser ask for the end-user’s permissions to activate the plug-in on a per-site basis.

When can the above functionality be most useful? When defending against malware. The sad truth is that being infected via a drive-by malware is something that can happen to anyone, regardless the security measures being taken (e.g using Linux or OSX, having an anti-virus running or using a browser which is not IE). Due to the increased efforts in making it secure, Firefox has very little known vulnerabilities in the core browser engine, forcing the bad guys to opt for its plug-ins as the attack vector.

Unfortunately, Adobe (maker of Flash and Reader) and Oracle (maker of Java) are still doing a so-so job in terms of making secure software, thus it is recommended to have their plug-ins run only when the user approves them to run.
As a matter of fact, I’d recommend getting rid of Java and Reader entirely, yet Flash is still needed for many sites, thus cannot be discarded easily.

So how could one make Firefox ask for a permission to run such plug-ins? Easy:
  1. Open the “tools” menu and choose “add-ons” (ctrl-shift-a for non OSX users).
  2. Choose the “plug-ins” tab on the left panel.
  3. Choose “ask to activate” for the not-so-secure plug-ins.

That’s it. Have a safe browsing.

Friday, November 8, 2013

Be specific with your python conditionals

Here’s a mistake in Python that I saw getting done time and again:
some_val = some_dict.get(some_key, None)  # the None is optional in this case
if some_val: do_something(some_val)
What’s wrong?
Usually, the person who writes such code wants do_something to run whenever some_value is not None, yet if some_val is an empty list, empty dict or even the number 0 - do_something will not run! The right way to do it is:
if some_val is not None: do_something(some_val)
alternatively, one can check
if some_key in some_dict: …
Both options are more verbose and will get the job done.

The OSX ‘open’ command

A few days ago I was asked “how can one open more than a single instance of an application in OSX?”. The question was raised because by default OSX will open the already running application instance when an application icon is clicked (or entered via spotlight) more than once.
My first guess was to invoke the application executable directly from the command line - and it worked. But then it made me think maybe there’s a better way to do it, so I found the open command. This command is quite versatile, allowing one to “open” a file with its default handler application or with an alternative one, open any file with a text editor, stream the standard input to a text editor, fix applications which has windows that has gone out-of-view and more. For the above requirement, the “-n” flag can be used, such as:
open -n /Application/
The application becomes independent from the terminal session and the prompt can be used to re-launch another instance immediately. Simple and elegant.