2

I'm trying to make my REST API more secure. For the moment I'm hashing my password in my angular app with CryptoJs.SHA256 before sending it to my C# backend. But I realize it's better to hash password on server side. So how can I send a password only readable by the server? I'm going to add SSL but I know HTTPS is also breakable. Is there an other solution?

Thanks

Alexandre
  • 604
  • 5
  • 21
  • 1
    What's on the client-side? A Javascript program? ASP.NET page? A C# client? Please add more information like how are you contacting the server. – Camilo Terevinto Nov 30 '15 at 13:58
  • 2
    If HTTPS is broken, then any JS implementation you send to the client is also untrustworthy (as it can be replaced by the attacker). Just use HTTPS (correctly, none of this "just ignore the BIG RED WARNING" nonsense) and be done with it. See e.g. this: https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/august/javascript-cryptography-considered-harmful/ – Piskvor left the building Nov 30 '15 at 14:39

3 Answers3

4

As Bruce Schneier says, "Anyone can design a cipher that he himself cannot break. This is why you should uniformly distrust amateur cryptography, and why you should only use published algorithms that have withstood broad cryptanalysis."

While nothing is 100% unbreakable, breaking HTTPS is significantly harder than breaking a homecooked security scheme made in JavaScript. Consider this: if you serve your super-secure JS over an untrusted (HTTP or HTTPS-with-invalid-certificate) connection, what prevents the attacker from substituting a broken version, which will bypass all the JS security? Nothing.

Modern browsers are going to great lengths to prevent HTTPS from being broken (with HSTS etc.); so it's significantly safer to rely on HTTPS (which can provide actual security when used correctly - "just ignore all those big red errors" is one simple way to break it) than on JS-over-HTTP (which only provides a feeling of security without an actual chance of being secure).

Further reading: https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/august/javascript-cryptography-considered-harmful/

https://security.stackexchange.com/questions/3921/why-do-some-people-really-hate-security-via-client-side?rq=1

https://security.stackexchange.com/questions/8596/https-security-should-password-be-hashed-server-side-or-client-side

Community
  • 1
  • 1
Piskvor left the building
  • 91,498
  • 46
  • 177
  • 222
0

There are a lot of sources out there on this topic, but few have actually analysed it. As a general rule, trust guidance from Thomas Pornin more than anybody else. I also highly recommend my own survey and recommendation on the topic.

TheGreatContini
  • 6,429
  • 2
  • 27
  • 37
0

Not exactly a fullblown answer to your question, but i'd start by looking into using a KDF (Key Derivation Function) rather than just hashing your secrets. Some KDF libraries that you can look into are:

  • PBKDF2
  • bcrypt
  • scrypt

https://en.wikipedia.org/wiki/Key_derivation_function

dobbs
  • 1,089
  • 6
  • 22
  • 45