While answering this question, I gave some (unfounded) advice on
create policy test_policy on policy for all to public using (
user_id = session_user_id());
Btw, you should schema-qualify the
session_user_id()
call to make your policy actually secure, so that the user cannot inject their ownsession_user_id
function through thesearch_path
.
But is this actually the case? I had misremembered the search_path
issue with SECURITY DEFINER
functions.
How and when are row-level-security policies parsed? Are the references resolved during definition or during evaluation?
It would make sense to have identifiers in them be early-bound not late-bound, but I could not find anything in the docs about this.