Go Back   kirupaForum > Development > Client-Side (HTML, CSS, JavaScript)

Reply
 
Thread Tools Display Modes
Old 11-28-2009, 01:22 PM   #1
arundracula
Registered User
 
arundracula's Avatar
SQL type injection in JS??

You might know what SQL injection in PHP mysql queries..

Closing the mysql query manually and deleting the table..

Adding extra parameters to make the query always true and logging in..

This was in earlier PHP, however we can avoid these by magic_quotes...

My question is that Will this trick work in a javascript function which accept a variable? If yes how to avoid it?

For eg:
Code:
function testFunction(variable){
 //doSomething with variable
}
In the above code we can run the function from location bar by typing javascript:testFunction(var);

If the var is typed in as in the SQL injection method(manually closing the function parenthesis and writing a code to create a file in the server...), will it make any problem?
arundracula is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-28-2009, 02:33 PM   #2
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
The generally accepted mindset is to ignore security in client-side scripts (JS), and implement it entirely in server-side scripts (e.g. PHP). This is because the user is able to interface with your server in any which way they like.

For example, making sure that your form meets the requirements you have set by testing them with a JavaScript script it useless, because the user can just write their own form and submit it to your server. Alternatively, instead of writing their own form, they could load up your page and execute any arbitrary JavaScript code they like.

Quite simply, the user is able to alter anything you write in JavaScript. This is not the case server-side and thus we implement security features. You need only worry about your client-side scripts working.

With that said, there are certain inputs that might break your script depending on what you are doing with said input. For example, if you are putting the string through an `eval` call then the user might inject some code. Similarly if you are generating URLs the user might provide unexpected content to alter the URL in an undesirable way.

This is why we have the escape functions `escape`, `encodeURI` and `encodeURIComponent`.

Hope that helps
icio is offline   Reply With Quote
Old 11-29-2009, 12:46 PM   #3
arundracula
Registered User
 
arundracula's Avatar
Ya.. It surely helped...
Now my thoughts are like this...
Make a basic working of the client side for normal users...

Check and validate all incomings to Server...

And I do beleive in NOT TRUSTING THE USER.. whether he may a hacker or a "mis-typed" ones
arundracula is offline   Reply With Quote
Old 11-29-2009, 12:47 PM   #4
icio
looks better in lowercase
 
icio's Avatar
Location Edinburgh, Scotland

Posts 3,689
Good Glad it helped.
icio is offline   Reply With Quote
Old 12-01-2009, 06:48 PM   #5
jwilliam
Call me Rooster Cogburn.
I'd also suggest reading the wikipedia entry on cross-site scripting attacks. Depending on what you're allowing users to do on your website, this could be a possible threat too.
jwilliam is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:29 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com