Skip to content

fix: [website/history] use identity check for session node index - #875

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/067-history-loc-truthiness
Open

fix: [website/history] use identity check for session node index#875
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/067-history-loc-truthiness

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026

Copy link
Copy Markdown
Member

The session history "remove node" flow silently no-ops when the matched node is the very first entry in the session's ordered key list:

    if loc:
        del sess[keys_list[i]]

loc holds the index of the matched node, and index 0 is falsy in Python, so if loc: skips the delete precisely when the match is at position 0 — even though loc was correctly set (as opposed to its None initial value meaning "no match").

Impact on an analyst: deleting the first node/session shown in the MISP-modules history tree appears to succeed (the UI reports "Node deleted") but the entry is never actually removed from the underlying session dict, leaving stale/duplicate history state.

Fix: check identity against the sentinel instead of truthiness — if loc is not None: — so index 0 is correctly treated as a valid match while None ("no match found") still skips the delete.

This is a pure bug fix with no behaviour change for any non-zero match.

Verification

  • python -m py_compile website/app/history/history_core.py — clean.
  • website/ has no automated test coverage in this repository; verification was py_compile plus running the module test suite, which still passes: 161 passed, 4 skipped, 5 subtests passed in 35.18s.

Found during a review of the repository; other findings are being submitted as separate PRs.

🤖 Generated with Claude Code

https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8

remove_node_session locates a matching node's index in the session key
list and stores it in loc, then guards the delete with `if loc:`. When
the match is the very first key, loc is 0, which is falsy in Python, so
the truthiness check skips the deletion entirely while the calling route
still reports success ("Node deleted"). The node silently remains in the
session-stored history tree.

Verified with the full misp-modules test suite against a live modules
server on port 6767: 161 passed, 4 skipped, 5 subtests passed, matching
the documented baseline.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant