[Artifacts] Harden Mol* fallback gene escaping and URL encoding done coding:8

← Artifacts
Improve /hypothesis Mol* dynamic fallback by JS-safe gene literal handling and URL encoding for manual RCSB/AlphaFold search links to keep 3D artifact panel reliable for unusual target gene symbols. IMPORTANT: Keep Mol* protein viewer on entity/hypothesis/challenge detail pages where it adds value. Do NOT feature it prominently on /showcase. Showcase should highlight: debate transcripts, hypothesis cards with scores, evidence tables, KG visualizations, and notebooks — the core discovery exchange features. ## REOPENED TASK — CRITICAL CONTEXT This task was previously marked 'done' but the audit could not verify the work actually landed on main. The original work may have been: - Lost to an orphan branch / failed push - Only a spec-file edit (no code changes) - Already addressed by other agents in the meantime - Made obsolete by subsequent work **Before doing anything else:** 1. **Re-evaluate the task in light of CURRENT main state.** Read the spec and the relevant files on origin/main NOW. The original task may have been written against a state of the code that no longer exists. 2. **Verify the task still advances SciDEX's aims.** If the system has evolved past the need for this work (different architecture, different priorities), close the task with reason "obsolete: " instead of doing it. 3. **Check if it's already done.** Run `git log --grep=''` and read the related commits. If real work landed, complete the task with `--no-sha-check --summary 'Already done in '`. 4. **Make sure your changes don't regress recent functionality.** Many agents have been working on this codebase. Before committing, run `git log --since='24 hours ago' -- ` to see what changed in your area, and verify you don't undo any of it. 5. **Stay scoped.** Only do what this specific task asks for. Do not refactor, do not "fix" unrelated issues, do not add features that weren't requested. Scope creep at this point is regression risk. If you cannot do this task safely (because it would regress, conflict with current direction, or the requirements no longer apply), escalate via `orchestra escalate` with a clear explanation instead of committing.

Git Commits (2)

[Artifacts] Harden Mol* fallback gene escaping in api.py — prevent XSS [task:ff90b5cf-54bf-45f6-a31d-36ad5bc87135]2026-04-16
[Artifacts] Harden Mol* fallback gene escaping in api.py — prevent XSS [task:ff90b5cf-54bf-45f6-a31d-36ad5bc87135]2026-04-16
Spec File

[Artifacts] Harden Mol* fallback gene escaping and URL encoding

Task ID: ff90b5cf-54bf-45f6-a31d-36ad5bc87135 Priority: P50 Type: one_shot Status: Complete

Goal

Improve /hypothesis Mol* dynamic fallback by JS-safe gene literal handling and URL encoding for manual RCSB/AlphaFold search links to keep 3D artifact panel reliable for unusual target gene symbols.

Acceptance Criteria

☑ Fix JS-safe gene literal handling in Mol* dynamic fallback (line 29820)
☑ Gene name properly escaped to prevent </script> injection attacks
☑ Normal gene names (e.g., FOXP2) work unchanged
☑ Protein viewer kept on entity/hypothesis/challenge detail pages
☑ Protein viewer NOT featured on /showcase page

Changes Made

api.py line 29820

Before:

var gene = {json.dumps(target_gene_first)};

After:

var gene = {json.dumps(html.escape(target_gene_first))};

Why: Using json.dumps() alone doesn't HTML-escape. If a gene name contains </script>, it could break out of the HTML <script> block and enable XSS. By HTML-escaping before JSON-encoding, </script> becomes \u003c/script\u003e in the JSON string, which prevents the HTML parser from seeing the closing tag sequence.

Verification

Tested escaping logic:

  • Problematic gene TEST</script><script>alert(1)// becomes "TEST&lt;/script&gt;&lt;script&gt;alert(1)//" — safe
  • Normal gene FOXP2 becomes "FOXP2" — no change

Showcase Restriction

Confirmed: /showcase page (line 55202+) does NOT include protein_viewer_html or molstar_html. The showcase highlights debate transcripts, hypothesis cards with scores, evidence tables, KG visualizations, and notebooks — not the 3D protein viewer.

Work Log

2026-04-16 — ff90b5cf-harden-mol-fallback

  • Investigated task: no prior commits found referencing this task ID
  • Reviewed api.py Mol* implementation (lines 29700-29870)
  • Identified XSS vulnerability: json.dumps(target_gene_first) on line 29820 doesn't HTML-escape, allowing </script> injection
  • Applied fix: json.dumps(html.escape(target_gene_first))
  • Verified: showcase page doesn't feature protein viewer (correct)
  • Verified: search links in fallback already use encodeURIComponent(gene) (correct)
  • Committed and pushed fix

Payload JSON
{
  "requirements": {
    "coding": 8
  },
  "_reset_note": "This task was reset after a database incident on 2026-04-17.\n\n**Context:** SciDEX migrated from SQLite to PostgreSQL after recurring DB\ncorruption. Some work done during Apr 16-17 may have been lost.\n\n**Before starting work:**\n1. Check if the task's goal is ALREADY satisfied (run the relevant checks)\n2. Check `git log --all --grep=task:YOUR_TASK_ID` for prior commits\n3. If complete, verify and mark done. If partial, continue. If not done, proceed.\n\n**DB change:** SciDEX now uses PostgreSQL. `get_db()` auto-detects via\nSCIDEX_DB_BACKEND=postgres env var.",
  "_reset_at": "2026-04-18T06:29:22.046013+00:00",
  "_reset_from_status": "done"
}

Sibling Tasks in Quest (Artifacts) ↗