Skip to content

Helmet and Password Hashing

rvdegroen edited this page Jun 22, 2022 · 7 revisions

Table of Contents

What is Helmet?


Helmet.js is a useful Node.js module that helps you secure HTTP headers returned by your Express apps. HTTP headers are an important part of the HTTP protocol, but are generally transparent from the end-user perspective. The headers provide important metadata about the HTTP request or response so the client (browser) and server can send additional information in a transaction.

Because the user doesn't see the HTTP headers, developers sometimes ignore them, but HTTP headers can leak sensitive information. So it's important to secure them and use them in a secure way.

A popular way Express apps leak information is through the X-Powered-By header. This header informs the browser which server vendor and version you’re using. By default, Express exposes the X-Powered-By header and leaks “Express” (usually without a version number). Hackers typically cross-reference this information with a list of publicly disclosed known vulnerabilities, which makes your app a prime target for easy exploits.

As you can see HTTP header shows which servor vendor we are using (Express) http header

Helmet can fix this with just one simple line of code:

import helmet from "helmet";

// ...

app.use(helmet());

After you've implemented this in your code, your HTTP headers will look like this: after helmet

As you can see there is no more vunerable information being displayed, futhermore there are some more safety functions made for your users and you.


What is Password hashing?


Password hashing is used to verify the integrity of your password, sent during login, against the stored hash so that your actual password never has to be stored. A good way to do password hashing in node.js is bcrypt.

No users wants their actual password to be seen by others, it's simply not safe. Thats why we use a module like bcrypt to change the password to a set of random characters.

We can use bcrypt by requiring it and using the function:

bcrypt

We put in the text we want to hash, and next to it we will put a number also known as saltrounds, most the time people will use 10. Imagine we not put in a password of "mypassword123", after it gets hashed it will be displayed in the database like this "2b$10$2rRdWQD3QolOa9auZLXHmeIrFfTnW". So thats why we use password hashing

Sources: https://github.com/helmetjs/helmetm, https://www.oreilly.com/library/view/advanced-express-web/9781783282494/ch05s07.html, https://www.veracode.com/blog/secure-development/fasten-your-helmetjs-part-1-securing-your-express-http-headers#:~:text=Share%20this%20article%3A-,Helmet.,from%20the%20end%2Duser%20perspective. , https://auth0.com/blog/hashing-passwords-one-way-road-to-security/

Clone this wiki locally