views:

49

answers:

3

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 this 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...)

A: 

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.

Rook
+2  A: 

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.

Pekka
Thanks for the response Pekka. If the index requires an outside bootstrap and there's an accidental server misconfiguration, does that security problem still apply?
shanebo
@shanebo no, if there is a misconfiguration in how PHP files are parsed, the bootstrap won't be fetched in the first place (And can't be accessed from the web root).
Pekka
+1  A: 

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.

Rufinus