Skip to content

[BUG/CORE-ENGINE] security_lens results silently clobber detector.py's spatially-corroborated sec_tainted_injection count #344

Closed

Description

@squid-protocol

🛑 Problem Statement

detector.py's coding_analysis() spatially corroborates RCE risk by correlating sec_high_risk_execution against sec_io/io hits within a 250-character radius, writing the result into counts["sec_tainted_injection"] (detector.py:1004-1013). Separately, security_lens.py::scan_content() runs its own, independent variable-echo taint check and produces its own tainted_injection count.

galaxyscope.py merges the two at lines 425-426:

for sec_key, hit_count in sec_results["counts"].items():
    logic_data["equations"][f"sec_{sec_key}"] = hit_count

This is a plain assignment (=), not additive, and it runs after coding_analysis() has already populated equations["sec_tainted_injection"]. Because security_lens.py's own tainted_injection count gets the same sec_ prefix applied, it silently overwrites whatever detector.py's proximity-based corroboration computed for the same key, on every non-inert file. One of the two spatial-correlation systems' output is discarded every time, with no error or warning.

Found while scoping #102/#105/#106 — both of those tickets propose feeding new deterministic signals into _calc_injection_surface following the exact pattern sec_tainted_injection already uses (signal_processor.py's "+500 gravity spike" for confirmed taint). That pattern isn't trustworthy until this collision is fixed.

🎯 Objective

Ensure both spatial-correlation systems' contributions to RCE/injection corroboration survive the merge, instead of one silently discarding the other.

🛠️ Proposed Implementation

Pick one explicitly, rather than leave the collision:

  • Keep sec_tainted_injection as detector.py's proximity-based count, and give security_lens.py's variable-echo result its own key (e.g. sec_variable_taint) instead of colliding on the same name, or
  • Merge additively (+=) instead of overwriting, if the two are meant to represent the same conceptual signal.

Whichever is chosen, update _calc_injection_surface (and any other consumer of sec_tainted_injection) to read the correct key(s).

✅ Acceptance Criteria

  • equations["sec_tainted_injection"] (or its renamed successor) reflects both systems' findings, not just whichever ran last.
  • A regression test exercises a file that would trigger both detector.py's proximity check and security_lens.py's variable-echo check, and asserts neither result is silently dropped.
  • signal_processor.py's _calc_injection_surface (and any other reader) is updated to match the resolved key(s).

Blocks trust in the "amplified" signal pattern that #105 and #106 both build on. Part of #102.

Activity

  1. added
    bug
    appsec
    core-engine
    on Jul 24, 2026
  2. squid-protocol commented on Jul 24, 2026

    @squid-protocol
    OwnerAuthor

    Correction to the diagnosis above, found while implementing this — the actual bug is more fundamental than a merge overwrite.

    Every sec_-prefixed key is explicitly the "PASSIVE SECURITY LENS OBSERVERS" section of SIGNAL_SCHEMA (analysis_lens.py:1165-1180) — by design, only ever meant to be populated from security_lens.py, merged in during galaxyscope.py's Phase 5.5, which runs after detector.splice() (and the coding_analysis() call inside it) has already returned.

    But detector.py's "1. Taint Tracking (RCE Weaponization)" block (detector.py:1005) and "4. The Active Hemorrhage" block (detector.py:1042) check spatial_map — a dict local to a single coding_analysis() call, populated only from that function's own per-language regex rules — for sec_high_risk_execution / sec_hardcoded_secrets. Those keys can never appear in spatial_map: nothing in coding_analysis()'s own rule set produces a sec_-prefixed name, and the one thing that does hasn't run yet at this point in the pipeline. Both conditions are permanently False — these are dead, unreachable blocks, not a real value that gets overwritten. Detector.py's own contribution to sec_tainted_injection/sec_hardcoded_secrets's amplification has always been exactly 0.

    The = vs += merge overwrite is still real, but it's the second half of the bug, not the first: detector.py's own rules do populate the correct unprefixed keys (high_risk_execution, io, hardcoded_secrets) in spatial_map. Once the dead blocks are pointed at the keys that actually exist, they'll start writing real values into sec_tainted_injection/sec_hardcoded_secrets — and that's when the unconditional = in the galaxyscope.py merge would immediately erase them again with security_lens.py's independent count.

    Revised fix, both parts required together:

    1. Point the two dead blocks in detector.py::coding_analysis() at the keys that are actually present at that stage (high_risk_execution/io for block 1, hardcoded_secrets for block 4).
    2. Make the galaxyscope.py Phase 5.5 merge additive instead of an unconditional overwrite, so security_lens.py's independent corroboration adds to detector.py's now-real contribution instead of replacing it.

    Implementing both together now.

  3. squid-protocol commented on Jul 24, 2026

    @squid-protocol
    OwnerAuthor

    Opened PR #347 with the corrected fix (both parts: the dead-key guard in detector.py, and the additive merge in galaxyscope.py). Block 4 (sec_hardcoded_secrets) is intentionally left dead in this PR, annotated in place, since it genuinely needs #346's correlate-after-both-phases fix rather than a key-name correction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    appsecbugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions