diff --git a/.github/workflows/security-alert-issues.yml b/.github/workflows/security-alert-issues.yml index 9c74a0c..bae42d5 100644 --- a/.github/workflows/security-alert-issues.yml +++ b/.github/workflows/security-alert-issues.yml @@ -32,11 +32,76 @@ jobs: "repos/${REPO}/code-scanning/alerts?state=open&per_page=100" \ --paginate) + # Some Snyk rules reach the alerts API without + # rule.security_severity_level, so the most recent Snyk Code SARIF + # analysis is the deterministic fallback for those alerts. + severity_map='{}' + + analysis_id=$(gh api \ + "repos/${REPO}/code-scanning/analyses?per_page=100" \ + --paginate \ + --jq '.[] | select((.category // "") == "snyk-code") | "\(.created_at)\t\(.id)"' \ + 2>/dev/null | sort -r | awk 'NR == 1 { print $2 }' || true) + + if [[ -n "${analysis_id}" ]]; then + sarif=$(gh api \ + -H "Accept: application/sarif+json" \ + "repos/${REPO}/code-scanning/analyses/${analysis_id}" \ + 2>/dev/null || true) + + if [[ -n "${sarif}" ]]; then + severity_map=$(echo "${sarif}" | jq -c ' + [ + .runs[]?.tool.driver.rules[]? + | (.properties | if type == "object" then . else {} end) as $props + | { + id: ((.id // "") | tostring), + score: ($props["security-severity"] // null), + text: ( + $props.severity + // ($props.problem | if type == "object" then .severity else null end) + // null + ), + level: ((.defaultConfiguration.level // "") | tostring | ascii_downcase) + } + | select(.id != "") + ] + | reduce .[] as $rule ({}; + .[$rule.id] = ( + if (try ($rule.score | tonumber) catch null) != null then + ($rule.score | tonumber) as $score + | if $score > 9.0 then "critical" + elif $score >= 7.0 then "high" + elif $score >= 4.0 then "medium" + elif $score >= 0.1 then "low" + else "none" + end + else + (($rule.text // "") | tostring | ascii_downcase) as $text + | if ($text == "critical" or $text == "high" or $text == "medium" or $text == "low") then + $text + elif $rule.level == "error" then "high" + elif $rule.level == "warning" then "medium" + elif $rule.level == "note" then "low" + else "unknown" + end + end + ) + ) + ' 2>/dev/null || echo '{}') + else + echo "::notice::Unable to download SARIF for snyk-code analysis #${analysis_id}" + fi + else + echo "::notice::No snyk-code code-scanning analysis found; relying on alert metadata" + fi + + echo "Resolved Snyk SARIF severity map: ${severity_map}" + echo "$alerts" | jq -c '.[]' | while read -r alert; do alert_number=$(echo "$alert" | jq -r '.number') title=$(echo "$alert" | jq -r '.rule.description // .rule.id') - severity=$(echo "$alert" | jq -r '.rule.security_severity_level // "unknown"') - rule=$(echo "$alert" | jq -r '.rule.id') + rule=$(echo "$alert" | jq -r '.rule.id // empty') tool=$(echo "$alert" | jq -r '.tool.name') html_url=$(echo "$alert" | jq -r '.html_url') instance=$(echo "$alert" | jq -r '.most_recent_instance') @@ -44,6 +109,18 @@ jobs: line=$(echo "$instance" | jq -r '.location.start_line // "unknown"') message=$(echo "$instance" | jq -r '.message.text // "No message available."') + reported_severity=$(echo "$alert" | jq -r '.rule.security_severity_level // empty') + severity="" + if [[ -n "${reported_severity}" ]]; then + severity=$(echo "${reported_severity}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]') + fi + if [[ -z "${severity}" || "${severity}" == "null" || "${severity}" == "unknown" ]]; then + severity=$(echo "${severity_map}" | jq -r --arg rule "${rule}" '.[$rule] // empty') + fi + if [[ -z "${severity}" || "${severity}" == "null" ]]; then + severity="unknown" + fi + marker="" existing=$(gh issue list \ @@ -57,6 +134,15 @@ jobs: continue fi + if [[ "${severity}" == "unknown" ]]; then + echo "::notice::Skipping alert #${alert_number} (${rule}): could not resolve an effective severity" + continue + fi + if [[ "${severity}" != "critical" && "${severity}" != "high" ]]; then + echo "::notice::Skipping alert #${alert_number} (${rule}): effective severity '${severity}' is below the high threshold" + continue + fi + case "${rule}" in *XSS*|*xss*) remediation=$'## Suggested remediation\n\n- Identify the source of the value passed to the HTTP response and determine whether it can contain user-controlled data.\n- Do not return untrusted input as raw HTML.\n- Escape dynamic values using an HTML-aware encoder or a templating engine with automatic escaping.\n- If HTML output is intentional, render only trusted templates and never interpolate untrusted user input into markup.\n- Set an appropriate Content-Type header and add a restrictive Content Security Policy as defense in depth.\n- Add a regression test using an XSS payload such as `` and assert that it is escaped, rejected, or safely encoded.\n' diff --git a/.github/workflows/snyk-code.yml b/.github/workflows/snyk-code.yml index e85818b..7a7f40e 100644 --- a/.github/workflows/snyk-code.yml +++ b/.github/workflows/snyk-code.yml @@ -47,6 +47,35 @@ jobs: command: code test args: --sarif-file-output=snyk-code.sarif + - name: Sanitize SARIF severity values + if: steps.snyk-token.outputs.available == 'true' && hashFiles('snyk-code.sarif') != '' + run: | + set -euo pipefail + + # Code Scanning rejects non-numeric properties.security-severity + # values, so drop invalid entries and let GitHub fall back to the + # rule level and severity metadata. + tmp=$(mktemp) + jq ' + walk( + if type == "object" then + .properties as $properties + | if ($properties | type) == "object" then + if ($properties | has("security-severity")) then + ($properties["security-severity"]) as $severity + | if (try ($severity | tonumber) catch null) != null then . + else del(.properties["security-severity"]) + end + else . + end + else . + end + else . + end + ) + ' snyk-code.sarif > "$tmp" + mv "$tmp" snyk-code.sarif + - name: Upload SARIF to GitHub Code Scanning if: steps.snyk-token.outputs.available == 'true' && hashFiles('snyk-code.sarif') != '' uses: github/codeql-action/upload-sarif@v3 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 54a15d7..6c63b33 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ Thanks for taking a look. This project is a local-first, read-only observability ## Prerequisites - **Node.js** `>=22.18` (`engines`); **24.x** is recommended and is what CI runs. The app uses the built-in `node:sqlite`, so no native module is compiled. -- **TypeScript 5.9** in strict mode, ESM, **no build step**: the sources run directly and `tsc` is used only for `--noEmit` typechecking. +- **TypeScript 7.0.2** in strict mode, ESM, **no build step**: the sources run directly and `tsc` is used only for `--noEmit` typechecking. - An OpenCode 2 session database is only needed to run the app against real data; the test suite builds its own fixtures. ## Setup @@ -22,13 +22,13 @@ Use `npm ci` rather than `npm install`: `package-lock.json` is committed and the npm run check # typecheck + typecheck:tui + full test suite — the standard gate npm run typecheck # tsc --noEmit only npm run typecheck:tui # tsc --noEmit -p tsconfig.tui.json (Solid JSX sidecar) -npm test # node:test, 51 files, 797 tests +npm test # node:test, 51 files, 828 tests npm run build:tui # rebuild dist-tui/tui.mjs; CI verifies the artifact is fresh npm run audit:prod # production dependency audit npm run serve # start the local UI (alias of npm start) ``` -`npm run check` must be green before you open a pull request. The suite is at 797 tests across 51 files and grows with each new suite. +`npm run check` must be green before you open a pull request. The suite is at 828 tests across 51 files and grows with each new suite. After any change under `src/plugin/tui.*`, rebuild the committed bundle and prove it is fresh: