When you're just using the password, we know that passwords can be figured out. When you're using tokens that give read-write access, well, if they get access to that token, they have access to pretty much what they need. They could change the code for your custom authentication engine, and nobody would really know who did it.
But most of the time, these tokens are just used in your CICD pipelines, or maybe you have some kind of environment file that you use locally or in different environments. So when you know you're just using your npm package somewhere, you're not trying to publish changes with this token, just go ahead and use the read-only. It'll save you some time. It'll give you a little bit of extra comfort at night, and you'll know exactly who has the right access to your applications.
All right, now on to managing your data. Because data is really this vast mystical, I don't know, phenomenon in our world. But something you wanna do, before you put new data in your database, make sure that you have pre-sanitized these values. You don't want to add a SQL statement to your database. Just, you know what types you expect to be going into each column in your database. Make sure that the value matches that. There shouldn't be any numbers trying to get written to string columns or any emails getting saved to address fields. Just go through the extra check and make sure that this data matches what you're expecting.
And one of the ways that we do this in Node is just type your schema. Most ORMs that we use, like Mongoose or some of the other, I forget the one that comes with Postgres, but whatever. You know the exact types. You know the names of the values. You know everything you need to know to make it impossible to save a different type of data in your database. And you need just a quick package. Just use validator.js. This makes it super easy to add that validation to your Node apps without you having to make up your own validation functions. They have things for emails, phone numbers, passwords, all that good stuff. And requests and responses.
This is something that I think we should all definitely be aware of. Make sure that you're using Helmet.js for your headers. This adds a bunch of just different security settings to your headers that honestly I had never thought about until I used this library. But it basically helps with any course issues, it locks down the differences between git and POST requests and it just takes care of a lot of behind the scenes things that you don't necessarily think of while you're writing your code.
And then when it comes to handling user data, earlier I was talking about making sure everything was encrypted, well use Crypto.js.
Comments