I have a WebAPI application which is working fine. There are no problems loging, registering etc. However, I come across something which requires some attention. When somebody is registering or logging then their passwords are sent in plain text. I know we can apply HTTPS certificate and this will be solved. However, I am more looking for a solution where I can hash password and WebAPI can automatically pick it up. I am not looking to make changes to built in WebAPI functionality to hash and store PW. This is to also make sure that when I am using FF or Chrome developer tools then nobody can read the PW from data being sent.
I am using Angular or JQuery AJAX to make calls to my WebAPI.
It is possible to encrypt the password in the frontend and send the hashed password and salt + rounds (when used) to the server.
Problem arises when the user tries to log in, you need to get the salt and roundings to the frontend, hash their password (which the typed in) send it to the server, there you do a compare like hashedPassword == hashedPassword and return true/false.
So in my opinion this is less secure than just doing all on the server side. Only benefit is, that no one can see your password in your dev-tools or in the payload.
Related
I am currently attempting to develop a quick tool that would allow me to check my cellular plan balance (carrier being MetroPCS). To do this, I need to be able to login to the metro website with a library (like python requests) that does not render javascript. While checking the post request for the login form on metro's website, I noticed that the password field (labeled "verificationValue") seems to be encrypted. This obviously means I cannot login with a plain text password. Encrypted pin number
I have attempted to look up ways to somehow trace back the javascript that may handle encrypting the password field before it is sent as a post request but was unable to find anything that I could understand.
you should try to find a way to interact with the service directly, bypassing the login form. For example, you might be able to use an API provided by the service to check your balance, rather than logging in to the website
I have a app which takes a csv from user, converts it to json and saves the json file in S3 bucket on AWS. Then I am using restful services from oracle to push that data to oracle jde.
User can't upload a file without being "approved" before hand - its a manual process for now, but their email needs to be added to S3 bucket first
The web app checks if the email exists in S3 then allows the file upload to happen, if it doesn't exist then file upload is rejected.
I don't have any other "user authentication" set up for now.
Next, in order to get the token from the external API, I need to feed it a service account username and password, currently, since its still in development I am keeping the username and password on my server side nodejs in a object which I pass into the api call to get the token.
For the time being we don't plan on having user login, so that being said how can I secure the username and password but still be able to get a token for "authenticated emails allowed to upload"?
Basically, I assume just keeping it in variable server side node is not a good idea, so looking for another way of storing it somewhere and still being able to make the call to the api.
For the time being we don't plan on having user login, so that being
said how can I secure the username and password but still be able to
get a token for "authenticated emails allowed to upload"?
You can't. Unless I'm misunderstanding something, those are not "authenticated emails", they are "pre-approved email addresses". You still need to authenticate your users to help secure the app.
So do I still hash and salt the hardcoded username and password and save to db?
You can't salt and hash your passwords because you're intending to reuse the original password. That puts the onus on you to secure the passwords. Don't play that game. Many people reuse the same passwords for lots of different accounts. Do you want to have to send an email to your users letting them know you had a security breach and that they need to reset all their passwords?
Basically, I assume just keeping it in variable server side node is not a good idea
That's right, it's not a good idea. For example what if your server dies? Then you'll loose that value. Not to mention the added cost of your RAM since everything will be stored in memory.
Solution
Store the credentials in a database. It can be in SQL or NoSQL, and the server can be in whatever you prefer
Considerations
Don't forget to hash the password before storing it
Add some salt when hashing
To validate a password, just hash the one you got from your client and compare it to the hash you stored in your database
Use HTTPS for traffic between your client and server
I want to send a password over HTTP.
Scenario:
User enters his username and password into a form.
Password is hashed and sent to the server with the username.
Server checks password hash and username and authenticates user. (the server doesn't know the plain text password either.)
If someone somehow intercepts the authentication message, he will obtain the hashed password and username, and he could potentially log in to that user's account. Essentially, the hashed password IS the password, according to the server.
Here's the thing: I don't care. It's rare enough that someone would have that data hijacked, and even so, it's not really a problem if your account gets stolen, you can just make a new one.
The Question: What is a good way to hash the user's password in JavaScript? The hash can't use random salt since it needs to be recognized by the server.
The only thing I am concerned about is the user's plain text password being found out if the message is intercepted. The reason being that the plain text password could also be used to compromise other services the person uses that may actually contain important information.
EDIT: to clarify, the question is mainly about what hashing algorithm to use, and if there is a lightweight library for it.
If security is actually not an issue, e.g. it's okay for people to compromise your system, and the only reason you want to salt the hash is to prevent the use of rainbow tables and the plaintext password from being determined, then do this:
Compute a sufficently long salt for every password on the server, and store it on the server (just like how most systems typically stores the password in the DB)
Send the salt to the user in plaintext
Compute the salted hash and send back
If I'm thinking about this correctly, this will still prevent the use of rainbow tables.
Otherwise, just go with https? :P
I'm experimenting with PouchDB and client-side Javascript. The example on the PouchDB site works great for me: http://pouchdb.com/getting-started.html. My question is, is there any way to obscure the username and password when I connect to the remote server? The code in question:
var remoteCouch = 'http://user:pass#mname.iriscouch.com/todos';
This is all client-side JS and publicly viewable. I'm stumped on figuring out a way around it.
When you're communicating between servers you can use SSL to remain secure. The client and server establish a secure connection before sending any data about the request (i.e. the file name, the basic authentication creds, etc.).
As far as what lives on the client side, it's more of a question of how secure do you want to be. Since everything is JavaScript, especially so with PouchDB, you have to settle for one of two things
Having a fancy switch that shows you menus or hides menus
In this scenario you have a main screen with all the important menus. The user either supplies the right password, which takes them to that screen, or the program says "Error incorrect username or password". But since it's all in JavaScript, anyone with enough knowledge of your system could say something like MyApp.User.isLoggedIn = function() { return true; };.
Encrypt what you need
If there is sensitive data on the client side, you can ask them to supply their password and encrypt the sensitive data using that password. Depending on the payload, it may or may not be too performance intensive. You might have to implement your own sessions in this case so you don't end up keeping that password or sensitive data around in memory. Then all Eve would have to do is go to the JS console and hit console.log(MyApp.User.password);. Even though the password is hashed and salted (or should be), Eve likely still has access to the hash function and salt.
Good luck! Would love to hear what you come up with.
If the username and password are to be provided by the user, you can present them with a login prompt and use a secure CouchDB session cookie. The cookie is tamper-proof and will be deleted when the browser session ends or you explicitly delete it.
given the following scenario: We have a html form for changing an account's password. It looks like this:
CurrentPassword: __________________
NewPassword: __________________
NewPasswordAgain: __________________
We want to send this request via an ajax call. If we send it and we leave our computer (without logging out and staying on the exact same page) someone could open the webkit inspector (or firebug) and see something like this:
http://cl.ly/3y213W1q0U2y2e251k0O
What would be your solution for making this more secure? Is it even possible using an ajax call here or would it be better to use a "normal" html form which reloads the whole page after sending?
Using a "normal" html form has the same problem, as packet sniffing could reveal the same data in a POST or GET header just as easily.
The best solution I can think of is to encrypt the password user-side via javascript. You don't really have to worry about the "what if the user has javascript disabled?" case since, in that case, the AJAX request won't go through either. Obviously this may have ramifications regarding how you store the password, but it will allow you to continue to use AJAX requests for the password update.
The author is not interested in encrypted connections here. He may as well be doing that already. What he wants is to be able to hide the password (and username) from any one who has an access to the computer, and can open the inspector tools to view the networking that occurred on the page.
One of the simplest things you could do is to refresh the page in case the authentication succeeded.
Something that you should do is to refresh the page whenever the user pressed "log out". This should clear all previous network data.
The less good options are about encrypting, obfuscating and hashing the password prior to sending it.
Hashing the password on client-side is not ideal because this prevents the use of hashed passwords with keys on the server-side (think HMAC). HMAC'd passwords are the best, because the key is kept on the filesystem whereas the salt is kept on the database. Cracking the password hash requires a rather solid access to the system.
Obfuscating and encrypting the password can be reversed. If someone sees a login request on the Webkit Inspector, he might be very interested in spending the time to undress your defenses.
I highly recommend refreshing the page at some point to avoid the problem entirely. Other options do not seem as good.
Encrypt the password on transport and make sure the calls you are making are being done over SSL!
To make this secure without using SSL, hash the passwords on the client using SHA-2. While that will protect the password itself, it won't protect someone from sniffing the hashed password. So you can't simply authenticate with the hashed password, either.
One way to do this is to use a server-generated random salt when authenticating. To authenticate, the client requests salt from the server, then hashes the password once (in order to match the hashed version stored on the server), then hashes again using that salt that it received from the server, then finally authenticates using a second ajax query with the salted-hashed password.
The server will authenticate only if this matches its own stored hashed password, hashed with the same salt it previously provided the client.
This way, it is impossible for someone to authenticate using the simple hashed version of the password. Since each salt provided by the server is valid only once, it would be essentially impossible for someone to intercept it and authenticate. (They would have to intercept the salt request, and then try to authenticate before the legitimate client could, all the while spoofing their session).
This protects users' passwords without using SSL, prevents logging in using data intercepted while the legitimate user is authenticating, and is fairly easy to implement. Of course there is no substitute for SSL as far as protecting the actual data on your site, but for a lot of typical web sites where there's not really any sensitive information, you should be more concerned about preventing theft of your users' passwords since people use the same password so often. This addresses that problem.
Note that this also does nothing to prevent session hijacking, but you can minimize the risk and damage of this by doing things like including browsers-specific information with the users's session, and allowing only a single active session at once, and requiring re-authentication to change email address or password.
Depending on the level of security you need, you could use RSA and public-key cryptography to encrypt the password within the browser prior to sending the ajax request. On the server-side, you would decrypt the passwords and process them as normal.
Of course, you would also need to be careful to delete any variables used to hold the entered passwords, and I am sure there are other security holes in this, but encryption will at least offer you some large degree of protection against that sort of attack.
Here's one library I found with a quick search. (disclaimer: I have not tested this, but it looks pretty good)
Lastly, I would strongly recommend that you transmit all login information via SSL. This adds an extra layer of security on top of the whole browser session between the browser and your server.