0
我有一个网站,其中所有的页面都通过index.php处理,其中包含取决于请求的URL(这通过mod_rewrite完成)的不同PHP文件。JS中的函数动态评估(这是安全的吗?)
我用下面的方法,在页面加载到执行特定的功能:
的index.php
<script type="text/javascript">
readyFns = Array();
</script>
<?php
// Do some stuff here, and pull the name of the PHP page to include from the DB
include $pageToInclude
?>
<script type="text/javascript">
commonFunctionToApplyToAllThePages();
otherCommonFunction();
// page-specific functions
for (i=0; i<readyFns.length; i++)
{
if (typeof(window[readyFns[i]]) == "function")
window[readyFns[i]]();
}
</script>
includedPage.php
<?php
// Generate page
?>
<script type="text/javascript">
readyFns.push("someFunction");
readyFns.push("someOtherFunction");
</script>
我很喜欢这种方法,因为我只需要在这个页面的末尾设置readyFns和所有的东西否则将被index.php
很好地控制。 我的问题是:这是安全的吗?它可能对某个人产生链接的敏感,该链接任意设置readyFns
指向一些恶意代码,然后链接到我的网站? 我会如何预防?
感谢 尼科
感谢您的回答,但不会只是移动问题?我的意思是,可以在'functs'中定义一个恶意函数,而不是主范围,否?或者我错过了什么? – nico 2010-07-20 21:58:12
这在技术上是可行的,但它不值得担心。我把它从窗口移出来,所以你不能像'setTimeout'或'alert'那样访问内建插件。 – bcherry 2010-07-22 22:06:52