mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 11:06:06 +00:00
f1ea716305
The token guard kept leaking: on a superuser connection an unqualified `alter type int4 rename to int4x` renamed pg_catalog's type for the whole server, sequences and catalog-only objects grew the database past the quota, regtype/regconfig/regdictionary looked TREK's objects up by name, and a column alias named insert or merge in front of INTO made a table. Instead of a longer word list, the store now asks the database: - No plugin SQL while TREK's role is privileged in the sense of the restore check (PRIVILEGED_ROLE_SQL, imported from server-checks.ts): every db:own call fails with PRIVILEGED_ROLE_PLUGIN_REFUSAL, read once per pool connection, and the boot log says why. - The objects an ALTER, DROP, REFRESH, TRUNCATE or CREATE INDEX ... ON changes, and the tables a CREATE or ALTER TABLE ties to its own, are resolved with to_regclass/to_regtype in the transaction right before the statement, and it is refused unless each one found lies in the plugin's schema. An unqualified int4, text or box is pg_catalog's and refused even with the role check off. - The quota counts every relation of the schema with its TOAST table, and a schema holds at most PLUGIN_SCHEMA_MAX_OBJECTS catalog objects (relations, types, constraints, enum labels). - The guard refuses every reg* type and its array in every spelling, the has_*_privilege functions, currtid2 and the BRIN/GIN maintenance functions; INTO only after the INSERT or MERGE that is the statement's verb or a WITH body's; TEMP only where it makes a temporary object (CREATE TEMP/TEMPORARY, SELECT ... INTO TEMP), so a column named temp works again; a base type; and a NUL anywhere in the SQL text. - A bound value or a migration id holding NUL is refused with the reason instead of being stripped, so the plugin's keys never change meaning. Every bypass from the re-review is a test on the real database, on the role the plugin data is meant to run as and on a superuser connection with the role check off.