|
-
Apr 26th, 2004, 04:32 PM
#1
Thread Starter
<?="Moderator"?>
PHP Security
Hey does anyone know any method of making a PHP site secure. I mean though coding it and not the server setup. I have read up this topic on php.net and i was wondering if anyone here had discovered good methods of adding security to their site.
I ask this because a forum my friend set up, phpBB i think, someone used a crack or something to gain view all the users passwords. I want to be able to stop this happening though my own coding.
Thanks
-
Apr 27th, 2004, 11:43 AM
#2
It's always a combination of server settings (or rather, php.ini settings) and coding.
First, disable register_globals.
Next, get rid of all evals. Not that eval itself is very evil (pun NOT intended), but it's rarely necessary and poses a security risk if some user input sneaks into the eval'ed string.
Next, be sure to check every bit of user input very carefully. Where does it go, what's done with it? Letting user input into SQL queries for example is asking for trouble. Writing it out as it is is too, that's the "sneak JavaScript into a page and fool users to reveal details" trick that was used against some online banking site.
User input always comes through the variables $_GET, $_POST, $_COOKIES and sometimes $_REQUEST. Then there's $_FILES where uploaded files are stored and another thing which stores the input in a PUT request.
Hmm, that's all I can think of for now. Others might add things.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 27th, 2004, 12:00 PM
#3
Ex-Super Mod'rater
What if you dont have the ability to turn register_globals off . I haven't ask my host to yet but I would expect them not to considering how many other users are on the same server.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Apr 27th, 2004, 12:21 PM
#4
Then unset every global variable you're going to use before using it.
unset($config);
$config = ...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 27th, 2004, 02:02 PM
#5
Ex-Super Mod'rater
Originally posted by CornedBee
Then unset every global variable you're going to use before using it.
unset($config);
$config = ...
Ow well I always initialise the variables before I use them anyway , treat it a bit like C++ . What was that about eval anyway?
As for for letting user input be used in SQL satements isn't it safe to use the AddSlashes() function before putting it in? Not to mention limiting the username being used by php files to the bare minimum they need. For example php scripts will rarly need to create tables, some will only need to ever use Select & Update.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Apr 27th, 2004, 02:15 PM
#6
addslashes should keep you safe, but I'm not a specialist there.
eval executes the string you pass as PHP, so it's generally a VERY bad idea to give the user even the faintest chance of modifying this string.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 27th, 2004, 02:23 PM
#7
Thread Starter
<?="Moderator"?>
Cheers for all the feedback.
CornedBee: is there a way to check to see if global vars are set on at the beggining of the code?
[EDIT]
Sorry stupid question
PHP Code:
print ini_get('register_globals');
[/EDIT]
Last edited by john tindell; Apr 27th, 2004 at 02:31 PM.
-
May 24th, 2004, 07:37 AM
#8
Junior Member
Actually CornedBee, any data that is in a $_GET, $_POST or $_COOKIE array will also be in the $_REQUEST-array, since $_REQUEST is just a gathering of the $_GET, $_POST and $_COOKIE arrays into one (and I think $_FILES too, more details on www.php.net)
Two valuable tips for more secure PHP coding, aside from what's already been mentioned (read on www.php.net for function specifics):
* Never trust input. If it's not defined by you, consider it to be harmful and take action to prevent the input to destroy the script.
If you're sending a variable into an SQL query, double, triple and quadrouple-check it for any harmful contents before you send it in the query.
* Always use the extension .php instead of .inc (or .tpl) when you are including files, because this will prevent people from accessing the contents of that file. If someone enters the address for an .inc-file, the webserver will print this out as plain text, very bad if you're storing sensitive information like database passwords in an included file. If they enter the address for a .php file, the file will be executed and nothing will happen.
If there is a way to solve your problems, there is no need to worry; if there is no way to solve your problems, there is no point to worry.
-
May 24th, 2004, 10:47 AM
#9
Actually CornedBee, any data that is in a $_GET, $_POST or $_COOKIE array will also be in the $_REQUEST-array
With "sometimes" I was referring to the low frequency of $_REQUEST being used.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 25th, 2004, 01:16 AM
#10
Junior Member
If there is a way to solve your problems, there is no need to worry; if there is no way to solve your problems, there is no point to worry.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|