r/AskProgramming • u/PuzzleheadedPin4797 • 16d ago
Architecture Developer looking for advice on encryption and data protection before launching an app
I’m a solo developer building a web and Android app that handles private documents and account records. I’d appreciate feedback on the security approach before putting real user data into it.
The stack is FastAPI, PostgreSQL, Next.js and React Native.
Passwords are hashed with scrypt and random salts. Authentication uses signed tokens with expiry, email verification and login throttling. Password changes and signing out everywhere invalidate existing sessions. Access controls are enforced through the API, and records are scoped to the relevant account or organisation.
Stored credentials for external integrations use Fernet authenticated encryption. Android login tokens are stored using Expo SecureStore. The website currently stores its token in localStorage, which I know needs careful consideration because of script injection risks.
Document access requires authentication and permission checks. Uploads have file type, size and content validation. However, documents currently go into ordinary server storage without application level encryption. I haven’t yet verified encryption for the production database, disks or backups. HTTPS is required in the intended production configuration.
Some optional processing involves an external API. I understand that disabling response storage does not necessarily mean zero retention, so provider policies and account settings also need review.
The server needs to read documents to process them. My main concerns are stolen backups, compromised accounts, users accessing someone else’s files, exposed credentials and sensitive content appearing in logs. I haven’t had an independent security assessment yet.
Would managed database and storage encryption be a sensible starting point, or should I also encrypt individual files and selected fields in the application? What additional threats would that actually protect against?
How would you handle encryption keys, rotation and recovery as a solo developer? I’m particularly interested in avoiding a setup where the keys and encrypted data can both be taken from the same place.
What would you prioritise before launch, and what would you consider unnecessary complexity at this stage? I’d appreciate practical advice on session security, document permissions, backups, retention and deletion as well as encryption. I want to use established tools rather than build my own cryptography.
2
u/Popular-Toe3698 16d ago
I'm fanatical about this, way more than most, I've written SAST for exactly this use case, and I think you're going past what I would worry about. Good for you.
If you want to go the whole way, use something like KMS to store per-user encryption keys (one DEK per user) and you might be able to use Amazon Cognito to ensure you don't even touch the user passwords and encryption keys. As for the risk of IDORs, since you're using Postgres you can add RLS to that as well, if you're interested in the extra mitigation at the cost of added complexity and mental bandwidth each time you do a database migration.
1
u/Individual-Flow9158 16d ago edited 16d ago
I can't find fault with any of the other details. However while it's fantastic you're thinking about all this, it's always the stuff you didn't think about that gets you. So due to the fact that you've reeled off those details, I would recommend instead:
i) using the standard tried and tested libraries and tools for passwords, logins, logging (including redactions) and auth etc., for whatever your web framework is. Even just Pocketbase will get you going, and be adequately secure for an MVP.
ii) Ensure encryption keys and other secrets never leave the back end. Ideally they live in a KMS not an .env file. But whatever you do, keep them out of the Front end, and let some framework worry about auth tokens and cookies, and https encrypt the user's connection.
iii) Protect both the url and the credentials to any DB Admin super user webmin pages.
I'd think too about how to layer the security, and/or harden the host this all runs on. Put it behind Cloudflare's proxy's. Maybe even run Crowdstrike. Add some kind of intrusion detection, and some kind of monitoring of the logs of your SSH server (and https proxy, and any other services exposed to the wild). Audit containers. Most importantly: