Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sometimes I get "this file contains potentially unsafe dynamic content" message in Mathematica notebook

Sometimes, when I open my own notebook, I get the message:

This file contains potentially unsafe dynamic content.

I do not remember when I started seeing these messages, but it was not long ago. May be 2-3 weeks ago? They do not show all the time. It is my own notebook, that I could close, go sleep, wake up, come open it up again, and I could see the above message, or I could not. Not sure what triggers it.

Here is a screen shot of one just happened.

enter image description here

I normally just ignore it, and enable dynamics and go on. I googled around, and do not see mention of it. One reference I found is this, where it talks about TrustedPath and such, and I really could not understand it at all.

This notebook just sits in my folder on my PC, same folder it was on all the time. May be an expert can explain this in easy to understand way, because I do not understand why I need to worry about the trustedPath thing when I am working on my own local PC (I am not even on a network, just stand alone PC in my living room) and what I need to change if any.

I'm using v8.0.1 on windows.

like image 511
Nasser Avatar asked May 26 '11 19:05

Nasser


2 Answers

Mathematica notebooks can execute arbitrary code simply by virtue of opening the file. This code could be potentially malicious, and it can be very difficult to predict what the code will actually do prior to executing it.

When you open a notebook Mathematica doesn't know whether you are the original author of the notebook (and you trust the content to run automatically), or whether you downloaded a notebook from the website of a complete stranger (and you shouldn't trust the content to run automatically). The best guess Mathematica can make is based on the location of the file on your computer. Certain directories are trusted (i.e. the Mathematica installation directory) and other directories are untrusted (i.e. your web browser download folder and your email attachments folder). The settings that control which directories are trusted and which are untrusted are described in the documentation page you mentioned.

In your case what's probably happening is that your document is saved in your Desktop directory or some other directory which is untrusted and Mathematica is asking your permission before doing something it thinks may be potentially harmful. Since you know it is not harmful then you are safe to allow the Dynamic content.

If you do not want to see these warnings in the future you can do one of two things:

  • Move the notebook file to a directory that is trusted.
  • Remove the notebook's current directory from the list of untrusted directories specified by the UntrustedPath option.
like image 105
ragfield Avatar answered Oct 24 '22 08:10

ragfield


My comments assume V8 of Mathematica...

For any given notebook, the message appears the first time an expression is about to be evaluated automatically, in some way other than normal user-directed input cell evaluation. So-called dynamic constructs like Manipulate, Dynamic and Hyperlink have the potential of causing such evaluations. The warning message is just a way to ensure that user remains in control.

Sometimes No Warning?

As will be shown in the examples below, the message does not appear until the dynamic code is about to be triggered (e.g. by bringing a Manipulate into view or by hovering a Hyperlink). This is why, in the same notebook, you might sometimes see the message and sometimes not.

Manipulate Example

I see from the screenshot that the notebook in question is a Wolfram Demonstrations Project authoring notebook. It almost certainly contains a Manipulate expression that triggers the message.

Here is a way to cause the warning to appear:

  1. From the menu, choose File / New / Demonstration
  2. Scroll down to the manipulate section and change the expression to Manipulate[Plot[Sin[x y], {x, -1, 1}], {y, -1, 1}] -- but do not evaluate the cell.
  3. Save and close the notebook
  4. Re-open the notebook, but note that the warning message does not appear.
  5. Evaluate the Manipulate cell.
  6. Save and close the notebook.
  7. Re-open the notebook and note that warning message now appears (provided the manipulate section is visible -- if not, scroll down to see it).

The first time the notebook was re-opened, it did not contain a cell with dynamic content. But when the Manipulate cell was evaluated, that changed. Thus, on subsequent re-openings the warning message appeared.

Hyperlink Example

All of this true for even seemingly innocuous content, like hyperlinks. Try this:

  1. Create a regular notebook and evaluate a cell containing the expression Hyperlink["http://www.wolfram.com"].
  2. Save, close and re-open the notebook.
  3. Hover over the hyperlink to make the warning message appear.

It appears that WRI is taking a very conservative view about dynamic content. I, for one, applaud that policy. Mathematica presents a huge attack surface for malicious code, so a conservative approach is good in my opinion. (In fact, the new plug-in scares me a little on that score, but that's another story.)

Warning Settings

You can tweak the settings related to the warning message by looking at the Notebook Security section on the System tab of the Preferences dialog.

like image 25
WReach Avatar answered Oct 24 '22 08:10

WReach