开发者

PHP: Is it secure to use index.php as the bootstrap?

开发者 https://www.devze.com 2023-01-14 09:20 出处:网络
I ask because it seems like the only thing ever called in a proper app index.php file is the require_once bootstrap file. I\'m assuming t开发者_开发问答his adds a layer of security but if not, this pa

I ask because it seems like the only thing ever called in a proper app index.php file is the require_once bootstrap file. I'm assuming t开发者_开发问答his adds a layer of security but if not, this pattern seems pointless. Why not just use the index.php file as the bootstrap? Any opinions, cautions, thoughts etc. are appreciated!

(By the way, my htaccess file is routing all requests to the index.php file...)


There is no inherent security difference, no matter whether you have your bootstrapoing process in the index file or a separate one.

Having a separate file is usually due to organization concerns (e.g. to have a file that can be included from elsewhere to import your app's functions, or to put all the tasks in properly named files, or to make it especially easy to add custom extensions to the boot process).

However, configuration files containing sensitive information - sometimes, more rarely, even all PHP files at all except for the index file - will be placed outside the web root where possible. That will make a security difference in that PHP files can not be accessed from outside in case of an accidental server misconfiguration.


in a secure enviroment only the index.php lies in the document root, all other PHP files should be outside document root, so it makes sense when the index.php file is only including a Bootstrap file outside the document root.


I don't know of any vulnerability that this exposes. Dropping a blank index.html or index.php into a folder can prevent an attacker from obtaining a directory listing if apache is misconfigured.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号