Skip to content

fix(syft-job): escape HTML before ANSI conversion in stdout/stderr vi… - #9606

Open
nithingowdar2006 wants to merge 1 commit into
OpenMined:devfrom
nithingowdar2006:fix/issue-9586-html-viewer-ansi-escaping
Open

nithingowdar2006 wants to merge 1 commit into
OpenMined:devfrom
nithingowdar2006:fix/issue-9586-html-viewer-ansi-escaping

Conversation

@nithingowdar2006

Copy link
Copy Markdown

…ewers

Fixes #9586

Two bugs in StdoutViewer.repr_html (job_stdout.py) and StderrViewer.repr_html (job_repr.py):

Bug 1 - Wrong escaping order: ANSI codes were converted to
first, and then '"' was replaced
with '"'. Every resulting span became
<span style="color: #cd3131;">, so the browser ignored
the style and coloured output showed up without colours.

Bug 2 - Missing HTML escaping: '<' and '>' were never escaped.
Any output that looks like an HTML tag (e.g. <class 'int'> or
tracebacks containing 'in ') was parsed as HTML and
disappeared from the view. Output containing <script> could also
inject arbitrary markup into the notebook.

Fix: use html.escape(raw_content, quote=False) before converting ANSI sequences to tags. The quote=False argument preserves '"' so the span style attributes remain valid HTML (their double-quotes must not be entity-encoded).

Tests added in packages/syft-job/tests/test_issue_9586_html_viewer.py covering both bugs and both viewer classes (stdout + stderr), including the XSS injection case.

Summary

Changes

Testing

Asana task


PR naming convention

Your PR title must follow this format or merging will be blocked:

type: short description in lowercase

Example titles:

  • feat: add retry logic to job approval
  • fix: handle timeout in notification sender
  • docs: update syft-bg README
  • chore: bump dependencies
  • refactor: split init flow into helpers
  • test: add criteria validation tests
  • ci: add release train workflow

Allowed types:

Type When to use Example
feat New feature or capability feat: add DS rejection emails
fix Bug fix fix: handle empty peer list
docs Documentation only docs: update syft-bg README
chore Maintenance, deps, config chore: bump dependencies
refactor Code restructuring (no behavior change) refactor: split init flow
test Adding or updating tests test: add approval criteria tests
ci CI/CD workflow changes ci: add release train workflow
perf Performance improvement perf: cache Drive API responses
build Build system or dependency changes build: pin syft-bg>=0.2.0

Just edit the PR title to fix any errors — the check re-runs automatically.

Auto-labeling

Labels are applied automatically — you don't need to add them manually:

  • Type labels from your PR title (e.g., feat: adds feature, fix: adds bugfix)
  • Package labels from which files you changed (e.g., editing packages/syft-bg/ adds pkg:syft-bg)

These labels are used to auto-generate categorized release notes.

…ewers

Fixes OpenMined#9586

Two bugs in StdoutViewer._repr_html_ (job_stdout.py) and
StderrViewer._repr_html_ (job_repr.py):

Bug 1 - Wrong escaping order: ANSI codes were converted to
  <span style="color: #cd3131;"> first, and then '"' was replaced
  with '&quot;'.  Every resulting span became
  <span style=&quot;color: #cd3131;&quot;>, so the browser ignored
  the style and coloured output showed up without colours.

Bug 2 - Missing HTML escaping: '<' and '>' were never escaped.
  Any output that looks like an HTML tag (e.g. <class 'int'> or
  tracebacks containing 'in <module>') was parsed as HTML and
  disappeared from the view. Output containing <script> could also
  inject arbitrary markup into the notebook.

Fix: use html.escape(raw_content, quote=False) *before* converting ANSI
sequences to <span> tags. The quote=False argument preserves '"' so the
span style attributes remain valid HTML (their double-quotes must not be
entity-encoded).

Tests added in packages/syft-job/tests/test_issue_9586_html_viewer.py
covering both bugs and both viewer classes (stdout + stderr), including
the XSS injection case.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

syft-job: job stdout and stderr HTML views drop <...> text and show no ANSI colors

1 participant