Skip to content

Adjust severity - #19

Merged
dancewithheart merged 2 commits into
masterfrom
adjust-severity
May 31, 2026
Merged

Adjust severity#19
dancewithheart merged 2 commits into
masterfrom
adjust-severity

Conversation

@dancewithheart

@dancewithheart dancewithheart commented May 31, 2026

Copy link
Copy Markdown
Owner

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors SARIF enrichment to use an effective-severity model that reclassifies indirect dependencies as notes instead of warnings, extends workflow SARIF output validation via --to-file and jq type checking, and integrates CVSS advisory data into message and tag generation.

Changes

SARIF Enrichment and Output Pipeline

Layer / File(s) Summary
Workflow SARIF Output Validation
.github/workflows/submit_deps.yml
Cabal-audit repository checkout configuration is extended, and SARIF generation is refactored to use --to-file output option with subsequent jq type validation instead of shell redirection.
EffectiveSeverity Model and Classification
src/Hgs/Sarif/Enrich.hs
Introduces EffectiveSeverity type and mapping functions that reclassify indirect dependencies as notes/recommendations instead of warnings. Pattern-matching simplifications are applied to relationshipFromPaths and localRootAndDirectDependency.
Message and Tag Enrichment with CVSS Data
src/Hgs/Sarif/Enrich.hs
Message construction is refactored to extract optional security-severity from result properties and incorporate effective severity and advisory CVSS lines into both plain-text and markdown message bodies. Result tags and properties are updated with new security/cabal-plan-submit tag structure and effective-severity field.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • dancewithheart/cabal-plan-submit#18: Main changes to src/Hgs/Sarif/Enrich.hs (severity model, message/tags, enrichment behavior) directly overlap with this issue's enrichment module refactor goals.

Possibly related PRs

  • dancewithheart/cabal-plan-submit#16: The main PR's src/Hgs/Sarif/Enrich.hs changes refine how enrichSarifValue/enrichRun/enrichResult compute effective severity and adjust SARIF level, message, and tags—directly building on this PR's introduction of the SARIF enrichment module.

Poem

🐰 With severity refined and wisdom deep,
Indirect deps now rest as notes to keep,
CVSS whispers dance through message halls,
While workflows validate each golden call—
A stronger audit path, from end to end!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Adjust severity' is concise and directly reflects the main change: modifying how SARIF severity is derived and displayed in vulnerability results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch adjust-severity

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/submit_deps.yml:
- Around line 119-120: The current jq check (the line invoking "jq type
../cabal-audit.sarif") only validates JSON and will not fail for non‑SARIF
shapes; replace that invocation with a jq -e structural predicate that asserts
the top-level value is an object and that it contains a "runs" key whose value
is an array so the workflow fails on invalid SARIF shape.

In `@src/Hgs/Sarif/Enrich.hs`:
- Around line 360-363: The current serialization uses
problemSeverity/explanation (which maps to "recommendation") for the "effective
severity" text and cabal-plan-submit.effective-severity property; change those
to serialize the actual EffectiveSeverity value instead: keep problem.severity
as recommendation for GitHub ranking, but where the code builds the effective
severity string (the expressions around problemSeverity, explanation, and
cvssText) and where the cabal-plan-submit.effective-severity property is set,
replace the use of problemSeverity/recommendation with a serializer/function
that renders the EffectiveSeverity enum/value (e.g. use the existing
EffectiveSeverity -> Text renderer) so the message body and property reflect the
real EffectiveSeverity; apply the same change in the other occurrences
referenced (the analogous blocks around lines 380-383 and 415-416).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 963b834b-2ebe-4298-8fcf-05e2051f9407

📥 Commits

Reviewing files that changed from the base of the PR and between a997417 and fe077bc.

📒 Files selected for processing (2)
  • .github/workflows/submit_deps.yml
  • src/Hgs/Sarif/Enrich.hs

Comment on lines +119 to +120
"$CABAL_AUDIT" --sarif --to-file ../cabal-audit.sarif
jq type ../cabal-audit.sarif

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -u

tmp="$(mktemp)"
printf '[]\n' > "$tmp"

jq type "$tmp" >/dev/null
echo "jq type exit code: $?"   # expected: 0

set +e
jq -e 'type == "object" and (.runs | type == "array")' "$tmp" >/dev/null
echo "strict predicate exit code: $?"  # expected: non-zero

Repository: dancewithheart/cabal-plan-submit

Length of output: 2015


🏁 Script executed:

#!/bin/bash
set -u

tmp="$(mktemp)"
printf '[]\n' > "$tmp"

jq type "$tmp" >/dev/null
echo "jq type exit code: $?"   # expected: 0

set +e
jq -e 'type == "object" and (.runs | type == "array")' "$tmp" >/dev/null
echo "strict predicate exit code: $?"  # expected: non-zero

Repository: dancewithheart/cabal-plan-submit

Length of output: 1986


🌐 Web query:

enrich-sarif expects top-level runs array SARIF

💡 Result:

The requirement that a SARIF file must contain a top-level runs array is a fundamental aspect of the SARIF (Static Analysis Results Interchange Format) specification [1][2]. Because enrich-sarif and similar utility tools operate on the SARIF object model, they expect valid SARIF files that conform to this schema [3][4]. In the SARIF object model: - A SARIF log is a JSON file whose top-level object is the sarifLog object [2]. - The sarifLog object must contain a property named runs, which is an array of one or more run objects [1][2]. - Each run object represents a single invocation of a single analysis tool [1][5]. Tools like enrich-sarif often parse this structure to iterate through the runs array to add data, augment findings, or enhance metadata [4][6]. If your tool or process is failing with an error indicating it expects a top-level runs array, it is likely because the input file is missing this structure, is not formatted as valid SARIF, or has been incorrectly transformed (e.g., flattened or stripped of the outer container) [2][4]. To resolve this: 1. Verify that your input file follows the standard SARIF JSON structure, which starts with an object containing at least the version and the runs array [1][7]. 2. If you are generating this file programmatically, ensure the root object includes the "runs": [...] key [2]. 3. Check that you are not accidentally passing a single run object (the content inside the array) directly to the tool instead of the full SARIF file [3].

Citations:


🏁 Script executed:

#!/bin/bash
set -u

tmp="$(mktemp)"
printf '[]\n' > "$tmp"

jq type "$tmp" >/dev/null
echo "jq type exit code: $?"   # expected: 0

set +e
jq -e 'type == "object" and (.runs | type == "array" and length > 0)' "$tmp" >/dev/null
echo "strict predicate exit code: $?"  # expected: non-zero

Repository: dancewithheart/cabal-plan-submit

Length of output: 1986


Make the jq check fail fast on non-SARIF (lines 119-120)

jq type ../cabal-audit.sarif succeeds for any valid JSON, so it won’t catch SARIF shape issues (top-level object with a runs array). Switch to a jq -e structural predicate so the workflow fails at validation time.

Suggested fix
-          jq type ../cabal-audit.sarif
+          jq -e 'type == "object" and (.runs | type == "array")' ../cabal-audit.sarif > /dev/null
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"$CABAL_AUDIT" --sarif --to-file ../cabal-audit.sarif
jq type ../cabal-audit.sarif
"$CABAL_AUDIT" --sarif --to-file ../cabal-audit.sarif
jq -e 'type == "object" and (.runs | type == "array")' ../cabal-audit.sarif > /dev/null
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/submit_deps.yml around lines 119 - 120, The current jq
check (the line invoking "jq type ../cabal-audit.sarif") only validates JSON and
will not fail for non‑SARIF shapes; replace that invocation with a jq -e
structural predicate that asserts the top-level value is an object and that it
contains a "runs" key whose value is an array so the workflow fails on invalid
SARIF shape.

Comment thread src/Hgs/Sarif/Enrich.hs
Comment on lines +360 to +363
<> " effective severity: "
<> problemSeverity explanation
<> "\n"
<> foldMap (\cvss -> " advisory CVSS: " <> cvss <> "\n") cvssText

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Serialize effective-severity with one vocabulary.

Indirect findings now emit level = note and effective-severity-note, but the message body and cabal-plan-submit.effective-severity property serialize the same concept as recommendation. That makes the new effective-severity field disagree with the SARIF level/tags this PR just introduced.

Keep problem.severity as recommendation if you want GitHub’s ranking text, but render effective severity from the actual EffectiveSeverity value.

Suggested fix
+renderEffectiveSeverity :: EffectiveSeverity -> Text
+renderEffectiveSeverity = sarifLevel
+
 appendExplanationText :: Maybe Text -> Text -> FindingExplanation -> Text
 appendExplanationText cvssText oldText explanation =
   Text.stripEnd oldText
@@
     <> explainedRelationship explanation
     <> "\n"
     <> "  effective severity: "
-    <> problemSeverity explanation
+    <> renderEffectiveSeverity (effectiveSeverity explanation)
     <> "\n"
@@
     <> explainedRelationship explanation
     <> "`\n"
     <> "* effective severity: `"
-    <> problemSeverity explanation
+    <> renderEffectiveSeverity (effectiveSeverity explanation)
     <> "`\n"
@@
         , ("precision", String "medium")
         , ("problem.severity", String (problemSeverity explanation))
-        , ("cabal-plan-submit.effective-severity", String (problemSeverity explanation))
+        , ( "cabal-plan-submit.effective-severity"
+          , String (renderEffectiveSeverity (effectiveSeverity explanation))
+          )
         ])

Also applies to: 380-383, 415-416

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Hgs/Sarif/Enrich.hs` around lines 360 - 363, The current serialization
uses problemSeverity/explanation (which maps to "recommendation") for the
"effective severity" text and cabal-plan-submit.effective-severity property;
change those to serialize the actual EffectiveSeverity value instead: keep
problem.severity as recommendation for GitHub ranking, but where the code builds
the effective severity string (the expressions around problemSeverity,
explanation, and cvssText) and where the cabal-plan-submit.effective-severity
property is set, replace the use of problemSeverity/recommendation with a
serializer/function that renders the EffectiveSeverity enum/value (e.g. use the
existing EffectiveSeverity -> Text renderer) so the message body and property
reflect the real EffectiveSeverity; apply the same change in the other
occurrences referenced (the analogous blocks around lines 380-383 and 415-416).

@dancewithheart
dancewithheart merged commit df0c5fa into master May 31, 2026
5 checks passed
@dancewithheart dancewithheart mentioned this pull request May 31, 2026
12 tasks
@dancewithheart
dancewithheart deleted the adjust-severity branch July 13, 2026 22:05
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