Fix role leakage between connections - #1444
Conversation
|
@levkk feel free to review this one, thanks :))! |
- One line fix - Test coverage formatting
162f9b7 to
24a1461
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This is an edge case I think. The real bug is if a client runs |
You're right, I reproduced it. SET ROLE issued after a backend is attached leaks with no pin involved: Next client on that backend gets current_user = pgdog1 fails with this PR's fix applied, so check-in cleanup can't reach it. Worth noting what is already working: role is not in UNTRACKED_PARAMS, the parser already produces Command::Set { name: "role" }, and link_client already emits RESET "role" at check-out. A SET ROLE outside a transaction is therefore already handled on main; I have a passing test for it. The hole is specifically that a SET issued once a server is attached is never written to client_params (populated only at check-out, server.rs:731), so the next check-out has nothing to reset. That's the same hole #1299 is fixing for parameters generally. So: how would you like this split?
|
Fixes #1341.
The bug
In transaction pooling, a client that pins its backend and runs SET ROLE leaks its current_user to the next client handed that backend:
The next client executes queries as a role it never asked for and may not be entitled to.
Root cause, see scoping
The fix is adding one statement to the
DIRTYcleanup list:Query::new("RESET SESSION AUTHORIZATION")On your (@levkk) RESET ROLE suggestion: I implemented and tested that first. RESET SESSION AUTHORIZATION makes all tests green, because per the docs SET SESSION AUTHORIZATION also resets role — so
RESET_ROLEalongside it is dead weight and I dropped it. Happy to switch to RESET ROLE instead if you'd rather keep the change narrower in intent, but then the SET SESSION AUTHORIZATION variant documented in the issue stays broken: it leaks session_user as well, and session_authorization is in -out path never resets it either.