Sensitive information should never depend on client-side¹ because Javascript encryption is useless.
The transparency offered by current browsers makes all your code and information readable and alterable in a few clicks. This does not mean that older browsers made the web safer. On the contrary, it was formerly easier for a developer to believe that his application was safe when using any kind of complication like Javascript encryption, compiled application (Flex/Actionscript), among others.
CSRF tokens can help you prevent someone from forging a call to your server from another source (Curl, CORS, etc.), but they will not guarantee that the other information being trafficked is intact as expected.
You can use a combination of CSRF and SSL/TLS to encrypt the connection between client and server, avoiding possible tampering with javascript files and ensuring that the response came from your application, but still doesn’t justify relying on the client-side provide sensitive information.
Updating
Responding to the comment, any security mechanism you can think of using Javascript in browsers has been thought of before, it is not a lack of idea, but rather the mechanics of how Javascript works in the browser. Even if you create a public key from the server for the client to use this key and you ensure that the information has been encrypted using a valid key, the end user still has the information before and afterward to encrypt it. The same facility to forge data that does not represent reality with and without such a mechanism is the same, as the customer will only tamper with the information before it is encrypted.
If you are depending on your secure information client, you need to rethink your application.
- What action does the customer take that guarantees him the right to points?
- Who has a financial obligation to create this score?
- They are multiple actions, each with a different score value?
- The same action may result in different scores?
- A person is able to get points while offline and sync when online?
Every question you can think about your model will be able to better specify where your problem is. If your customer earns offline points, you need to think about coupon forms, such that a coupon has a generated code that makes it mathematically unlikely that anyone will be able to "find" it at random. If your customer earns points when making a purchase, it may be the responsibility of the establishment itself to guarantee the authenticity of the information. If a specific action is only able to generate a specific amount of points, that score can be stored on the server side.
You can encrypt the client-side data and decrypt on the server-side.
– Alisson
@Alisson, exactly, I had thought of it using jCryption, because I can’t leave a symmetric key exposed in my client-side code.
– DanOver
You can leave the methods all on the server side, and do only "triggers" on the client side, with the encrypted parameters, any parameter that arrives in the method and gives conversion failure, you automatically do not perform the operation and back to the client
– Miguel Neto
@Miguelneto, I’ve thought about this too, but I believe that the client can tamper with the data before it goes through the encryption, but of course this is still an extra barrier, a mere palliative. As for triggers, if the Urle client encrypts and discovers the triggers I send to the server, I will have big problems.
– DanOver