Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-04-2009, 04:31 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 17
adamscott421 is on a distinguished road
Default Security Concerns when sending request to php

I am making an app that sends an NSURLRequest to my own webserver to a php file that queries a database. The user will be allowed to insert items into the database so i obviously need a cleaning function for that. But my question is are there any other security concerns i need to worry about, for instance can i hard code my username and password when connecting to mysql?
adamscott421 is offline   Reply With Quote
Old 06-04-2009, 05:22 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by adamscott421 View Post
I am making an app that sends an NSURLRequest to my own webserver to a php file that queries a database. The user will be allowed to insert items into the database so i obviously need a cleaning function for that. But my question is are there any other security concerns i need to worry about, for instance can i hard code my username and password when connecting to mysql?
Use https if you don't want people to snoop on the contents of your request. Even then, remember that the URL is NOT encrypted, so anyone monitoring the network between the phone and your server could conceivably see the URL (NAT servers, web proxies, etc.) So be sure to put anything sensitive in a POST, not in a GET.

That done, I don't think there's any reason to put your database password in the iPhone app - it should be in the PHP, since the PHP accesses the database.

Lastly, you need to make sure that no one can construct a http query that would harm your data. Perhaps the app should request a user key (NOT easily guessable, NOT a sequential number!) from the server on first run, and include that user key in every request? Then the server should only act on requests with a valid user key. At this point, even if someone builds a custom https request, they need to guess a valid user key to affect any data.

PS - just for noobs - you should not have any SQL or real field and table names in your https request; just action names that the server will respond to. If you have "select from" or "delete from" anywhere in your request, or something like "action=set&table=hiscores&field=name" , then you're doing it wrong.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 06-04-2009, 06:09 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 17
adamscott421 is on a distinguished road
Default Just to clarify a few things

Thanks smasher that helped but just to clarify I am hard coding the username and password into the php file. Is that ok? the objective-c code basically just sends https requests and gets back json. so the vulnerabilites are really just in my php code not in my objective-c.
adamscott421 is offline   Reply With Quote
Old 06-04-2009, 08:55 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 25
eatenbyrats is on a distinguished road
Default A couple of suggestions

Sanity check all the data on the server end.

Assume all the data you get is full of injection attacks, shell escapes, and cross-scripting.

PEAR has quite a few useful classes already pre-rolled, and there are countless good references on the web on the topic. Always use a database extraction layer.

Hard coding your login into the script itself will make it hard to maintain and make it insecure:
- Every time you do a regular password change, you'll have to have a monkey edit the script.
- A simple permissions change error would be enough to expose your login information. Put that kind of information in an external file outside the web server's scope instead.

http://devzone.zend.com/tag/Security_Tips

Last edited by eatenbyrats; 06-06-2009 at 04:45 AM.
eatenbyrats is offline   Reply With Quote
Old 06-04-2009, 11:52 PM   #5 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 17
adamscott421 is on a distinguished road
Default Clarify Again

Thanks but about the user name and password. The user doesn't have one and I'm not sending anything in POST variables. I'm talking about hard coding my username and password into the mysql_connect function in the php script. Is that OK?
adamscott421 is offline   Reply With Quote
Old 06-05-2009, 12:14 AM   #6 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by adamscott421 View Post
Thanks but about the user name and password. The user doesn't have one and I'm not sending anything in POST variables. I'm talking about hard coding my username and password into the mysql_connect function in the php script. Is that OK?
Yes, that's the right thing to do - keep it on the web server. No reason to put it in the app anyway, since the app always works through the script.
__________________

Free Games!
smasher is offline   Reply With Quote
Reply

Bookmarks

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



» Advertisements
» Online Users: 341
6 members and 335 guests
givensur, ipodphone, jbro, mer10, mtl_tech_guy, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,881
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:10 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0