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…”
FileNameJoin@{$InstallationDirectory, "AddOns", "Applications", "Security"}
$\endgroup$Symbol
sinceanything[[0]]
will beSymbol
. E.g. withanything[[0]]["Del" ~~ "eteF" ~~ "ile"]
I getDeleteFile
in a way that would pass most whitelists and most blacklists. Of course, it can be prevented by undefining dangerous functions. $\endgroup$