Skip to content

[HOTFIX] Sanitize imported Jupyter notebook previews - #5646

Open
jongyoul wants to merge 2 commits into
apache:masterfrom
jongyoul:codex/sanitize-jupyter-import-previews
Open

jongyoul wants to merge 2 commits into
apache:masterfrom
jongyoul:codex/sanitize-jupyter-import-previews

Conversation

@jongyoul

Copy link
Copy Markdown
Member

What is this PR for?

Jupyter notebook imports convert saved markdown and rich output into Zeppelin result previews. This PR sanitizes imported HTML previews, renders SVG output as encoded images, keeps JavaScript and LaTeX output as text, applies deterministic MIME display priority, and updates the jsoup dependency and license metadata. Imported cell source remains unchanged.

What type of PR is it?

Hot Fix

Todos

  • Sanitize imported markdown and HTML previews
  • Normalize rich output MIME handling
  • Preserve imported cell source
  • Add import and reload regression coverage
  • Update jsoup license metadata

What is the Jira issue?

N/A

How should this be tested?

  • ./mvnw -B -T1 -pl zeppelin-jupyter --am test -Dtest=JupyterUtilTest -Dsurefire.failIfNoSpecifiedTests=false
  • ./mvnw -B -T1 -pl zeppelin-server --am test -Dtest=NotebookImportTest -Dsurefire.failIfNoSpecifiedTests=false
  • ./mvnw -B -T1 -DskipTests -Prat org.apache.rat:apache-rat-plugin:check

Screenshots (if appropriate)

N/A

Questions:

  • Does the license files need to update? Yes, the bundled jsoup license metadata is updated.
  • Is there breaking changes for older versions? Imported previews are normalized and sanitized; imported cell source is preserved.
  • Does this needs documentation? No additional user documentation is required.

Comment on lines +99 to +103
} else if (type == JupyterOutputType.TEXT_HTML) {
// MathJax also interprets content, so skip it for untrusted saved output.
outputData = "<div class=\"tex2jax_ignore\">" + ImportedHtml.clean(outputData) + "</div>";
}
return result;
return new TypeData(type.getZeppelinType().toString(), outputData);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we try the next MIME candidate when sanitization leaves the HTML preview empty? For example, if a bundle contains a canvas-only HTML preview and a PNG snapshot, we select the HTML first and end up rendering an empty <div>, even though the bundle already contains a usable image. We can keep preferring HTML when it survives sanitization and fall back to the next candidate when it doesn't.

Comment on lines +116 to +118
+ "{\"output_type\":\"display_data\",\"data\":{"
+ "\"text/html\":\"<b>preferred</b>\",\"text/plain\":\"fallback\","
+ "\"application/javascript\":\"alert(1)\"}},"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we test the same MIME bundle with the keys in reverse order as well? The current fixture puts text/html first, so an implementation that simply picks the first supported key would also pass. Asserting that both orders select HTML would verify that the declared priority, not the input key order, determines the preview.

Copilot AI balanced review requested due to automatic review settings December 1, 2026 11:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the notebook import hardening changes.

No open issues 🎉

What changed in this PR

This hotfix hardens Zeppelin’s Jupyter notebook imports by converting saved markdown and rich output into sanitized, static previews while preserving cell source.

Changes:

  • Sanitize HTML previews and disable MathJax processing; render SVG as encoded images and JavaScript/LaTeX as text.
  • Apply deterministic MIME selection with fallback handling and native PNG results.
  • Add import regression coverage and update jsoup dependency and license metadata.
File Description
zeppelin-server/​src/​test/​java/​org/​apache/​zeppelin/​socket/​NotebookImportTest.java Adds server-level coverage for sanitized imports and preserved source.
zeppelin-server/​pom.xml Removes the jsoup exclusion.
zeppelin-jupyter/​src/​test/​java/​org/​apache/​zeppelin/​jupyter/​nbformat/​JupyterUtilTest.java Tests sanitization, MIME priority, fallbacks, and source preservation.
zeppelin-jupyter/​src/​main/​java/​org/​apache/​zeppelin/​jupyter/​types/​ZeppelinOutputType.java Adds the IMG output type.
zeppelin-jupyter/​src/​main/​java/​org/​apache/​zeppelin/​jupyter/​types/​JupyterOutputType.java Maps PNG to images and JavaScript/LaTeX to text.
zeppelin-jupyter/​src/​main/​java/​org/​apache/​zeppelin/​jupyter/​parser/​MarkdownParser.java Sanitizes rendered markdown and disables MathJax processing.
zeppelin-jupyter/​src/​main/​java/​org/​apache/​zeppelin/​jupyter/​parser/​ImportedHtml.java Adds shared HTML sanitization and renderable-content checks.
zeppelin-jupyter/​src/​main/​java/​org/​apache/​zeppelin/​jupyter/​nbformat/​Output.java Normalizes rich output and applies deterministic MIME selection.
zeppelin-jupyter/​pom.xml Adds an explicit jsoup 1.24.1 dependency.
zeppelin-distribution/​src/​bin_license/​licenses/​LICENSE-jsoup-1.24.1 Adds the jsoup 1.24.1 license text.
zeppelin-distribution/​src/​bin_license/​licenses/​LICENSE-jsoup-1.16.1 Corrects existing jsoup copyright metadata and formatting.
zeppelin-distribution/​src/​bin_license/​LICENSE Lists jsoup 1.24.1 in the bundled license inventory.

Review effort: Balanced

@miinhho

miinhho commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

LGTM, thanks for addressing both comments!

@jongyoul
jongyoul force-pushed the codex/sanitize-jupyter-import-previews branch from 61fa99d to 9ee0f0c Compare December 4, 2026 16:51

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants