Skip to content

fix(security): escape API-controlled values in sophia_dashboard innerHTML (RIP-306) - #16832

Merged
Scottcjn merged 1 commit into
Scottcjn:mainfrom
xxzzzzy:fix/sophia-dashboard-rip306-innerhtml-xss
Sep 5, 2026
Merged

fix(security): escape API-controlled values in sophia_dashboard innerHTML (RIP-306)#16832
Scottcjn merged 1 commit into
Scottcjn:mainfrom
xxzzzzy:fix/sophia-dashboard-rip306-innerhtml-xss

Conversation

@xxzzzzy

@xxzzzzy xxzzzzy commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

scripts/sophia_dashboard.py (Admin Dashboard for SophiaCore Attestation Inspector) renders 4 API-controlled innerHTML blocks. Three were missing escape, and one had the same unsafe inline-onclick+JSON.stringify pattern as #16790 (reviewer asked for that fix to be reused here).

Fix

  • Add esc() helper that escapes & < > " ' and coerces nullish to ''.
  • Replace per-row onclick='showDetail(${JSON.stringify(r).replace(/'/g,"&#39;")})' with a single delegated click listener on #review-table that reads data-record-idx and looks up the record from currentFilteredRecords. The &#39; replace was a no-op (the browser HTML-decodes it back to ' before evaluating the JS string), and any value containing ' or </script> could break out.
  • Escape every API-controlled value in tbody.innerHTML, detail-verdict, and detail-history.
  • detail-title now uses textContent (inherently safe).
  • Coerce confidences through Number() before arithmetic so a non-numeric payload returns NaN rather than NaN-as-string.
  • Add EMOJI[...]-lookup fallback (|| '') so a malicious verdict value does not produce undefined in the chip.

Tests

tests/test_sophia_dashboard_xss.py — 9 source-pattern regression tests, all pass:

tests/test_sophia_dashboard_xss.py ........9 [100%]

Related

Notes

  • Non-breaking hardening; all visual output preserved when the API returns well-formed values.
  • No new dependencies, no workflow change, no API change.

…HTML (RIP-306)

scripts/sophia_dashboard.py (Admin Dashboard for SophiaCore Attestation Inspector):
  - Add esc() helper that escapes the five HTML-significant characters.
  - Replace the per-row inline-onclick-with-JSON.stringify pattern with a single
    delegated click listener on #review-table that reads data-record-idx and
    looks up the record from currentFilteredRecords.
  - Escape every API-controlled value going into tbody.innerHTML.
  - Escape API-controlled values in detail-verdict and detail-history blocks.
  - detail-title now uses textContent (inherently safe).
  - Coerce confidences through Number() before arithmetic.
  - Add EMOJI[...]-lookup fallback (|| empty-string).

tests/test_sophia_dashboard_xss.py:
  - 9 source-pattern regression tests that fail if the unsafe patterns come back.

Refs: RIP-306 admin dashboard XSS; same defensive posture as Scottcjn#16790, Scottcjn#16809-Scottcjn#16821.
@github-actions github-actions Bot added the needs-tier Maintainer must assign a review tier (contributor cannot self-label) label Sep 2, 2026

@Scottcjn Scottcjn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Escapes API-controlled values in sophia_dashboard innerHTML (RIP-306 surface).

@Scottcjn
Scottcjn merged commit 62b2aca into Scottcjn:main Sep 5, 2026
3 checks passed
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Sophia auto-tier: skipped — this PR touches consensus / money / CI code. It needs a maintainer Payment: N RTC directive rather than an automatic award.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-tier Maintainer must assign a review tier (contributor cannot self-label)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants