Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix(ci): fail closed on malformed Safety reports (#1366)
Guofang.Tangc10090dc9bd0
diff --git a/.github/workflows/security-scan.yml b/.github/workflows/security-scan.ymlindex de21d781..71df8a1d 100644--- a/.github/workflows/security-scan.yml+++ b/.github/workflows/security-scan.yml@@ -55,7 +55,12 @@ jobs:pip install -r .github/requirements/security-scan-tools.txt --require-hashes- name: Run Safety Check (Package Vulnerabilities)+ continue-on-error: truerun: |+ # Keep publishing reports and the PR comment even when the Safety+ # gate fails. The final gate below preserves the failure status.+ echo 'SAFETY_SCAN_STATUS=failed' >> "$GITHUB_ENV"+# NOTE: Safety 3.x repurposed --output to select a console format# (json/text/screen/...), not a file path. Writing JSON to a file# now requires --save-json; the previous `--output safety-report.json`@@ -76,6 +81,13 @@ jobs:exit 1fi+ # Guard 2: fail closed when Safety produces a report without the+ # vulnerability array expected by the downstream checks.+ if ! jq -e '(.vulnerabilities | type == "array")' safety-report.json >/dev/null 2>&1; then+ echo "::error::Safety report has an invalid vulnerability structure. Expected an array-valued 'vulnerabilities' field. Treating as failure."+ exit 1+ fi+echo "Checking for package vulnerabilities..."# Vulnerability IDs reviewed and accepted as non-actionable for this@@ -119,7 +131,7 @@ jobs:# No []? / || echo "0" fallback on a missing/null "vulnerabilities"# key: iterating over null raises inside jq, leaving VULNS empty, so- # guard 2 below catches it rather than silently treating a broken+ # Guard 3 below catches it rather than silently treating a broken# report as zero.VULNS=$(jq --arg ignored "$IGNORED_VULN_IDS" '($ignored | split(",")) as $ignore_list@@ -127,7 +139,7 @@ jobs:| length' safety-report.json 2>/dev/null)- # Guard 2: ensure VULNS is a non-negative integer before the -gt+ # Guard 3: ensure VULNS is a non-negative integer before the -gt# comparison. "null" (missing/null key) or "" (jq parse failure) would# cause bash's -gt to throw an arithmetic error and fall through to the# success branch — the same silent-pass bug as a missing file.@@ -149,6 +161,7 @@ jobs:exit 1elseecho "✅ No actionable security vulnerabilities found (ignored: $IGNORED_VULN_IDS)"+ echo 'SAFETY_SCAN_STATUS=passed' >> "$GITHUB_ENV"fi- name: Run Bandit (Code Security Linter)@@ -188,6 +201,7 @@ jobs:fi- name: Upload Security Reports+ if: always()uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7with:name: security-reports@@ -198,7 +212,7 @@ jobs:semgrep-report.json- name: Comment PR with Security Results- if: github.event_name == 'pull_request'+ if: always() && github.event_name == 'pull_request'uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9with:script: |@@ -221,6 +235,12 @@ jobs:}const items = parse(data);+ if (items === null) {+ return [+ '### ' + title,+ '⚠️ Invalid report structure in ' + reportPath + ' — check the job logs.',+ ].join('\n');+ }if (items.length === 0) {return [`### ${title}`, `✅ No findings.`].join('\n');}@@ -249,12 +269,17 @@ jobs:const safetySection = renderSection('Safety — dependency vulnerabilities','safety-report.json',- (data) => (data.vulnerabilities || [])- .filter((v) => !ignoredVulnIds.includes(v.vulnerability_id))- .map(+ (data) => {+ if (!Array.isArray(data.vulnerabilities)) {+ return null;+ }+ return data.vulnerabilities+ .filter((v) => !ignoredVulnIds.includes(v.vulnerability_id))+ .map((v) => `- \`${v.package_name}==${v.analyzed_version}\`: ${v.vulnerability_id}` +(v.CVE ? ` (${v.CVE})` : '') + ` — ${v.advisory || 'no advisory text'}`- )+ );+ }) + (ignoredVulnIds.length? `\n\n_Excluded as accepted, non-actionable findings: ${ignoredVulnIds.join(', ')} — see the workflow file's inline comments for why._`: '');@@ -303,3 +328,11 @@ jobs:console.log('⚠️ Could not post security comment:', error.message);console.log('📋 Security scan results saved to artifacts');}++ - name: Enforce Safety Gate+ if: always()+ run: |+ if [ "${SAFETY_SCAN_STATUS:-failed}" != "passed" ]; then+ echo "::error::Safety scan failed. See the Safety output and uploaded reports above."+ exit 1+ fi