TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-29-2009, 03:29 AM   #1 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 429
Thanks: 30
knight13 is on a distinguished road
Default xss security

I have been reading about cross site scripting, and basically everything i have read say's that xss is basically people putting javascript code in form inputs, and to protect against it a person should use htmlentitties to filter things going into a database.

What i want to know is if this is the only way xss is used and can i prevent it from happening just by using htmlentitties to filter all the data that gets put into my databases?
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Old 06-29-2009, 05:06 AM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,211
Thanks: 17
Village Idiot is on a distinguished road
Default

XSS - like most javascript tricks - are merely fancy layers behind the conventional means. The only way to get to your server is VIA HTTP (or other basic methods), the data can be forged just as easily without XSS tricks. Just secure your database inputs and validate your info. It (like most javascript tricks) are hype in front of conventional method, but many don't understand how they actually work so they feel it is a new thing. I will admit the interfaces are new, but the technology is not.

If you use PHP, use mysql_real_escape_string and typecast your ints. If you use a language that supports SQL paramaters (does MySQL do those) use them, they ar inheritally immune.
Village Idiot is offline  
Reply With Quote
Old 06-29-2009, 09:17 AM   #3 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,238
Thanks: 3
Salathe is on a distinguished road
Default

I'm not really sure where VI is coming from with regards to his labeling cross-site scripting as "hype" or to what he refers to as "conventional methods" (unless you just mean DHTML). To slide in with talking about SQL injection further blurs things.

Back to XSS, htmlspecialchars isn't necessarily the saviour that you may think it is. One can still inject scripting without using any (of the 5) characters affected by htmlspecialchars, and an injected script can (depending on the situation) sometimes still work even if characters have been pushed through htmlspecialchars.
__________________
salathe@php.net
Salathe is offline  
Reply With Quote
Old 06-29-2009, 09:48 AM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 832
Thanks: 31
sketchMedia is on a distinguished road
Default

This is a useful resource:
http://ha.ckers.org/xss.html

Quote:
htmlspecialchars isn't necessarily the saviour that you may think it is
Agreed, you would be surprised how easy (relatively) it is to bypass it (especially given that many people use broken browsers).

Essentially XSS is when the attacker is able to inject a script into a page, and have it run from that domain. This has many possibilities but the main form of attack is cookie theft (i think ?), which can be very damaging.

One way to approach this is to create a white list of tags, and strip out the ones not on the white list, however this is still not fool-proof.

There are a number of lib's for PHP that claim to help escape your output, one being http://htmlpurifier.org/, you might be able to use PHP's Tidy extension also.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 06-29-2009, 03:26 PM   #5 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 258
Thanks: 7
CoryMathews is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
XSS - like most JavaScript tricks
XSS is not only a JavaScript hack, it is for any server-side language as well.

It is simply when someone inputs information into a form of some kind and the information is then shown again to the user without removing anything.

Basically if you have say a search form. And in that form I "search" for

Code:
Something <a href="example.com/yourscrewed.php">View all results</a>
Now I pass the url of these results to a user and they click on the link. Bingo XSS attack. If you get that on a trusted site, people are likely to click it. Of course there are also all sorts of other ways, such as forms ect..

To prevent it just don't display what they typed in. Simple as that.
CoryMathews is offline  
Reply With Quote
Old 06-29-2009, 09:15 PM   #6 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 429
Thanks: 30
knight13 is on a distinguished road
Default

What do i do if i want to allow people to be able to put links and html and image codes into certain parts of the website, how would i protect the site from xss but still let them add their codes.
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Old 06-30-2009, 03:22 PM   #7 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 258
Thanks: 7
CoryMathews is on a distinguished road
Default

You can strip out all tags, with the exception of the ones that you want. http://us3.php.net/manual/en/function.strip-tags.php

Also check out http://www.acunetix.com/websitesecur...security-1.htm they have some great info on security for php. Also they have a scanner (link at bottom of page) which will scan your site for xss vulnerabilities. (xss is the free part)
CoryMathews is offline  
Reply With Quote
Old 06-30-2009, 06:51 PM   #8 (permalink)
The Frequenter
 
knight13's Avatar
 
Join Date: Jun 2009
Location: Cleveland,Ohio
Posts: 429
Thanks: 30
knight13 is on a distinguished road
Default

Thanks CM i will check that site out, and thanks for the info.
__________________
Anyone who has never made a mistake has never tried anything new.
~ Albert Einstein ~
knight13 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
html form field security? knight13 General 11 06-26-2009 07:50 PM
Several Questions - Security and Performance Killswitch General 0 12-09-2008 03:10 AM
Security Article / Tutorial on PHPFreaks.com drewbee General 0 07-03-2008 05:36 PM
security section (xss,injection,etc) sarmenhb Feedback 2 01-29-2008 08:06 PM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM


All times are GMT. The time now is 05:32 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design