Repository navigation
[2.19] Handle null field name in DlsFlsFilterLeafReader.isMasked - #6806
Conversation
A _geo_distance sort with a non-default unit as the first sort key makes Lucene call getPointValues with a null field name. On 2.19, isMasked passed that null to the masked-field matchers and to String.endsWith, which threw a NullPointerException and failed the search with HTTP 500. DlsFlsFilterLeafReader wraps every search, so this affected users without any DLS, FLS or field masking too. isMasked now treats a null field name as masked, so the reader reports no values for it, the same as the FLS check already does. main handles this through normalizeFieldName (opensearch-project#5537), which does not exist on 2.19. Resolves opensearch-project#6803 Signed-off-by: Dhruv Srikanth <dhruvsrk@amazon.com>
56e56ad to
a4af4f6
Compare
PR Reviewer Guide 🔍(Review updated until commit b0d4c09)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit a4af4f6 |
Covers a user whose roles have no DLS, FLS or masking rules, which matches the reported case. Signed-off-by: Dhruv Srikanth <dhruvsrk@amazon.com>
|
Persistent review updated to latest commit 7a6c26e |
Any _geo_distance sort that does not use Lucene's built-in distance sort (a non-meter unit, descending order, several origin points) builds a comparator with a null field name. Add descending and two-point cases, and terms aggregations with missing values, which do not reach the null path on 2.19. Signed-off-by: Dhruv Srikanth <dhruvsrk@amazon.com>
|
Persistent review updated to latest commit 9fb4037 |
The null field name comes from any _geo_distance sort that does not use Lucene's built-in distance sort, not only one with a unit. Signed-off-by: Dhruv Srikanth <dhruvsrk@amazon.com>
|
Persistent review updated to latest commit b0d4c09 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.19 #6806 +/- ##
==========================================
- Coverage 68.49% 68.49% -0.01%
==========================================
Files 348 348
Lines 24821 24823 +2
Branches 4141 4142 +1
==========================================
+ Hits 17002 17003 +1
- Misses 5890 5893 +3
+ Partials 1929 1927 -2
🚀 New features to boost your workflow:
|
|
I noticed that the earlier fixes for this NPE (#5504, #5537) guarded against a null field name but left its source open. #5537's comment notes that "OpenSearch code calls diverse LeafReader methods with a null field param" and that "the semantics are not quite clear". I had an agent trace it, and the null comes from OpenSearch core, in code inherited from Elasticsearch 7.10 and kept through OpenSearch's Lucene 9.1 upgrade (opensearch-project/OpenSearch#2487). I believe a one-line fix in core would stop the null from reaching reader wrappers in the first place, rather than only guarding against it in the security plugin. In - return new DoubleComparator(numHits, null, null, reversed, filterPruning(pruning)) {
+ return new DoubleComparator(numHits, null, null, reversed, Pruning.NONE) {How the null reaches the security plugin
What I think happened
With a null field, skipping never actually happens for this comparator, so the change shouldn't affect sort results; it only stops the null calls. I've tested it locally. Does it make sense to open an issue on opensearch-project/OpenSearch and raise a PR for it? |
|
#6803 claims there is a second latent NPE in |
Description
On 2.19, some
_geo_distancesorts fail on every shard with HTTP 500 (Cannot invoke "String.endsWith(String)" because "field" is null), for example a sort with"unit": "mi"as the first sort key ([BUG] NullPointerException in DlsFlsFilterLeafReader.isMasked when sorting by _geo_distance with field masking active #6803). For these sorts, OpenSearch asks the index reader for point values with a null field name.DlsFlsFilterLeafReaderpasses that null toisMasked, which callsfield.endsWith(...)on it. The reader wraps every search on 2.19, so users without any DLS, FLS or masking rules (for exampleall_access) are affected too.mainis already fixed by Handle cases gracefully where null field name is passed to LeafReader methods #5537, but that change can't be applied to 2.19 because the classes it edits don't exist there.Before: HTTP 500. After:
isMaskedtreats a null field name as masked, sogetPointValues(null)returns null ("no point values"), the same answer Lucene's own reader gives. The search succeeds with the same results. Behavior for real field names doesn't change.Issues Resolved
Resolves #6803
Is this a backport? No. This is a 2.19-only fix;
mainis already covered by #5537.Do these changes introduce new permission(s) to be displayed in the static dropdown on the front-end? No, no new permissions are introduced.
Testing
New integration test
GeoDistanceSortWithFieldMaskingIntegrationTest. It indexes three documents at known distances and runs each query as six users:all_access; read only; masked fieldowner; masked fieldown*.~statusand maskedowner;location,ownerand maskedowner._geo_distancesortunit: mi, first sort keyorder: desc, nounitunitunit: mi, second sort keyunitFor each 200, the test also checks hit order, sort distances, masked values and FLS visibility. It also runs
termsaggregations withmissing, which caused the same error on 3.0; they pass before and after on 2.19.The existing unit tests matching
*DlsFlsFilterLeafReader*,*FieldMasking*,*Fls*and*Dls*, the existing integration tests matching*Fls*,*Dls*and*Masking*, and spotless all pass with this change.Check List
The documentation, security dashboards plugin PR and API changes companion PR checklist items were removed because they do not apply: this is a bug fix with no user-facing documentation change, no new permissions and no request/response schema changes.
AI Usage
This change was developed with AI assistance (Kiro). The author directed the approach, reviewed every line, and verified behavior with the tests described above.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.