Web 服务器上的 Unix 高级文件权限
我有 3 个包含 PHP 脚本的文件夹:
- core
- custom_modules_1 (cm1)
- custom_modules_2 (cm2)
核心由 Apache 执行,并包含来自 cm1 或 cm2 的 (require_once) 文件。它从不包括 cm1 和 cm1 cm2 同时。
但是当 cm1 包含 cm2 中的文件时就会出现问题,这是应该避免的,但是如何呢?
我正在使用 cPanel 运行 VPS CentOS 服务器,因此 ACL 可能不是一个选项,因为它可能会破坏 cPanel。
I've got 3 folders that contain PHP scripts:
- core
- custom_modules_1 (cm1)
- custom_modules_2 (cm2)
The core is executed by Apache and includes (require_once) files from either cm1 or cm2. It never includes cm1 & cm2 at the same time.
But the problem occurs when cm1 includes a file from cm2, which should be prevented, but how?
I'm running a VPS CentOS server with cPanel, so ACL is probably not an option since it could break cPanel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不能通过权限来解决。您需要向每个脚本添加哨兵代码以防止交叉包含。
This cannot be solved with permissions. You will need to add sentinel code to each script in order to prevent cross-inclusion.
有多种方法可以解决此问题,具体取决于您的具体要求的详细信息(帖子中不清楚)。
根据脚本的来源位置使用不同的包含路径(将 custom_modules_1 或 custom_modules_1 作为路径的一部分)
使用 open_basedir 限制对特定目录的访问
对不同文件集使用不同的所有权并使用 suphp 强制执行访问权限
There are a number of ways to solve this depending on the details of your exact requirements (not clear from post).
use different include paths for scripts depending on where they will source the modules from (with custom_modules_1 or custom_modules_1 as part of the path)
use open_basedir to restrict access to specific directories
use different ownership on the different filesets and enforce access permissions using suphp
感谢您的回答,但我设法强制执行所需限制的唯一方法是使用 php auto_prepend_file 附加一个文件,该文件在包含的每个 php 文件中进行某些检查。
Thank you for your answers, but the only way I've managed to force the wanted restrictions was using php auto_prepend_file to append a file that does certain checks inside every php file that is included.