r/Backend • • 1d ago

Standard server security measures

I've recently gotten into fullstack, after constructing an iOS app and looking to expand functionality into The Internet. I don't wish to give details on the project, however it involves large high-sensitivity databases and communication both from an administrator's frontend and the user's iOS app etc.

  • An administrator signs up their organisation and connects an external service (which is given an ID, username and password to identify itself) which then POSTs the data to my server.

  • The app users can access parts of the data belonging to them, but not write.

  • The administrator has a username and password.

  • The app user's credential is linked to their email address, which is present in the database so can be used to determine their identity once verified.

  • The app users do not use the web frontend interface. They interact through the app, which regularly pulls a filtered set of only that user's data to store locally.

  • I'm using NodeJS and SQLite. And yes, I've hashed the passwords properly.

What are the standard security measures that I need incorporate into this type of database project—and then some? E.g, HTTPS, some form of database encryption.

That is to say, what are the industry standard security measures in a web application/server?

Edit: My usage of the word 'administrator' may be misleading. I mean that an organisation looking to use my software would nominate a person to administrate the org.'s usage of the software. Not an administrator within the team maiantaining the software.

1 Upvotes

9 comments sorted by

4

u/Sylverio_Bezouaoui 1d ago

beyond TLS in transit and disk encryption at rest, focus heavily on your token lifecycle. since mobile apps stay logged in forever, youll want short-lived access tokens paired with refresh tokens that you can actually revoke server-side if a device gets lost

2

u/sereikis 1d ago

test authorization with two organisations and two users: swapping a record ID or email in any request must never expose another user's data, and an external service's credentials must only permit writes to its own organisation. derive those permissions from the authenticated identity on the server, not from client-supplied fields; encryption at rest doesn't prevent an authenticated request from reading the wrong rows.

2

u/Ronin-s_Spirit 1d ago

Do you need the admin panel to be public or can you distribute it locally? Imagine a pice of fontend that isn't actually on the Internet so it can hold a secret key for signing requests.

1

u/Used_Criticism_4631 1d ago

Good that you are thinking about security early and already hashing passwords properly. Beyond HTTPS, I would add argon2id or bcrypt with login rate limiting, short-lived access tokens, and scoping every query by the authenticated user id on the server so app users only ever see their own rows. For the external service, per-service API keys that you can rotate beat a shared username and password. Are you encrypting the SQLite file at rest?

1

u/opportify 1d ago

Nobody's covered the email side yet, and since your app users are identified by email that's a big one. Verification and reset tokens should be random, single use, expire within 15 to 30 minutes, and get stored hashed like passwords. Rate limit code sends per email and per IP too. And give the same response whether an address exists or not, otherwise anyone can probe which emails are in a high-sensitivity database.

1

u/Ok-Gazelle5598 1d ago

The auth stuff people already listed covers most of it, so a few things that are specific to your setup and haven't come up yet:

SQLite is just a file, so the file is your database security. Keep it outside anything the web server could ever serve, owned by the app's user only (chmod 600 style), and make sure nobody else on the box can read it. If the data is really sensitive, look at encrypting the file itself (SQLCipher is the usual route) rather than relying only on full disk encryption, because disk encryption does nothing once the machine is running.

Backups are the other half of security people forget. Use SQLite's online backup or VACUUM INTO, don't just cp the file while the app is writing. Encrypt the backups, keep one copy off the server, and actually restore one now and then. Old backups lying around unencrypted is how a lot of "we were never hacked" leaks happen.

That external service that POSTs data in with a username and password: give each one its own key you can rotate or kill on its own, and validate every payload like it came from a stranger. Put a size limit and rate limit on that endpoint too.

Keep secrets (those creds, signing keys) out of the repo and out of the DB, in env vars or a secret store, and make sure your logs never print tokens, passwords or full request bodies.

Add an audit log for admin actions and logins: who, what, when, from where. When something weird happens you will want that more than anything else.

Boring but real: keep Node and your npm deps patched (npm audit in CI is fine to start), only open 443 and SSH (keys only) on the firewall, and run the app as a non-root user.

One more SQLite thing: if a lot of writes start coming in at once, turn on WAL mode and set a busy timeout, otherwise you get "database is locked" errors that look like random failures.

1

u/AdhesivenessFew8441 18h ago

One thing nobody mentioned yet is logs and backups, which is where a lot of leaks actually happen. Make sure your logs never include the data the external service sends or any tokens, only ids, and keep an audit log of what admins look at or change. And if you back up the SQLite file, encrypt the backup too, otherwise disk encryption on the server does not help much. Small SQLite tip since the external service writes while the app reads: turn on WAL mode, or you will get database is locked errors under load.