views:

38

answers:

3

I have a flash application (a game) and it needs to pass data to a php page to save the user, and the user's score. However I don't want the user to be able to alter the score him/herself or to initial a scoring without using the application.

What is the best way to do this?

+1  A: 

Implement a md5-hash function and hash the score and the username.

Then load a PHP-file from Flash with score, username and md5-hash as GET-parameters. The PHP-file checks the data by hashing the values again.

Since Flash runs in the browser it can be recompiled so you cannot be 100% sure. If you want to get sure completely you have to validate each step the user does with the server.

Flexx
but they can make an md5 hash of their name and desired score by themselves and replace the post/get values with it.
Malfist
to prevent this just use a so called "salt" which is a secret string you can put at the beginning of each string you want to hash. The users don't know the string and cannot create a hash on their own.http://en.wikipedia.org/wiki/Salt_(cryptography)
Flexx
MD5 is one way.
webbiedave
But that means I have to have a static salt, once they find out the salt, or generate a rainbow table, they can do whatever they want. Using a salt in this scenario is security by obscurity, which is highly discouraged. If you want to pass the salt along with the post/get, meaning use a dynamic salt, the user would be able to fake it with his/her own salt.
Malfist
@webbiedave, You can send them plaintext, and a hash to guarantee integrity.
Malfist
A: 

You have two services. One service is the game service. The other service is the scoring service. You need to set up some kind of authentication around your scoring service. Your game service then needs some set of credentials to access this authentication.

One approach would be to surround your score service with https and require an https token to access it. Your game service could then have that token hard coded into the server-side code of the game itself.

Pace
once they have the token, they can submit scores by themselves. Or manipulate the post/get values.
Malfist
The user never gets or sees the token. The traffic flows as follows... GameClient<UserHost> --> GameService<GameHost> --> ScoreService<GameHost>. The (GameService --> ScoreService) connection is on your private network and so all traffic on that path is hidden from the user. There is no reason to bring the token to the UserHost. The token can be dynamic, changing however often you want so even if they crack it they'll be lost after the next rollover.
Pace
+2  A: 

If the client (i.e. flash) is keeping track of/generating the score, there is no secure way for you to send the score to the server. Whatever the swf file can do, an attacker can also imitate.

The only secure way is to send each user move or action to the server. The server is responsible for the state of the game and maintaining the score; the client just generates the moves.

With such an approach, an attacker cannot manipulate the score. He can still bypass your SWF file, but to get a high score he still has to make the right moves. The attacker can make a bot to make the moves intelligently; to avoid that you can only use security by obscurity.

sri
I suppose, at some point, there's always a way to cheat.
Malfist