fix: guard against null and immutable map returns in RuleIndices and CustomLogType - #1797
Conversation
PR Reviewer Guide 🔍(Review updated until commit 05e0744)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 05e0744
Previous suggestionsSuggestions up to commit 57f2bfb
|
…CustomLogType Signed-off-by: thecodingshrimp <leonard.stutzer@sap.com>
57f2bfb to
05e0744
Compare
|
Persistent review updated to latest commit 05e0744 |
Summary
fixes #1796
Two defensive guards for null/immutable map returns found during a code audit.
These are independent bugs; no upstream issue existed prior to this PR.
Finding 1 — NPE in
RuleIndices.ingestQueries()(HIGH)File:
src/main/java/org/opensearch/securityanalytics/util/RuleIndices.java, line 290LogTypeService.getRuleFieldMappingsForBuiltinLogType()returnsnullwhen thelog type is not registered in
builtinLogTypeLoader. That null is passed directlyinto
OSQueryBackend's constructor, which stores it asthis.fieldMappingswhen
enableFieldMappings=true.getMappedField()then callsthis.fieldMappings.containsKey(field)unconditionally, causing aNullPointerExceptionduring pre-packaged rule ingestion at startup for anyunrecognized rule category.
Before:
After:
Finding 2 — UnsupportedOperationException in
CustomLogType(StreamInput)(MEDIUM)File:
src/main/java/org/opensearch/securityanalytics/model/CustomLogType.java, line 96StreamInput.readMap()returnsCollections.emptyMap()(Java's immutable singleton)when the serialized map has zero entries.
CustomLogTypestores this value directlyas
this.tags. Any subsequent call togetTags().put(...)throwsUnsupportedOperationException.Before:
After:
Finding 3 — Reviewed, no action (LOW / informational)
LogTypeService.javalines 656 and 791 returnMap.of()for empty field-mappingresponses. All call sites are read-only (
.containsKey(),.get()). No fix required.Testing
TransportIndexDetectorAction.javais not modified in this PR.