普通网友 2014-04-17 10:20
浏览 53

使用PHP eval合成动态类时有哪些风险?

I was reading : When (if ever) is eval NOT evil? and a few others guides on the net when to use eval and when not. None of this posts could really answer my question about security concerns in regard of dynamic class compositing at run-time.

Background : As we can't use PHP 5.4 traits to properly mixin in classes into each other, we needed another solution to get dynamic mixins. So we found this particular class on on Github : https://github.com/wellspringworldwide/PHP-ClassMixer/blob/master/ClassMixer.php which does exactly what we want.

I am not really an expert to evaluate such code in regard of potential security risks but maybe somebody on Stackoverflow knows what the risks are of such methods.

As far I understood, the base for security concerns with this method of using eval for class composition are only given when

  1. The class to be mixed into another class is accessible and modifiable from outside, for instance file or RPC access
  2. A user can gain access to the running context, ie, the surrounding code loads plugin code
  3. A user gains access to the applications working memory and alters data there.

None of these circumstances are given in our application but I am not sure there are other conditions we need to think about when using eval that way !?

thank you.

  • 写回答

1条回答

  • duandu8202 2014-04-17 12:08
    关注

    Eval basically is bad because it's eval() :D

    No seriously:

    You should NEVER compose some source and throw it into eval. As soon as your script composing the source has any dependent data sources like a DB backend, the file system reading (especially text-)files or (even worse) some form data there's always the chance of invasive and damaging code being injected. (e.g. ;exec('rm -rf /');)

    Using the Decorator Pattern might help you out. Please read this and that as a primer to understanding the Decorator Pattern.

    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。