I no longer believe it is a good idea to work with a list of dangerous functions. I have tried to edit the question is such a way that it respects my earlier perspective, but also so that it does not give users the impression that certain things are safe whereas they are not.
Introduction
Running Mathematica code from an untrusted source is very dangerous. Luckily, Mathematica warns you about dynamic content, so that it is probably safe to open any notebook, as long as you don't run it.
I feel it would be very nice to have a list of functions that can harm a system. Using this, we may be able to make a function that checks if a notebook is safe.
A function to find dangerous functions
A naive function to see if dangerous expressions are present in a NotebookObject
, could be the following.
Through[{Unprotect, ClearAll}[dangerousFunctionsQ]]
dangerousFunctionsQ[nb_] := !
FreeQ[ToExpression[Unevaluated[#], StandardForm,
HoldComplete] & /@ (NotebookRead@Cells[nb])[[All, 1]],
Alternatives @@ listOfDangerousFunctions];
Protect[dangerousFunctionsQ];
Where listOfDangerousFunctions
is given. Unfortunately, this code does not guarantee safety, even we know the full list of dangerous functions.
Furthermore, getting the NotebookObject
is a bit tricky. We could simply open the notebook and use Notebooks
, but opening the notebook doesn't sound too safe. Also making an automated approach based on this is inelegant. Note however, that using the obvious alternative, which is to use Import
(with one argument) on the notebook file turns out not to be safe.
The question is: Which built-in functions are dangerous (especially just by themselves)?
Related
In a CDF can I suppress or avoid “This file contains potentially unsafe dynamic content…”
Answer
Honestly, Mathematica is so flexible and has so many undocumented functions tucked away in nooks that I think it would be better to create a white-list of safe functions than to try to list all potentially dangerous ones.
Better still would be to simply run Mathematica on a virtual machine or in an instance of Sandboxie where no damage is permanent (excepting privacy issues if network access is not blocked).
Comments
Post a Comment