fix: Prevent NPE in OSQueryBackend when fieldMappings is null - #1790
Open
nagendramohan wants to merge 1 commit into
Open
Conversation
When creating a detector for a Sigma rule with an aggregation expression, ruleFieldMappings.get(category) can return null if the log type has no field mappings defined. This null was passed directly to the OSQueryBackend constructor, which stored it as-is when enableFieldMappings=true. Subsequent calls to getMappedField() then threw NullPointerException on this.fieldMappings.containsKey(field). Fix: Initialize fieldMappings to an empty HashMap when the provided map is null (in QueryBackend constructor). Also adds a null guard in getMappedField() as defense-in-depth. When fieldMappings is empty/null, fields pass through unmapped — the aggregation query uses the original Sigma field names, which is the correct degraded behavior. Resolves opensearch-project#1750 Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
nagendramohan
requested review from
AWSHurneyt,
KashKondaka,
amsiglan,
eirsep,
engechas,
getsaurabh02,
goyamegh,
lezzago,
manaswini1920,
nishtham-amazon,
riysaxen-amzn,
toepkerd and
vikhy-aws
as code owners
August 14, 2026 08:35
Contributor
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Author
|
Gentle bump 🙂 — small fix + tests for the NPE in QueryBackend/getMappedField when an aggregation detector has enableFieldMappings=true but fieldMappings is null (#1750). Would appreciate a maintainer review when there's bandwidth; happy to iterate on feedback. Thanks! |
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.
When creating a detector for a Sigma rule with an aggregation expression, ruleFieldMappings.get(category) can return null if the log type has no field mappings defined. This null was passed directly to the OSQueryBackend constructor, which stored it as-is when enableFieldMappings=true. Subsequent calls to getMappedField() then threw NullPointerException on this.fieldMappings.containsKey(field).
Fix: Initialize fieldMappings to an empty HashMap when the provided map is null (in QueryBackend constructor). Also adds a null guard in getMappedField() as defense-in-depth.
When fieldMappings is empty/null, fields pass through unmapped — the aggregation query uses the original Sigma field names, which is the correct degraded behavior.
Resolves #1750
Description
When creating a detector for a Sigma rule with an aggregation expression (e.g., count(field) > N), ruleFieldMappings.get(category) returns null if the log type has no field mappings defined. This null was passed to OSQueryBackend, causing a NullPointerException at this.fieldMappings.containsKey(field) in getMappedField().
Fix: Initialize fieldMappings to an empty HashMap when the provided map is null (in QueryBackend constructor). Also adds a null guard in getMappedField() as defense-in-depth. When mappings are unavailable, fields pass through unmapped — the correct degraded behavior.
Related Issues
Resolves #1750
Testing
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.