This repository was archived by the owner on May 29, 2026. It is now read-only.
fix(security): SQL injection in MagicMapper UNION search (wave-3 C2, C3)#1994
Open
rubenvdlinde wants to merge 1 commit into
Open
fix(security): SQL injection in MagicMapper UNION search (wave-3 C2, C3)#1994rubenvdlinde wants to merge 1 commit into
rubenvdlinde wants to merge 1 commit into
Conversation
…icMapper UNION search (C2, C3) C2 — _limit/_offset interpolated raw into UNION SQL: searchAcrossMultipleTablesWithUnion() concatenated $query['_limit'] / $query['_offset'] directly into the final LIMIT/OFFSET clause. The boundary that strips '_'-prefixed params (SearchQueryHandler) explicitly preserves them, so the raw user value flowed from any /api/objects GET through to a raw prepared SQL string. Cast at the boundary and clamp: LIMIT 1..1000, OFFSET >= 0. C3 — ORDER BY accepted unsanitised @self.<field>: The @self. branch set the column name to METADATA_PREFIX . substr($field, 6) with no sanitizeColumnName / quoteIdentifier, then concatenated into the ORDER BY clause. Only the non-underscore branch was sanitised. Allowlist the metadata-suffix against getMetadataColumns(), sanitise + quote in every branch, and skip unknown suffixes instead of risking injection. Both reachable from any caller that hits a UNION-search code path, including @publicpage object reads — i.e. anonymous-reachable injection.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Wave-3 critical security sweep — PR 1 of 4
Fixes two SQL-injection vectors in
lib/Db/MagicMapper.php::searchAcrossMultipleTablesWithUnion().C2 — _limit / _offset interpolated raw into UNION SQL
MagicMapper.php:1243-1245(pre-fix) built" LIMIT {limit} OFFSET {offset}"fromquery['_limit']/query['_offset']without casting.SearchQueryHandlerpreserves_-prefixed system params untouched, so the raw user value flowed from anyGET /api/objects(incl.@PublicPagepaths) into a raw prepared SQL string.Fix: cast + clamp at the boundary: (int), then max(1, min(1000, …)) for limit and max(0, …) for offset.
C3 — ORDER BY accepted unsanitised @self.
MagicMapper.php:1213-1224(pre-fix): the@self.branch set columnName = METADATA_PREFIX . substr(field, 6) with no sanitizeColumnName + no quoteIdentifier, then concatenated into the ORDER BY clause. Only the non-_else-if branch was sanitised + quoted.Fix: allowlist the
@self.<suffix>candidate against getMetadataColumns(); sanitise + quote in every branch (incl. the_-prefixed system-column path); skip unknown suffixes instead of risking arbitrary-identifier injection.Why one PR for both
Both are the same class of bug (SQL injection via unfiltered string interpolation in the same method), both reachable via any UNION-search path including anonymous-reachable
@PublicPagereads. Keeping them together gives reviewers a single diff to audit the entire UNION-clause assembly.Test plan