Skip to content

Validate identifiers substituted into extension scripts#308

Open
jim-mlodgenski wants to merge 1 commit into
aws:mainfrom
jim-mlodgenski:harden-extension-script-substitution
Open

Validate identifiers substituted into extension scripts#308
jim-mlodgenski wants to merge 1 commit into
aws:mainfrom
jim-mlodgenski:harden-extension-script-substitution

Conversation

@jim-mlodgenski

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

execute_extension_script() substitutes @extowner@ and @extschema@
into the extension script, filtering each value through
quote_identifier(). Certain characters (" $ ' \) cannot be
quoted consistently both inside and outside of string literals, so a
name containing one of them can produce a script that does not parse the
way the extension author intended once the substitution is performed.

This change rejects substitution when the owner or schema name contains
any of these characters instead of producing such a script, matching the
identifier handling that PostgreSQL core performs for the same
substitutions. The pg_tle_injection regression test is extended with
coverage for both the owner and schema cases, including a check that
ordinary names continue to work.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

execute_extension_script() substitutes @extowner@ and @extschema@ into
the extension script, filtering each value through quote_identifier().
Certain characters (" $ ' \) cannot be quoted consistently both inside
and outside of string literals, so a name containing one of them can
produce a script that does not parse the way the extension author
intended once the substitution is performed.

Reject substitution when the owner or schema name contains any of these
characters instead of producing such a script. This matches the
identifier handling that PostgreSQL core performs for the same
substitutions. Extend pg_tle_injection with coverage for both the owner
and schema cases, including that ordinary names continue to work.
-- @extschema@ and @extowner@ substitutions are filtered through
-- quote_identifier(). A schema or owner name containing a character that
-- cannot be consistently quoted inside and outside of string literals (any of
-- " $ ' \) must be rejected rather than substituted into the script.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: guess it is still beneficial to test $ and \ ?

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