[2.x] fix(search): harden pgsql search configuration handling#4663
Merged
Conversation
Bind the `pgsql_search_configuration` setting via `?::regconfig` instead of interpolating it into the SQL string. The value is now treated as data; Postgres rejects invalid configuration names at the cast.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pgsql_search_configurationsetting was interpolated directly into the SQL strings built byDiscussion\Search\FulltextFilter::pgsql()andPost\Filter\FulltextFilter::pgsql(), allowing a second-order SQL injection: an admin could write a payload to the setting and any subsequent search would execute it.?::regconfigparameter binding for the search configuration. The value is now treated as data, and Postgres rejects unknown configuration names at the cast — defence in depth for free.SQLSTATEreturned by Postgres as an unambiguous signal:42883(operator-does-not-exist ontsvector || pg_sleep) means the payload was treated as code;42602(invalid name syntaxfrom theregconfigcast) means it was treated as data. Verified to fail against the un-patched code and pass against the patched code.Scope
Test plan
composer test:integrationagainst Postgres 16 with the new test passes.FulltextSearch|FulltextFilter|ListWithFulltext) pass against Postgres with the fix.tests/integration/api/discussionssuite (39 tests) passes against Postgres.SQLSTATE 42883) — i.e. the test would have caught the regression.Credit
Reported via the Flarum.org foundation contact form by userb1ank.