Skip to content

insights: identify triggering insight on stop#7366

Open
msrivas-7 wants to merge 3 commits into
zaproxy:mainfrom
msrivas-7:insights-abort-reason
Open

insights: identify triggering insight on stop#7366
msrivas-7 wants to merge 3 commits into
zaproxy:mainfrom
msrivas-7:insights-abort-reason

Conversation

@msrivas-7
Copy link
Copy Markdown
Contributor

@msrivas-7 msrivas-7 commented May 18, 2026

What

When the Insights add-on stops a scan via exitAutoOnHigh, identify the triggering insight in every headless artefact (AF progress, daemon exit reason, report data, rendered reports).

Fixes zaproxy/zaproxy#9340.

Changes

insights add-on

  • AF progress warning (InsightsJob.recordInsight): insights.automation.stopplan now takes the insight's key, reason, site, and statistic.
    • Before: Insights stopping plan due to High Level Insight
    • After: Insights stopping plan due to High Level Insight: insight.auth.failure (Exceeded High) on https://example.com = 75 %
    • Empty site falls back to a <global> label via insights.automation.stopplan.site.global.
  • Daemon exit reason (ExtensionInsights.recordInsight): setExitStatus(2, …) now appends the insight identifiers (LEVEL : REASON : SITE : KEY : STATISTIC). Stays non-localized — good for log scraping. Exit code unchanged.
    • After: Shutting down ZAP due to High Level Insight: HIGH : EXCEEDED_HIGH : https://example.com : insight.auth.failure : 75
  • Report data (ExtensionInsightsReport): new key stoppingInsight (the triggering Insight). Backed by a new stoppingInsight field on ExtensionInsights, set from both AF and daemon paths and reset on InsightsJob.runJob so re-runs don't see stale data.
  • Reports dep bump: >=0.39.0>=0.46.0 (version that ships the templates which render stoppingInsight).

reports add-on

  • 11 built-in templates updated to render the stopping insight when present: traditional-html, traditional-html-plus, traditional-pdf, modern, high-level-report, risk-confidence-html, traditional-json, traditional-json-plus, traditional-xml, traditional-xml-plus, traditional-md. HTML/PDF/MD use a localized message (report.insights.stoppedby); JSON/XML add a stoppingInsight sibling to the existing insights data.
  • No-op when stoppingInsight is null — existing baseline outputs unchanged.

Naming uses "stop" rather than "abort" per maintainer feedback.

Tests

  • insights add-on
    • New InsightsJobUnitTest — stop path sets the trigger, calls stopPlan(false), warns with insight details; covers <global> fallback, exitAutoOnHigh=false, and non-HIGH levels.
    • Extended ExtensionInsightsReportUnitTest — verifies stoppingInsight is exposed/omitted in the report data appropriately.
  • reports add-on
    • New format-specific tests in ExtensionReports{Json,Xml,Md}UnitTest — parse the rendered output and assert the stopping insight appears.
    • New HTML smoke test in ExtensionReportsUnitTest (matches existing shouldGenerateReport style — covers render-time errors in the Thymeleaf snippet).
    • ReportTestUtils.generateReportWithInsights overloaded to optionally accept a stopping insight.

./gradlew :addOns:insights:check :addOns:reports:check :spotlessApply — all green.

Notes

  • No Insight model change — trigger tracked on ExtensionInsights to keep @AllArgsConstructor and existing test fixtures stable.
  • Exit code stays 2 — out of scope; the enriched reason string is the differentiator.
  • Help updated: report-data mention moved from insights-options.html to the Reports section in insights.html (per review feedback). English-only.
  • CHANGELOG.md updated for both add-ons.
  • DCO signed off.

@psiinon
Copy link
Copy Markdown
Member

psiinon commented May 18, 2026

Logo
Checkmarx One – Scan Summary & Details633f1b64-b03f-4f03-ae84-b1ffb0c4b17a


New Issues (1) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 HIGH Improper_Restriction_of_Stored_XXE_Ref addOns/reports/src/test/java/org/zaproxy/addon/reports/ReportTestUtils.java: 428
detailsThe loads and parses XML using parse, at line 523 of /addOns/reports/src/test/java/org/zaproxy/addon/reports/ExtensionReportsXmlUnitTest.java. ...
Attack Vector

Use @Checkmarx to interact with Checkmarx PR Assistant.
Examples:
@Checkmarx how are you able to help me?
@Checkmarx rescan this PR

Comment on lines +24 to +25
The message reported on stop identifies the triggering insight (key, reason, site, value), and when a report is generated it includes
<code>stoppedByInsights</code> and <code>stoppingInsight</code> so headless pipelines can detect Insights-driven stops without log scraping.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when a report is generated it includes

No it doesn't, the reports need to be updated to expose the new data (there's no "data dump" as mentioned in the PR description). The report part better under the Reports section in the main help page.

without log scraping.

It was already possible without log scraping, this is incorrect and not relevant for the help.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catches, fixed in the latest push. Reports now actually expose the data

Comment thread addOns/insights/CHANGELOG.md Outdated

## Unreleased
### Added
- Report data now exposes `stoppedByInsights` and `stoppingInsight` so pipelines can detect Insights-driven stops from the report alone.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was already possible as mentioned elsewhere, we can say that it's now easier/explicit though. In any case the reports are not yet exposing that data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@msrivas-7 msrivas-7 force-pushed the insights-abort-reason branch from 260fbdd to 6992437 Compare May 19, 2026 10:26
@kingthorin kingthorin force-pushed the insights-abort-reason branch from 6992437 to 8da5b85 Compare May 19, 2026 13:32
msrivas-7 added 2 commits May 21, 2026 00:47
The AF progress warning and daemon exit reason now include the
insight key, reason, site, and statistic. Report data also exposes
stoppedByInsights and stoppingInsight so pipelines can detect
Insights-driven stops without log scraping.

See zaproxy/zaproxy#9340.

Signed-off-by: Mehul Srivastava <msrivas4017@gmail.com>
Signed-off-by: Mehul Srivastava <msrivas4017@gmail.com>
@msrivas-7 msrivas-7 force-pushed the insights-abort-reason branch from 8da5b85 to 2c1bd99 Compare May 21, 2026 07:54
@msrivas-7
Copy link
Copy Markdown
Contributor Author

Rebased to resolve conflicts

@msrivas-7 msrivas-7 requested a review from thc202 May 21, 2026 08:21
Comment thread addOns/reports/src/main/zapHomeFiles/reports/traditional-json-plus/report.json Outdated
Comment thread addOns/reports/src/main/zapHomeFiles/reports/traditional-json/report.json Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

insights: identify the triggering insight when exitAutoOnHigh stops a plan / scan

4 participants