CVE-2026-59011 AI-generated analysis
platform/packages/providers/MediaProvider, MediaProvider query path (queryInternal projection redaction) and util/SQLiteQueryBuilder
MediaProvider.queryInternal now validates the projection against strict columns up front, expands null and legacy "*" projections, and redacts latitude, longitude and oem metadata in every projection element using word-boundary matching with alias preservation. Before, it used an exact-string, first-occurrence replacement that aggregate wrappers, repeated columns and wildcards could bypass.
Root cause
In MediaProvider.queryInternal, two redactions relied on hasColumnsToFilterInProjection and updateProjectionToFilterColumns: LATITUDE/LONGITUDE (when indexMediaLatitudeLongitude() is on and the caller is not MediaProvider itself) and OEM_METADATA (when the caller lacks the OEM metadata permission). hasColumnsToFilterInProjection only did an exact List.contains() of the lowercased column name against the projection elements. updateProjectionToFilterColumns replaced only the first matching element (indexOf) with "NULL AS <column>". Three cases were therefore missed and returned the real value: a column embedded in an expression (for example an aggregate such as MIN(latitude)), the second occurrence of a repeated column, and an explicit "*" wildcard.
How the fix works
- src/com/android/providers/media/util/SQLiteQueryBuilder.java:enforceStrictColumns(String[]) is made public so MediaProvider can run strict column validation before any redaction logic.
- src/com/android/providers/media/MediaProvider.java:queryInternal lowercases the projection and calls qb.enforceStrictColumns(projection) right away. Per the commit message, this rejects comma-separated projections and invalid space-containing aliases when strict columns are enabled. It then always runs maybeReplaceNullProjection, so a null projection is expanded to all projection-map columns before filtering.
- src/com/android/providers/media/MediaProvider.java:maybeReplaceNullProjection now also expands an explicit "*" element in place to all projection-map columns for callers with targetSdkVersion < Q, and disables strict columns for that query. Wildcard results therefore go through the same redaction.
- src/com/android/providers/media/MediaProvider.java:queryInternal no longer gates on hasColumnsToFilterInProjection, which is removed. It builds a columnsToFilter list and calls updateProjectionToFilterColumns once. The list holds OEM_METADATA when Flags.enableOemMetadata() is on and the caller lacks the OEM permission, and LATITUDE and LONGITUDE when indexMediaLatitudeLongitude() is on and the caller is not MediaProvider itself.
- src/com/android/providers/media/MediaProvider.java:updateProjectionToFilterColumns is rewritten to visit every element. For each one it strips a DISTINCT/ALL prefix, then splits the expression from the alias with splitProjection (ALIAS_PATTERN " (?:as )?([_a-z0-9]+)$"). It tests the expression with containsWord, using the precompiled case-insensitive \bcolumn\b patterns in FILTER_COLUMN_PATTERNS. On a match, constructNullProjectionForExpression replaces the element with "null as <alias>", "null as <column>" or "null as \"<escaped expr>\"". The prefix is added back and the new element is registered in qb's projection allowlist. Because every element is checked, repeated columns and aggregate wrappers are redacted.
- src/com/android/providers/media/MediaProvider.java (query setup near line 6766): qb.setProjectionAllowlist(new ArrayList<>(sAllowlist)) copies the static legacy allowlist for each query. The per-query allowlist additions above therefore do not reach the shared static list.
- tests/src/com/android/providers/media/MediaProviderTest.java adds two tests. testQueryingMediaGeolocationData_returnsNull checks that repeated and aggregate columns return null. testQueryingMediaGeolocationDataBypasses_throwsException checks that aliased, comma-separated and DISTINCT/ALL forms throw IllegalArgumentException.
Completeness
- Covers projection elements only: the exact column, repeated columns, expressions that contain the column name as a whole word (aggregates), an optional DISTINCT/ALL prefix, a trailing alias with or without AS, a null projection, and an explicit "*" for callers with targetSdk < Q.
- Detection is regex based (\bcolumn\b on the expression part). Any element that reaches the filter with the column name present as a whole word is nulled, so the mechanism is a denylist on names rather than a parse of the SQL expression. For strict-column callers, the early enforceStrictColumns rejection is the first barrier.
- "*" is only expanded for callers with targetSdkVersion < Q. For newer callers, "*" is left to strict column enforcement.
- The Android 16 commit redacts only LATITUDE, LONGITUDE and OEM_METADATA (Android 17 also handles _SPECIAL_FORMAT). The owner package name filter in the same function (shouldFilterOwnerPackageNameInProjection) is not touched by this change, and its matching logic is not shown.
- Redaction applies to the projection only. The diff does not change how selection, sort order or group-by clauses are handled. An existing test suggests selection is handled separately, but that code is not in the material.
Behavior changes
- Strict column validation now runs before redaction. For strict-column callers, invalid projection elements (comma-separated, aliased with spaces, DISTINCT-prefixed) throw IllegalArgumentException; the tests assert this for targetSdk >= Q.
- Redacted columns are emitted as "null as <alias>" (lowercase, alias kept) instead of "NULL AS <column>". An unaliased bare column becomes "null as <column>". Other unaliased expressions become "null as \"<escaped expr>\"".
- Null projections are always expanded via maybeReplaceNullProjection in the redaction path. For targetSdk < Q callers, "*" is expanded to all projection-map columns and strict columns are disabled for that query.
- The caller's projection array is lowercased in place. A copy of sAllowlist is passed to the query builder, so per-query allowlist additions do not reach the static list.
Per major
- Android 14: Not affected per the bulletin. 0/8 patched-region lines present at android-security-14.0.0_r31.
- Android 15: Not affected per the bulletin. 0/8 patched-region lines present at android-security-15.0.0_r19.
- Android 16: Same fix: commit 8c2db23d64e2 (RESTRICT AUTOMERGE, cherry-pick of 660116175a31) in android-security-16.0.0_r10. Covers LATITUDE, LONGITUDE and OEM_METADATA.
- Android 17: Adapted fix: commit 25db6ac2f79e in android-security-17.0.0_r3. Same mechanism, with these differences: the projection lowercasing already existed; _SPECIAL_FORMAT is added to columnsToFilter and FILTER_COLUMN_PATTERNS; the pre-fix code already added per-query allowlist entries, so the sAllowlist copy also addresses an existing leak there; and splitProjection/targetProjection use projElement rather than the prefix-stripped cleaned string.
Unknowns
- The material does not show where, or for which callers, qb.setStrictColumns(true) is set. The commit message says it is enabled for all non-system callers.
- The implementation of shouldFilterOwnerPackageNameInProjection, and any selection or sort-order redaction for these columns, is not shown.
- It is not shown which legacy (targetSdk < Q) allowlisted projection expressions reach the regex filter.
- The existing test testQueryingMediaGeolocationDataInProjectionShouldReturnNull (which includes "latitude AS LAT") still appears in the context. How it coexists with the new test that expects an exception for aliased forms is not shown.