Skip to content

Conversation

rbngzlv
Copy link
Contributor

@rbngzlv rbngzlv commented Aug 28, 2025

Hi! This patch "adds" support for the new \restrict and \unrestrict meta-commands issued in pg_dump as part of the fix for GHSA-6m5q-cc57-2mj6 (see: https://www.postgresql.org/support/security/CVE-2025-8714/).

These meta-commands are specific to the psql (https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-META-COMMANDS), so, my first approach was to add them to PSQL_DUMP_BLACKLISTED_STATEMENTS because my understanding is that any meta-command present in the dump would manifest as the following error when cloning the schema:

ERROR: syntax error at or near "\" at character XX

In fact, we can find an exmple of this error in the project's test suite:
image

However, I was not entirely comfortable with that approach. Therefore, I propose switching to using psql to load the SQL generated by pg_dump, as this eliminates the need for explicit blacklisting and should improve resilience to future changes in pg_dump output.

Fixes #322

This approach avoids the need to explicitly blacklist `\restrict` and `\unrestrict` psql meta-commands issued in newer `pg_dump` versions, and should increase resilience to future changes in `pg_dump` output.
Copy link

codecov bot commented Aug 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.27%. Comparing base (755a9a9) to head (468c14d).

Additional details and impacted files
@@               Coverage Diff               @@
##           development     #324      +/-   ##
===============================================
+ Coverage        75.11%   75.27%   +0.16%     
===============================================
  Files               35       35              
  Lines              892      898       +6     
===============================================
+ Hits               670      676       +6     
  Misses             222      222              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

`system` passes command line parameters safely
@rbngzlv
Copy link
Contributor Author

rbngzlv commented Aug 28, 2025

The approach to switch to psql doesn't work well. When we are inside a transaction the schema creation is not commited and psql can't find the schema.

# First psql call cloning the schema
psql:/tmp/20250828-5805-u607b9:39: ERROR:  schema "xxxxx" does not exist
LINE 1: CREATE TABLE "xxxxx".active_storage_attachments (

# Second psql call copying the schema_migrations content
psql:/tmp/20250828-2770-4bommy:73: ERROR:  relation "xxxxx.schema_migrations" does not exist
LINE 1: INSERT INTO "xxxxx".schema_migrations VALUES ('20250120163...

def create_tenant_command(conn, tenant)
# NOTE: This was causing some tests to fail because of the database strategy for rspec
if ActiveRecord::Base.connection.open_transactions.positive?
conn.execute(%(CREATE SCHEMA "#{tenant}"))
else
schema = %(BEGIN;
CREATE SCHEMA "#{tenant}";
COMMIT;)
conn.execute(schema)
end
rescue *rescuable_exceptions => e
rollback_transaction(conn)
raise e
end

@rbngzlv
Copy link
Contributor Author

rbngzlv commented Aug 28, 2025

This PR is superseded by #325.

@rbngzlv rbngzlv closed this Aug 28, 2025
@rbngzlv rbngzlv deleted the switch-to-psql branch August 28, 2025 11:30
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.

Postgresql 17.6 adds \restrict and \unrestrict statements to dump that need to be blacklisted
1 participant