Skip to content

[bug] normalise: map iteration causes non-deterministic canonical text for structured payloads #48

@RachanaB5

Description

@RachanaB5

Summary

payloadText in normalise.go processes structured payloads (map[string]any) by iterating over the map and concatenating string values. Because Go map iteration order is non-deterministic, the same input can produce different CanonicalText values across runs.


Example

Input:

{
  "name": "shell",
  "args": "rm -rf /"
}

Possible Output A:

"shell rm -rf /"

Possible Output B:

"rm -rf / shell"

The output depends entirely on Go's random map iteration order at runtime.


Root Cause

Go's map iteration order is intentionally randomised. Iterating over a map[string]any and concatenating values without first sorting the keys produces output that varies between runs, even for identical inputs.


Why This Is an Issue

Area Impact
Canonical Text Identical inputs produce different CanonicalText values
Scan Behaviour Detection becomes non-deterministic
Aho-Corasick Matching Patterns may match in one run and silently fail in another
Signals & Scores Results become inconsistent and unreliable
Reproducibility Bugs are difficult to reproduce and investigate
Multi-field Patterns Patterns spanning multiple fields are especially vulnerable

Expected vs. Actual Behaviour

Behaviour
Expected Same input → Same CanonicalText (every run)
Actual Same input → Different CanonicalText (random map iteration)

Severity

Medium–High

  • Directly affects correctness and reliability of detection logic
  • Can cause inconsistent outcomes for identical inputs in security-sensitive scenarios
  • Produces flaky signals, scores, and decisions that are hard to debug or reproduce

Affected File

  • normalise.gopayloadText function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions