PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 14th, 2005, 06:39 AM
n000b n000b is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Location: Melbourne, Australia
Posts: 595 n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 12 h 45 m 42 sec
Reputation Power: 9
Send a message via ICQ to n000b
Security in PHP

Hey guys,

Can you please help me out by listing some security things that I would have to watch out for when making a website in PHP, and possible methods to fix/stop the problem.

For example, I know about SQL injection, and to stop that I just had to make sure I add slashes to all entries to a DB.

What other security issues are there, and how do I stop/fix them?

Reply With Quote
  #2  
Old February 14th, 2005, 06:58 AM
MacMyDay MacMyDay is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Suffolk, England
Posts: 434 MacMyDay User rank is Corporal (100 - 500 Reputation Level)MacMyDay User rank is Corporal (100 - 500 Reputation Level)MacMyDay User rank is Corporal (100 - 500 Reputation Level)MacMyDay User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 7 h 52 m 2 sec
Reputation Power: 9
All data input.

Rule #1 of all programming: never trust the user. Like in Million Dollar Baby: always protect yourself. Keep repeating it to yourself until you realise this.

Limit everything by allowing only what they should be entering. So, if you have a simple box that allows them to insert a date, then perform simple checks using regex to make sure it's the date. Having said such, it may not have a devistating effect on many things, but it does mean it's one less problem.

Also, always make sure on every page you're checking the user's info to see whether they can access the page. The security thread has more info on the subject.
__________________
Suffolk Website Designers

Reply With Quote
  #3  
Old February 14th, 2005, 09:17 AM
J_Tree's Avatar
J_Tree J_Tree is offline
Rocking my php-ness
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Boston, MA
Posts: 1,968 J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 15 h 20 m 37 sec
Reputation Power: 146
Send a message via ICQ to J_Tree Send a message via AIM to J_Tree Send a message via MSN to J_Tree Send a message via Yahoo to J_Tree
I like to try to stay away from text input as well. It's a lot easier to 'clean' form input from a select, checkbox, etc then it is to clean a text field.

It isn't always possible, but the harder you make it for users to enter incorrect data the easier it will be to secure your web app.

Reply With Quote
  #4  
Old February 14th, 2005, 09:51 AM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Kentucky
Posts: 14,445 Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)Sepodati User rank is General 31st Grade (Above 100000 Reputation Level)  Folding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced FolderFolding Points: 97169 Folding Title: Advanced Folder
Time spent in forums: 3 Months 2 Days 19 h 29 m 33 sec
Reputation Power: 3067
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
Every input is a text box when it comes down to it. Even though your form may use selects and check/radio buttons, it doesn't mean a malicious user has to use your form.

There are many many issues to be concerned about. Read the Security thread at the top of this forum. You'll get a lot of good ideas out of there. Other than that, search the web. Chris Shiflett writes a lot of good articles on PHP/web security. Read some of the stuff he's written and you'll be ahead of a lot of others.

---John Holmes...
Comments on this post
SimonGreenhill agrees!

Reply With Quote
  #5  
Old February 14th, 2005, 10:46 AM
J_Tree's Avatar
J_Tree J_Tree is offline
Rocking my php-ness
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Boston, MA
Posts: 1,968 J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level)J_Tree User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 15 h 20 m 37 sec
Reputation Power: 146
Send a message via ICQ to J_Tree Send a message via AIM to J_Tree Send a message via MSN to J_Tree Send a message via Yahoo to J_Tree
Quote:
Originally Posted by Sepodati
Every input is a text box when it comes down to it. Even though your form may use selects and check/radio buttons, it doesn't mean a malicious user has to use your form.


Absolutely correct sir, but at least with the other types of input you know the exact form data you should be looking for as well as the method.

Reply With Quote
  #6  
Old February 14th, 2005, 04:32 PM
SimonGreenhill's Avatar
SimonGreenhill SimonGreenhill is offline
(retired)
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Dec 2003
Location: The Laboratory
Posts: 10,101 SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 4925 Folding Title: Novice Folder
Time spent in forums: 3 Months 3 Weeks 6 h 6 m 31 sec
Reputation Power: 0
Facebook
There are also a lot of good articles at phpsec.org, I highly recommend Chris Shiflett's PHP Security Workbook here.

Reply With Quote
  #7  
Old February 14th, 2005, 08:56 PM
qcimushroom qcimushroom is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 16 qcimushroom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 57 m 59 sec
Reputation Power: 0
Quote:
Originally Posted by MacMyDay
All data input.

Rule #1 of all programming: never trust the user.

Valiate all user input some how.
If you are expecting a number back use " settype($var,"integer"); " where $var is the name of your variable to force it to be a number.

Reply With Quote
  #8  
Old February 14th, 2005, 09:05 PM
SimonGreenhill's Avatar
SimonGreenhill SimonGreenhill is offline
(retired)
Dev Shed God 11th Plane (10000 - 10499 posts)
 
Join Date: Dec 2003
Location: The Laboratory
Posts: 10,101 SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)SimonGreenhill User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 4925 Folding Title: Novice Folder
Time spent in forums: 3 Months 3 Weeks 6 h 6 m 31 sec
Reputation Power: 0
Facebook
or just use a cast:

$var = (int) $var;

You can also use things like is_num(), is_int(), is_bool() etc to test if a variable is a certain type.

Reply With Quote
  #9  
Old February 14th, 2005, 09:22 PM
-Si- -Si- is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 71 -Si- User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 22 m 58 sec
Reputation Power: 6
Quote:
Originally Posted by n000b
Hey guys,

Can you please help me out by listing some security things that I would have to watch out for when making a website in PHP, and possible methods to fix/stop the problem.

For example, I know about SQL injection, and to stop that I just had to make sure I add slashes to all entries to a DB.

What other security issues are there, and how do I stop/fix them?


You should read the sticky. There's some useful information in there. If it's not mentioned in there, you should read the PHP Manual's section on Security, it covers SQL injection, and then there's just stuff like never outputting user input variables without validating them first.

Reply With Quote
  #10  
Old February 15th, 2005, 01:12 AM
n000b n000b is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Location: Melbourne, Australia
Posts: 595 n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 12 h 45 m 42 sec
Reputation Power: 9
Send a message via ICQ to n000b
Thanks guys, I'll do what you all suggested

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Security in PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
Stay green...Green IT