Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropping role with table privileges granted by non-neon_superuser #10964

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tristan957
Copy link
Member

We were previously only revoking privileges granted by neon_superuser. However, we need to do it for all grantors.

@tristan957 tristan957 requested a review from a team as a code owner February 24, 2025 23:43
Copy link

github-actions bot commented Feb 25, 2025

7755 tests run: 7377 passed, 0 failed, 378 skipped (full report)


Flaky tests (3)

Postgres 17

Code coverage* (full report)

  • functions: 32.8% (8638 of 26362 functions)
  • lines: 48.6% (73099 of 150465 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
fff6e6e at 2025-02-27T05:12:05.225Z :recycle:

We were previously only revoking privileges granted by neon_superuser.
However, we need to do it for all grantors.

Signed-off-by: Tristan Partin <tristan@neon.tech>
FOR grantor IN
SELECT DISTINCT rtg.grantor
FROM information_schema.role_table_grants AS rtg
WHERE grantee = '{role_name}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, isn't this prone to SQL-injection now? I.e. if you name role like ';DROP DATABASE template0;'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think you're right. Hmmm


EXECUTE revoke_query;
revoke_query := format(
'REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA %I FROM "{role_name}" GRANTED BY %I',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, if the grantee is some 'funny' name, I guess you need something like quote_ident() or so

Comment on lines +383 to +384
TEST_GRANTOR = "my_grantor"
TEST_GRANTEE = "my_grantee"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of whether the current code is prone to injections or not (I bet it does, though), let's make role names for both grantor and grantee to contain the injections vector like '; RAISE 'ouch'; ' or "; RAISE 'ouch'; " depending on the type of quotes you use in what case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@tristan957
Copy link
Member Author

Given the SQL injection comments, good catch, I will take another look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants