Skip to content

Commit 01492ff

Browse files
committed
chore: adding disable ignore flag
1 parent 064fb7d commit 01492ff

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed

docs/cli-reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ socketcli [-h] [--api-token API_TOKEN] [--repo REPO] [--workspace WORKSPACE] [--
151151
[--excluded-ecosystems EXCLUDED_ECOSYSTEMS] [--default-branch] [--pending-head] [--generate-license] [--enable-debug]
152152
[--enable-json] [--enable-sarif] [--sarif-file <path>] [--sarif-scope {diff,full}] [--sarif-grouping {instance,alert}] [--sarif-reachability {all,reachable,potentially,reachable-or-potentially}] [--enable-gitlab-security] [--gitlab-security-file <path>]
153153
[--disable-overview] [--exclude-license-details] [--allow-unverified] [--disable-security-issue]
154-
[--ignore-commit-files] [--disable-blocking] [--enable-diff] [--scm SCM] [--timeout TIMEOUT] [--include-module-folders]
154+
[--ignore-commit-files] [--disable-blocking] [--disable-ignore] [--enable-diff] [--scm SCM] [--timeout TIMEOUT] [--include-module-folders]
155155
[--reach] [--reach-version REACH_VERSION] [--reach-timeout REACH_ANALYSIS_TIMEOUT]
156156
[--reach-memory-limit REACH_ANALYSIS_MEMORY_LIMIT] [--reach-ecosystems REACH_ECOSYSTEMS] [--reach-exclude-paths REACH_EXCLUDE_PATHS]
157157
[--reach-min-severity {low,medium,high,critical}] [--reach-skip-cache] [--reach-disable-analytics] [--reach-output-file REACH_OUTPUT_FILE]
@@ -306,6 +306,7 @@ The CLI will automatically install `@coana-tech/cli` if not present. Use `--reac
306306
|:-------------------------|:---------|:--------|:----------------------------------------------------------------------|
307307
| `--ignore-commit-files` | False | False | Ignore commit files |
308308
| `--disable-blocking` | False | False | Disable blocking mode |
309+
| `--disable-ignore` | False | False | Disable support for `@SocketSecurity ignore` commands in PR comments. When set, alerts cannot be suppressed via comments and ignore instructions are hidden from comment output. |
309310
| `--strict-blocking` | False | False | Fail on ANY security policy violations (blocking severity), not just new ones. Only works in diff mode. See [Strict Blocking Mode](#strict-blocking-mode) for details. |
310311
| `--enable-diff` | False | False | Enable diff mode even when using `--integration api` (forces diff mode without SCM integration) |
311312
| `--scm` | False | api | Source control management type |

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.80"
9+
version = "2.2.81"
1010
requires-python = ">= 3.11"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.80'
2+
__version__ = '2.2.81'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class CliConfig:
9191
files: str = None
9292
ignore_commit_files: bool = False
9393
disable_blocking: bool = False
94+
disable_ignore: bool = False
9495
strict_blocking: bool = False
9596
integration_type: IntegrationType = "api"
9697
integration_org_slug: Optional[str] = None
@@ -201,6 +202,7 @@ def from_args(cls, args_list: Optional[List[str]] = None) -> 'CliConfig':
201202
'files': args.files,
202203
'ignore_commit_files': args.ignore_commit_files,
203204
'disable_blocking': args.disable_blocking,
205+
'disable_ignore': args.disable_ignore,
204206
'strict_blocking': args.strict_blocking,
205207
'integration_type': args.integration,
206208
'pending_head': args.pending_head,
@@ -693,6 +695,19 @@ def create_argument_parser() -> argparse.ArgumentParser:
693695
action="store_true",
694696
help=argparse.SUPPRESS
695697
)
698+
advanced_group.add_argument(
699+
"--disable-ignore",
700+
dest="disable_ignore",
701+
action="store_true",
702+
help="Disable support for @SocketSecurity ignore commands in PR comments. "
703+
"Alerts cannot be suppressed via comments when this flag is set."
704+
)
705+
advanced_group.add_argument(
706+
"--disable_ignore",
707+
dest="disable_ignore",
708+
action="store_true",
709+
help=argparse.SUPPRESS
710+
)
696711
advanced_group.add_argument(
697712
"--strict-blocking",
698713
dest="strict_blocking",

socketsecurity/core/messages.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,8 @@ def security_comment_template(diff: Diff, config=None) -> str:
816816
<tbody>
817817
"""
818818

819+
show_ignore = not (config and getattr(config, 'disable_ignore', False))
820+
819821
# Loop through security alerts (non-license), dynamically generating rows
820822
for alert in security_alerts:
821823
severity_icon = Messages.get_severity_icon(alert.severity)
@@ -842,10 +844,10 @@ def security_comment_template(diff: Diff, config=None) -> str:
842844
<a href="https://socket.dev/alerts/malware">What is known malware?</a></p>
843845
<blockquote>
844846
<p><em>Suggestion:</em> {alert.suggestion}</p>
845-
<p><em>Mark as acceptable risk:</em> To ignore this alert only in this pull request, reply with:<br/>
847+
{f"""<p><em>Mark as acceptable risk:</em> To ignore this alert only in this pull request, reply with:<br/>
846848
<code>@SocketSecurity ignore {alert.pkg_name}@{alert.pkg_version}</code><br/>
847849
Or ignore all future alerts with:<br/>
848-
<code>@SocketSecurity ignore-all</code></p>
850+
<code>@SocketSecurity ignore-all</code></p>""" if show_ignore else ""}
849851
</blockquote>
850852
</details>
851853
</td>
@@ -890,7 +892,7 @@ def security_comment_template(diff: Diff, config=None) -> str:
890892
<blockquote>
891893
<p><em>Next steps:</em> Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at <strong>support@socket.dev</strong>.</p>
892894
<p><em>Suggestion:</em> Find a package that does not violate your license policy or adjust your policy to allow this package's license.</p>
893-
<p><em>Mark the package as acceptable risk:</em> To ignore this alert only in this pull request, reply with the comment <code>@SocketSecurity ignore {first_alert.pkg_name}@{first_alert.pkg_version}</code>. You can also ignore all packages with <code>@SocketSecurity ignore-all</code>. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.</p>
895+
{f'<p><em>Mark the package as acceptable risk:</em> To ignore this alert only in this pull request, reply with the comment <code>@SocketSecurity ignore {first_alert.pkg_name}@{first_alert.pkg_version}</code>. You can also ignore all packages with <code>@SocketSecurity ignore-all</code>. To ignore an alert for all future pull requests, use Socket\'s Dashboard to change the triage state of this alert.</p>' if show_ignore else ""}
894896
</blockquote>
895897
</details>
896898
</td>

socketsecurity/socketcli.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -486,21 +486,27 @@ def main_code():
486486
# 3. Updates the comment to remove ignored alerts
487487
# This is completely separate from the main scanning functionality
488488
log.info("Comment initiated flow")
489-
490-
comments = scm.get_comments_for_pr()
491-
log.debug("Removing comment alerts")
492-
scm.remove_comment_alerts(comments)
489+
490+
if not config.disable_ignore:
491+
comments = scm.get_comments_for_pr()
492+
log.debug("Removing comment alerts")
493+
scm.remove_comment_alerts(comments)
494+
else:
495+
log.info("Ignore commands disabled (--disable-ignore), skipping comment processing")
493496

494497
elif scm is not None and scm.check_event_type() != "comment" and not force_api_mode:
495498
log.info("Push initiated flow")
496499
if scm.check_event_type() == "diff":
497500
log.info("Starting comment logic for PR/MR event")
498501
diff = core.create_new_diff(scan_paths, params, no_change=should_skip_scan, save_files_list_path=config.save_submitted_files_list, save_manifest_tar_path=config.save_manifest_tar, base_paths=base_paths, explicit_files=sbom_files_to_submit)
499502
comments = scm.get_comments_for_pr()
500-
log.debug("Removing comment alerts")
501-
503+
502504
# FIXME: this overwrites diff.new_alerts, which was previously populated by Core.create_issue_alerts
503-
diff.new_alerts = Comments.remove_alerts(comments, diff.new_alerts)
505+
if not config.disable_ignore:
506+
log.debug("Removing comment alerts")
507+
diff.new_alerts = Comments.remove_alerts(comments, diff.new_alerts)
508+
else:
509+
log.info("Ignore commands disabled (--disable-ignore), all alerts will be reported")
504510
log.debug("Creating Dependency Overview Comment")
505511

506512
overview_comment = Messages.dependency_overview_template(diff)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)