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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 04-10-2009, 08:47 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
Default Preventing PHP scripts used in a iPhone app from being accessed via web browser

Hi All,
I've hit a security hole in my app that I can not get out off.

Basically, I am using this method to pass parameters to a php script which returns values from a server:

Code:
NSString *urlstr = [[NSString alloc] initWithFormat:@"http://www.yourserver.com/yourphp.php?param=%d", paramVal];
NSURL *url = [[NSURL alloc] initWithString:urlstr];
NSString *ans = [NSString stringWithContentsOfURL:url];
// here in ans you'll have what the PHP side returned. Do whatever you want
[urlstr release];
[url release];
I then pose the question. How do you secure 'http://www.yourserver.com/yourphp.php' ? You can easily navigate to the same script (if you know the path) and pass in any parameters that you want. Am I missing something?

I'm totally a beginner here so go easy on me! Any code snippets or suggestions that can be thrown my way would be greatly appreciated. Thanks!

Last edited by blamethatkid; 04-10-2009 at 08:54 PM.
blamethatkid is offline   Reply With Quote
Old 04-10-2009, 09:07 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 62
Default

I suppose you could detect the client on the php side and not do anything unless it's an iphone. I'm not sure what the the iphone looks like as a client thought.
lymeric is offline   Reply With Quote
Old 04-10-2009, 09:29 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
Default

Quote:
Originally Posted by lymeric View Post
I suppose you could detect the client on the php side and not do anything unless it's an iphone. I'm not sure what the the iphone looks like as a client thought.
yeah I guess the only problem there is that the client can be spoofed.
blamethatkid is offline   Reply With Quote
Old 04-10-2009, 09:37 PM   #4 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 49
Default

Quote:
Originally Posted by blamethatkid View Post
I'm totally a beginner here so go easy on me! Any code snippets or suggestions that can be thrown my way would be greatly appreciated. Thanks!
You can't protect yourself against this purely on the server side. A client can be faked very easily so just checking what device type the callee uses is not enough. Here are some possible solutions:

Let the user provide a username and password
Encrypt the data to a from the server
Use a computed 'checksum' that the device must send with the user

The first two is the best and ortodox solutions, the third is a bit easier to implement.

Let's say the client sends three data to the server: a, b and c. Then add an extra parameter: d.
Calculate d in a way only you now, like d = 543*b/a-c, then the server easily can validate that the data is from your application.

Good keyword to search for in programming forums: "checksum", "MD5" and "CRC32"
Joche is offline   Reply With Quote
Old 04-10-2009, 09:42 PM   #5 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 2
Default

Use authentication system, an email + a password.
Milad is offline   Reply With Quote
Old 04-10-2009, 09:49 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
Default

Quote:
Originally Posted by Milad View Post
Use authentication system, an email + a password.
my app doesn't work on a user name + password system.
The app just calls a script that populates a table on my app. Users are asked to put in their email at some point when they make an entry on the table.
The main problem is that someone clever could figure out the script being called and recall all the email addresses stored on the server. setting up a username + password system is not conducive to the way the app would work because the users will never have to recall their entry.
blamethatkid is offline   Reply With Quote
Old 04-10-2009, 11:08 PM   #7 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 2
Default

Unless the SDK supports the use of client certificates when accessing URLs then your best bet would be to follow Joche's advice and implement a non trivial checksum value in addition to maybe encoding the values client side before passing them to the PHP script (which would obviously decode + verify checksum value)

vortfu
vortfu is offline   Reply With Quote
Old 04-10-2009, 11:47 PM   #8 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 4
Default possible solution

the iPhone App iMobsters uses a user Id and phone Id passed somehow. You might want to look into how they are doing it. If you try and access it via Safari, even spoofed as an iPhone, it won't work. Here's an example:

Have Safari act as an iPhone and as normal:

http://imobstersapp.com/equipment.ph...y&iid=51&cat=2


Quote:
Originally Posted by blamethatkid View Post
Hi All,
I've hit a security hole in my app that I can not get out off.

Basically, I am using this method to pass parameters to a php script which returns values from a server:

Code:
NSString *urlstr = [[NSString alloc] initWithFormat:@"http://www.yourserver.com/yourphp.php?param=%d", paramVal];
NSURL *url = [[NSURL alloc] initWithString:urlstr];
NSString *ans = [NSString stringWithContentsOfURL:url];
// here in ans you'll have what the PHP side returned. Do whatever you want
[urlstr release];
[url release];
I then pose the question. How do you secure 'http://www.yourserver.com/yourphp.php' ? You can easily navigate to the same script (if you know the path) and pass in any parameters that you want. Am I missing something?

I'm totally a beginner here so go easy on me! Any code snippets or suggestions that can be thrown my way would be greatly appreciated. Thanks!
auprogrammer is offline   Reply With Quote
Old 04-11-2009, 12:42 AM   #9 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: San Diego, CA
Posts: 406
Default

Quote:
The app just calls a script that populates a table on my app. Users are asked to put in their email at some point when they make an entry on the table.

The main problem is that someone clever could figure out the script being called and recall all the email addresses stored on the server.
It wouldn't even take somebody clever.

This isn't an "iPhone" problem, and you're on the wrong forum. You need to learn PHP 101, and go to a PHP forum.

But, then again, it isn't even a PHP problem. It's a basic web services security issue, that transcends any given language or platform. You need to learn about HTTP authentication and SSL. (There are other approaches, but it would take a good understanding of computer security.) You don't need code snippets. You first need to understand some of the basics of computer security, authentication and encryption. And before you even look into that, you need to get a basic understanding of the societal and legal issues. You at least seem to have an inkling about that, as you do seem troubled by your current approach.

Your security is no security, and asking people to store their email addresses in such an insecure manner is just plain irresponsible. I hope your app has not yet been released.

I'll give one more bit of advice - you've mis-stated your problem. It is NOT "preventing somebody from accessing the data from a web browser". It's "preventing unauthorized access to the data". I hope that's helpful, because before you can solve the problem, first you need to understand just what the problem is.

Perhaps you should channel your efforts initially into an app that has less potential for damage. Sorry for ripping you a new one for being a newbie - but there are some thing that newbies probably shouldn't be dabbling in just yet.

Last edited by jtara; 04-11-2009 at 12:47 AM.
jtara is offline   Reply With Quote
Old 04-11-2009, 12:47 AM   #10 (permalink)
New Member
 
Join Date: Mar 2009
Location: Silicon Valley, CA
Posts: 135
Default

Quote:
Originally Posted by jtara View Post
It wouldn't even take somebody clever.

This isn't an "iPhone" problem, and you're on the wrong forum. You need to learn PHP 101, and go to a PHP forum.

But, then again, it isn't even a PHP problem. It's a basic web services security issue, that transcends any given language or platform. You need to learn about HTTP authentication and SSL. (There are other approaches, but it would take a good understanding of computer security.) You don't need code snippets. You first need to understand some of the basics of computer security, authentication and encryption. And before you even look into that, you need to get a basic understanding of the societal and legal issues. You at least seem to have an inkling about that, as you do seem troubled by your current approach.

Your security is no security, and asking people to store their email addresses in such an insecure manner is just plain irresponsible. I hope your app has not yet been released.

Perhaps you should channel your efforts initially into an app that has less potential for damage.
Wow dude did they run out of your flavor coffee at the neighborhood Starbucks this evening?

Dave (nominates this for "Rant of the Year 2009" )
AEDave is offline   Reply With Quote
Old 04-11-2009, 10:33 AM   #11 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 49
Default

Quote:
Originally Posted by AEDave View Post
Wow dude did they run out of your flavor coffee at the neighborhood Starbucks this evening?

Dave (nominates this for "Rant of the Year 2009" )
*LOL*
Joche is offline   Reply With Quote
Old 04-11-2009, 10:51 AM   #12 (permalink)
Tutorial Author
 
Join Date: Jan 2009
Posts: 144
Default

Quote:
Originally Posted by Joche View Post
*LOL*
i lol'd.

But i also did learn a lot from this topic. Php ftw.
meowmix23F is offline   Reply With Quote
Old 04-11-2009, 11:23 AM   #13 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: San Diego, CA
Posts: 406
Default

My first thought when I read the title was "What? They're running PHP on the iPhone now??

As bad an idea s that sounds, if it hasn't been done yet, it will be. And it might actually make sense for some class of apps.

In this particular case, it would solve the security problem.
jtara is offline   Reply With Quote
Old 04-11-2009, 11:38 AM   #14 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 2
Default

PHP can be run on iPhone if you jailbreak yours, it's available in the jail breaking community.
Milad is offline   Reply With Quote
Old 04-11-2009, 11:58 AM   #15 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 10
Default

Quote:
Originally Posted by jtara View Post
It wouldn't even take somebody clever.

This isn't an "iPhone" problem, and you're on the wrong forum. You need to learn PHP 101, and go to a PHP forum.

But, then again, it isn't even a PHP problem. It's a basic web services security issue, that transcends any given language or platform. You need to learn about HTTP authentication and SSL. (There are other approaches, but it would take a good understanding of computer security.) You don't need code snippets. You first need to understand some of the basics of computer security, authentication and encryption. And before you even look into that, you need to get a basic understanding of the societal and legal issues. You at least seem to have an inkling about that, as you do seem troubled by your current approach.

Your security is no security, and asking people to store their email addresses in such an insecure manner is just plain irresponsible. I hope your app has not yet been released.

I'll give one more bit of advice - you've mis-stated your problem. It is NOT "preventing somebody from accessing the data from a web browser". It's "preventing unauthorized access to the data". I hope that's helpful, because before you can solve the problem, first you need to understand just what the problem is.

Perhaps you should channel your efforts initially into an app that has less potential for damage. Sorry for ripping you a new one for being a newbie - but there are some thing that newbies probably shouldn't be dabbling in just yet.
Thanks for helping me ask the right questions.

Last edited by blamethatkid; 07-17-2010 at 07:37 PM.
blamethatkid is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone app, mysql, nsurl, php

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: 255
19 members and 236 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, Desert Diva, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, ryantcb, Speed, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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