PostgreSQL - Functions-Body-Security I'm thinking about how to hide as many attributes of relations from a user as possible &amp; if functions can help with that.
Example:

The user &quot;dummy_user&quot; should have as little insight as possible.
The table &quot;user&quot; contains user data incl. password. The password should not be accessible for the dummy_user.
The function &quot;does_password_match(user_id, password)&quot; checks if the password matches the user.

My question now: I read in the PostgreSQL doc: &quot;SECURITY DEFINER specifies that the function is to be executed with the privileges of the user that owns it.&quot;.  So that means I can create the function does_password_match as admin and it can access the password that way and the user is allowed to execute it with the privileges of the admin?
But the dummy_user can still see the body of the function. So you can't really hide an internal structure this way, right?
And if within this function the password is searched via a SELECT, can the dummy_user then potentially still see the value of the field? And so the password of a user can potentially still be read?
The most secure way is to revoke the select privilege on the columns.
Then the user will never be able to see the contents no matter what. You can't really hide the body of a function, and you can't hide the table structure from a user (e.g. by querying pg_attribute).
But the information that there is a column named &quot;password&quot; doesn't reveal anything the user didn't know beforehand, so I don't consider this a problem.
A password stored in the database should always be encrypted anyway and with a one way encryption, so it can't be decrypted (e.g. SHA-256).
So even in the extremely unlikely case that the user finds a way to work around the privilege system in Postgres, he would only see the encrypted value and couldn't do anything with it.