为什么我会收到安全警告消息“此文件包含潜在不安全的动态内容”在这个构造中
我终于能够重现我偶尔收到的这条消息了。
这是在 Windows 7 的 V8.04 上进行的。
在尝试过程中,我发现当我打开带有 Manipulate 的笔记本时,如何使 Mathematica 生成上述消息。
首先是错误消息屏幕:
我现在点击“启用动态”,一切似乎都很好。但每次我重新打开笔记本时,我都会再次收到该消息。 (必须关闭M,然后重新启动,然后打开笔记本才能看到该消息)。
所以我不明白这个警告消息,为什么会出现,以及我需要在代码中更改什么来删除它。
生成它的代码是:
Manipulate[
DynamicModule[{p},
p["x"] = 0;
Row[{Dynamic[
Refresh[p["x"]++; Row[{"p[x]=", p["x"]}],
TrackedSymbols -> {n}]]}]
],
Button["update counter", n++],
{{n,0}, None}
]
上面是在它自己的笔记本上,笔记本中没有其他内容。
我关闭M,然后启动它,然后打开笔记本,我看到上面的消息。
现在,我最初认为要删除该消息,我需要将 p["x"] 更改为 p[x] 所以我关闭了上面的笔记本,并使用以下代码创建了一个新笔记本:
Manipulate[
DynamicModule[{p},
p = 0;
Row[{Dynamic[Refresh[p++; Row[{"p=", p}], TrackedSymbols -> {n}]]}]
],
Button["update counter", n++],
{{n, 0}, None}
]
然后关闭 M,并再次启动它,并打开上面的笔记本, 现在我没有看到警告消息。但是当我重复这个过程时,我看到同样的错误又出现了。
(我将这个问题发布到数学组,但这很慢,而且我的帖子甚至没有出现在那里,但在那篇帖子中我说,当我将 p["x"] 更改为 p[x] 时,错误消失了,因为它一开始确实是这样做的,但是当我后来尝试它时,消息又回来了,我不明白为什么)
p["x"] 是一个索引对象,如本页所述:
http://reference.wolfram.com/mathematica/tutorial/MakingDefinitionsForIndexedObjects.html
< strong>问题是:上面的代码中是什么导致了这个警告的出现?我在上面的例子中写错了什么吗?
启用动态后代码运行正常。顺便说一句,我从打开所有其他笔记本的同一个文件夹中打开此笔记本,没有任何变化,这是在家用电脑上,没有网络共享文件夹,没有任何异常。
以下是笔记本安全性的相关链接
http://reference.wolfram.com/mathematica/ tutorial/NotebookSecurity.html
我在上面没有看到任何与我正在做的事情相关的内容。我能说的就是,它与 Manipulate 中 DynamicModule[] 的使用有关,Manipulate 本身就是一个 DynamicModule。但我对此还不太了解,无法弄清楚为什么这是一个问题。
更新 1
我不明白这与路径有什么关系。我可以通过简单地注释掉内部 Dynamic 来消除错误,如下所示:
Manipulate[
(*
DynamicModule[{p},
p["x"]=0;
Row[{Dynamic[Refresh[p["x"]++;Row[{"p[x]=",p["x"]}],TrackedSymbols-> \
{n}]]}]
],
*)
n,
Button["update counter", n++],
{{n, 0}, None}
]
保存笔记本,关闭 M,启动 M,打开笔记本。错误消失了。
所以,它在代码中。
更新2
试图重现尤达在他的回答中报告的内容,但我无法做到。
- 创建新笔记本,输入
Dynamic@DateString[]
- ENTER 进行评估。
- SAVE
- 关闭 M
- 打开 M
- 打开笔记本
- 无错误
更新
于 2001 年 12 月 21 日数学组的约翰·富尔茨(John Fultz)很友善地回复了我的帖子,我认为如果我在这里发布他的答案以供其他人查看,我认为他不会介意
> > So, why is using p["x"] causing the security warning message?
That is a bug, which has already been fixed in development sources.
John Fultz
User Interface Group
Wolfram Research, Inc.
抱歉,我没有可包含到他的回复的链接,我找不到现在在谷歌上有链接。我使用雷鸟来阅读新闻组。
现在这个问题应该保持开放状态吗?还是应该关闭?如果我需要关闭它,我可以接受其中一个答案,以便将其关闭。
I am finally able to reproduce this message that I get once in a while.
This in on V8.04, on windows 7.
While trying things, I found how to make Mathematica generate the above message when I open a notebook with Manipulate in it.
First the error message screen:
I now hit 'enable dynamics' and all seems well. But each time I reopen the notebook, I get the message again. (One must close M, and start up again, and then open the notebook to see the message).
So I do not understand this warning message, and why it comes up, and what I need to change in the code to remove it.
The code to generate it is:
Manipulate[
DynamicModule[{p},
p["x"] = 0;
Row[{Dynamic[
Refresh[p["x"]++; Row[{"p[x]=", p["x"]}],
TrackedSymbols -> {n}]]}]
],
Button["update counter", n++],
{{n,0}, None}
]
The above is on its own notebook, with nothing else in the notebook.
I close M, then start it, then open the notebook, and I see the above message.
Now, I thought initially that to remove the message, I need to change p["x"] to p[x] so I closed the above notebook, and made a new notebook with this code:
Manipulate[
DynamicModule[{p},
p = 0;
Row[{Dynamic[Refresh[p++; Row[{"p=", p}], TrackedSymbols -> {n}]]}]
],
Button["update counter", n++],
{{n, 0}, None}
]
Then closed M, and started it again, and opened the above notebook,
and now I did not see the warning message. But when I repeated the process, I saw the same error come back.
(I posted this question to the Math group, but that is slow, and my post has not even shown up there, but in that post I said that the error went away when I changed p["x"] to p[x], because it actually did at first, but when I later tried it, the message came back, which I do not understand why)
p["x"] is an indexed object as explained in this page:
http://reference.wolfram.com/mathematica/tutorial/MakingDefinitionsForIndexedObjects.html
The question is: What is in the above code makes this warning to show up? Am I writing something wrong in the above example?
Code runs OK after I enable dynamics. Btw, I am opening this notebook from the same folder I open all my other notebooks, nothing changed and this is on home PC, no networks share folder and nothing out of the ordinary.
Here is the related link to notebook security
http://reference.wolfram.com/mathematica/tutorial/NotebookSecurity.html
I do not see in the above anything related to what I am doing. All what I can say, it has to do with the use of DynamicModule[] inside Manipulate, which is itself a DynamicModule. But I do not understand this well enough to figure why this is a problem.
Update 1
I do not see how this has anything to do with path. I can remove the error by simply commenting out the inner Dynamic like this:
Manipulate[
(*
DynamicModule[{p},
p["x"]=0;
Row[{Dynamic[Refresh[p["x"]++;Row[{"p[x]=",p["x"]}],TrackedSymbols-> \
{n}]]}]
],
*)
n,
Button["update counter", n++],
{{n, 0}, None}
]
Save the notebook, close M, start M, open the notebook. Error went away.
So, it is in the code.
Update 2
Trying to reproduce what Yoda reported in his answer, I am not able to.
- make new notebook, type
Dynamic@DateString[]
- ENTER to evaluate.
- SAVE
- close M
- open M
- open notebook
- no error
Update dec 21, 2001
On the Math Group, John Fultz was kind enough to reply to my post, I do not think he will mind if I post his answer here for the benefit of others to see
> > So, why is using p["x"] causing the security warning message?
That is a bug, which has already been fixed in development sources.
John Fultz
User Interface Group
Wolfram Research, Inc.
Sorry that I do not have a link to include to his reply, I could not find a link on google now. I use thunderbird to read newsgroups.
Should now this question remain open? Or should it be closed? If I need to close it, I can accept one of the answers so it is closed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这并不是因为特定的代码示例,而是因为 Mathematica 的安全功能。来自
tutorial/NotebookSecurity
,默认情况下,仅
$InstallationDirectory
、$BaseDirectory
和$UserBaseDirectory
是“受信任的”。此外,还有一组目录始终不受信任(可以更改)。这些是您的下载现在的解决方案是将当前工作目录添加到受信任文件夹列表中。
转到
首选项>高级>打开选项检查器
并在全局首选项
下开始搜索trusted
,您应该会看到弹出的三个选项。您可以在此处添加它们。This is not because of the particular code sample, but rather due to Mathematica's security features. From
tutorial/NotebookSecurity
,By default, only
$InstallationDirectory
,$BaseDirectory
, and$UserBaseDirectory
are "trusted". In addition, there are a set of directories that are always untrusted (can be changed). These are your downloadsThe solution now, is to add your current working directory to the list of trusted folders.
Go to
Preferences > Advanced > Open Options Inspector
and underGlobal Preferences
, start searching fortrusted
and you should see the three options pop up. You can add them here.这更像是尤达答案加上评论的延续,而不是单独的独立答案,但正如已经指出的,如果您从不受信任的目录打开笔记本
并且,您将在输出单元格中获得动态内容安全警告。如果您评估以下代码:您将能够确定您的笔记本是否位于受信任或不受信任的路径中(无论是否出现安全警告)。
This is more a continuation of Yoda's answer plus the comments than a separate stand alone answer but as has been stated if you open a notebook from an untrusted directory and you have Dynamic content in an Output cell you will get a security warning. If you evaluate the following code:
you will be able to satisfy yourself about whether or not your notebook is in a trusted or untrusted path (notwithstanding the appearance or not of the security warning).
假设您使用默认选项设置(即“TrustByDefault”->Automatic),您将看到三种行为之一。
如果笔记本位于“TrustedPath”中列出的目录中,则假定内容是安全的,您将永远不会看到警告。
如果笔记本位于“UntrustedPath”中列出的目录中,则内容被假定为不安全,并且您将始终看到警告。
如果笔记本所在的目录既未在“TrustedPath”中列出,也未在“UntrustedPath”中列出,您可能会看到警告,也可能不会看到警告,具体取决于笔记本中存储的 DynamicBox 表达式的内容。 Mathematica 将在尝试计算表达式之前检查该表达式。如果它仅包含“安全”表达式的简短白名单中的表达式,那么您将不会看到警告。如果它包含任何未包含在“安全”表达式白名单中的表达式,那么您将看到警告。
Assuming you are using the default option settings (i.e. "TrustByDefault"->Automatic) you will see one of three behaviors.
If the notebook is in a directory listed in the "TrustedPath" the content is assumed to be safe and you will never see the warning.
If the notebook is in a directory listed in the "UntrustedPath" the content is assumed to be unsafe and you will always see the warning.
If the notebook is in a directory that is listed in neither the "TrustedPath" nor the "UntrustedPath" you may or may not see the warning depending on the contents of the DynamicBox expression stored in the notebook. Mathematica will examine the expression before attempting to evaluate it. If it contains only expressions from a short whitelist of "safe" expressions then you will not see the warning. If it contains any expressions which are not included in the whitelist of "safe" expressions then you will see the warning.
我也遇到了笔记本电脑上出现此消息的问题,我以为以前没有出现过,但我现在确信这是因为笔记本中存在动态输出,并且动态输出在前端运行这一事实。因此,当您打开带有可见动态输出的笔记本时,FE 将尝试运行它。如果您从笔记本中删除所有动态输出,保存它,关闭它(甚至关闭并重新打开 Mathematica 以确保),然后重新打开笔记本,则不应出现该消息,因为没有动态输出。
我按照 yoda 的建议进行操作,打开选项检查器并在全局首选项中编辑 TrustedPath。我发布这个“答案”作为 yoda 答案的延续,因为我必须进行一些操作才能弄清楚如何添加到 TrustedPath 的路径。
我将文档添加为受信任路径,如下所示(在 Mac OS 10.6 上)(并且我小心地不要保存任何我不信任的内容):
您将看到
FrontEnd`FileName[{$RootDirectory},"x"]
将 x 替换为您想要信任的路径如:
FrontEnd`FileName[{$RootDirectory}, "/Users/John/Documents/"]
现在,我再也不会收到有关存储在 Documents 或其任何子文件夹中的笔记本的烦人警告。
I too had a problem with this message coming up on notebooks that I thought it hadn't come up on before, but I am now convinced it is because of Dynamic output existing in the notebook and the fact that Dynamic output runs in the front end. So when you open a notebook with Dynamic output visible the FE will try to run it. If you delete all Dynamic output from a notebook, save it, close it (and even close and reopen Mathematica to be sure) then reopen the notebook the message should not appear since there is no Dynamic output.
I did as yoda suggested, I opened the Option Inspector and edited the TrustedPath in the Global Preferences. I am posting this "answer" as a continuation of yoda's answer since I had to do some playing to figure out exactly how to add a path to TrustedPath.
I added Documents as a trusted path as follows (on Mac OS 10.6) (and I am careful not to save anything there I don't trust):
You will be presented with
FrontEnd`FileName[{$RootDirectory},"x"]
Replace x with the path that you want trusted such as:
FrontEnd`FileName[{$RootDirectory}, "/Users/John/Documents/"]
Now I never get the annoying warning for notebooks stored in Documents or any of its subfolders.