First, I will answer your question "side-quest":
you are completely right with your worries and concerns, and everyone who develops an application should think about the same thing. Everything else is careless and careless.
To reduce the damage that could be caused by a successful SQL injection attack, you should definitely use the least privilege principle.
You must configure a system that meets your requirements.
I will use the object names from your example, except that I use underscores instead of minuses. It is useful to use only lowercase letters, underscores and numbers in the names of objects, as this will make your life easier.
\c postgres postgres CREATE DATABASE test_database WITH OWNER app_admin; \c test_database postgres DROP SCHEMA public; CREATE SCHEMA app AUTHORIZATION app_admin; \c test_database app_admin GRANT USAGE ON SCHEMA app TO app_user; ALTER DEFAULT PRIVILEGES FOR ROLE app_admin REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC; ALTER DEFAULT PRIVILEGES FOR ROLE app_admin IN SCHEMA app GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO app_user; ALTER DEFAULT PRIVILEGES FOR ROLE app_admin IN SCHEMA app GRANT SELECT, USAGE ON SEQUENCES TO app_user; ALTER DEFAULT PRIVILEGES FOR ROLE app_admin IN SCHEMA app GRANT EXECUTE ON FUNCTIONS TO app_user;
But if you take the principle the least seriously, you must grant permissions to tables individually and, for example, do not allow app_user
until DELETE
and UPDATE
data in tables where the user does not need to do this.
source share