Skip to content

Stop failing issue_comment runs that have no ignore command - #464

Draft
David Larsen (dc-larsen) wants to merge 5 commits into
mainfrom
fix/issue-comment-keyerror
Draft

David Larsen (dc-larsen) wants to merge 5 commits into
mainfrom
fix/issue-comment-keyerror

Conversation

@dc-larsen

@dc-larsen David Larsen (dc-larsen) commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

With --scm github, an issue_comment run on a pull request that already has a Socket security comment exits 3 for any ordinary comment:

Comment initiated flow
Unexpected error when running the CLI: 'ignore'
Traceback (most recent call last):
  ...
KeyError: 'ignore'
exit=3

Only a comment that starts with @SocketSecurity ignore from someone with write access avoids it. The example workflow (workflows/github-actions.yml) subscribes to issue_comment, so every "LGTM" or review reply on a pull request with Socket alerts produces a failed Socket job. Found while verifying 2.13.0 against real pull request scans. The unguarded lookup dates back to the first releases; 2.13.0 reports it as exit 3.

Root Cause

Comments.check_for_socket_comments only adds an "ignore" key when the pull request has at least one honored ignore command. Github.remove_comment_alerts (and the GitLab equivalent) called Comments.process_security_comment whenever a security comment existed, and Comments.get_ignore_options read comments["ignore"] directly. With no ignore command, that lookup raised KeyError, which the CLI reports as an unexpected error (exit 3). An ignore command rejected by the write-access gate (#302) leaves the same shape, so it crashed too.

Fix

  • remove_comment_alerts (GitHub and GitLab) returns early when there are no ignore commands: it logs No @SocketSecurity ignore commands on this pull request; security comment left unchanged and makes no API call. Rewriting the security comment with no commands would only re-normalize it, so leaving it alone is the safer no-op.
  • get_ignore_options treats a missing "ignore" key as no commands, so any other caller gets (False, []) instead of a crash.
  • Exit 0 for these runs follows the README contract: no findings were evaluated and nothing failed.
  • @SocketSecurity ignore <pkg>, ignore-all, malformed commands and --disable-ignore take the same path as before. GitLab never reports an issue_comment pipeline source, so its comment flow is reachable only by configuration; it gets the same guard for consistency.

Not changed (separate issues, noticed while testing):

  • Github.comment_reaction_exists compares content to ":thumbsup:", but the API returns "+1", so the check never matches. GitHub de-duplicates a user's identical reaction, so the visible effect is one extra API call per ignore comment per run.
  • get_comments_for_pr reads only the first page of comments (30), so an ignore command past the 30th comment is not seen.

Tests

  • tests/unit/test_comment_event_flow.py (new, 20 cases). Full cli() runs for an issue_comment event: ordinary comments (plain, empty, mentions @SocketSecurity without ignore) exit 0 with no comment update, reaction or telemetry; no security comment exits 0; ignore npm/lodash@... removes only that row, adds the reaction and sends one telemetry event; ignore-all replaces the table with the no-alerts body; --disable-ignore never reads comments; an ignore command from a commenter without write access is dropped without crashing; four malformed commands keep every row. Unit cases cover get_ignore_options({}) and remove_comment_alerts on both adapters with and without ignore commands. 8 of the 20 fail on main with KeyError: 'ignore'.
  • Full suite with all Socket API key variables unset: uv run pytest -q tests/unit/ tests/core/: 1021 passed (1001 on main). uv run ruff check, uv lock --locked --offline, git diff --check and uv build pass.
  • End to end against a test org, with real comments on a throwaway private pull request (npm: lodash 4.17.11 + handlebars 4.0.11 on the default branch; the pull request adds vm2 3.9.11), emulating the example workflow with --scm github --strict-blocking. Before = 2.13.0 from PyPI; after = this branch's wheel. For the ignore cases, both versions ran from the same starting security comment (38 alert rows), restored between runs:
Comment on the pull request 2.13.0 This branch
LGTM, thanks exit 3, KeyError: 'ignore' exit 0, comment unchanged (updated_at unchanged), run twice
LGTM, thanks + --disable-ignore exit 0, skipped same
@SocketSecurity ignore vm2 (no version) exit 0, logs "Unable to process ignore command", 38 rows kept same, identical comment body
@SocketSecurity ignore (no package) exit 0, 38 rows kept same, identical comment body
@SocketSecurity ignore npm/vm2@3.9.11 exit 0, 35 vm2 rows removed (3 left), +1 reaction same, identical comment body
@SocketSecurity ignore-all exit 0, 0 rows, +1 reaction same, identical comment body

Other open 2.13.x fixes

2.13.1 and 2.13.2 were released from main on 2026-11-20, so this branch merges main at v2.13.2 and bumps to 2.13.3 in pyproject.toml, socketsecurity/__init__.py and uv.lock, with its CHANGELOG entries under a new ## 2.13.3 heading. #459, #460, #461, #462, #463, #464 and #465 all make the same bump, so the version files merge cleanly between them, and once one merges the rest ride main's unreleased 2.13.3 (Version Check accepts a version equal to main's while it is above the latest PyPI release). Merging a second one conflicts only in CHANGELOG.md: keep one ## 2.13.3 heading and combine the bullets under its subsections (Upgrade notes, Changed, Fixed, Documentation, in that order). There are no code conflicts between them. If main releases 2.13.3 before this merges, bump to the next patch again. This branch and #460 both edit scm/github.py and scm/gitlab.py; those merge cleanly.

Public Changelog

With --scm github, an ordinary comment on a pull request that has a Socket security comment no longer fails the Socket job with exit 3. The comment run now exits 0 and leaves the security comment unchanged.

An issue_comment run on a pull request that already has a Socket security
comment crashed with KeyError: 'ignore' and exited 3 unless the pull request
also had an honored @SocketSecurity ignore command. check_for_socket_comments
only adds the "ignore" key when such a command exists, but
remove_comment_alerts called process_security_comment whenever the security
comment existed, and get_ignore_options indexed comments["ignore"] directly.
Any ordinary comment, or an ignore command from someone without write
access, failed the job.

remove_comment_alerts (GitHub and GitLab) now returns early and leaves the
security comment untouched when there are no ignore commands, and
get_ignore_options treats a missing key as no commands. Ignore, ignore-all
and --disable-ignore behave as before.

This branch was successfully deployed

1 active deployment
socket-firewall — a4bcf0b1 Deployed Nov 20, 2026 by dc-larsen via python-sfw-smoke-enterprise #666
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