views:

54

answers:

1

I use a hidden variable (input type=hidden) to store ID information on a page. To prevent attackers, I decided to encrypt the data stored using System.Security.Cryptography.

The hidden variable is accessed in JS and executes validation logic. I will need to decrypt the data before executing the validation logic. Is there a way to decrypt data in JS that was encrypted using System.Security.Cryptography

+8  A: 

If you can decrypt it using JavaScript on the client side, so can any attacker. This approach is flawed for that reason. The Validation logic also needs to be done server side. You should never trust client side validation for anything that could potentially hurt your site.

George Stocker
Agreed. Any validation logic should happen on the server side.You can't trust ANYTHING that happens on the client side.
Techpriester
I do JS validation for convenience (no round trip) and validate on server side as I don't trust the client side script. With this approach, I have to eliminate client side validation?
@TechPriester quite correct. I use Java Script for client side validation of formatting and whatnot, but I double check that against server side validation. The only reason I even have it on the client side is to have immediate feedback for the user regarding formatting (Things like letters in a credit card number box, etc).
George Stocker
I wish I could upvote this answer a thousand times. Do not -ever- use javascript to store sensitive information.
Mike Robinson
If I store data in the hidden input variable, I am able to access it on the client side. If I do not do this, what is the best approach for accessing this data from a JS function?
@unknown (yahoo) If you can access it from JavaScript, so can an attacker. Anyone can see a 'hidden' form field. Hidden is a misnomer.
George Stocker