Skip to content

Backport #32313 to 2.0: preserve math equations through frontend and backend sanitizers - #32509

Merged
Rohit0301 merged 2 commits into
2.0from
backport-32313-2.0
Sep 3, 2026
Merged

Rohit0301 merged 2 commits into
2.0from
backport-32313-2.0

Conversation

@Rohit0301

Copy link
Copy Markdown
Contributor

Summary

Backport of #32313 (fixes #32276) to the 2.0 release branch.

Math equations (<block-math-equation> nodes) inserted via the BlockEditor's $$...$$ syntax were silently stripped on save due to two independent sanitizer layers:

  1. Frontend (sanitize.utils.ts) — DOMPurify strips unknown HTML tags. Applied the placeholder-protect pattern (with per-call nonce) already used for entity links: stash <block-math-equation> tags before sanitizing, restore after.
  2. Backend (DescriptionSanitizer.java) — OWASP HTML sanitizer uses an explicit allowlist. Added block-math-equation element with math_equation attribute (LaTeX, rendered client-side by KaTeX) and isediting restricted to "true"/"false".
  3. CSS (math-equation.less) — Fixed selection-state bug where background-color: black + color: white made KaTeX text invisible when clicked.

Changes backported

  • DescriptionSanitizer.java — allow block-math-equation through OWASP sanitizer
  • DescriptionSanitizerTest.java — 2 new test cases
  • sanitize.utils.ts — nonce-based placeholder protection for math equations
  • sanitize.utils.test.ts — 3 new Jest cases
  • math-equation.less — fix selected-node color bug
  • BlockEditorMathEquations.spec.ts — new Playwright E2E spec (save + reload round-trip)

Test plan

  • Frontend Jest: sanitize.utils.test.ts — 13/13 pass
  • Backend JUnit: DescriptionSanitizerTest.java — 28/28 pass
  • Playwright E2E: math equation survives save + page reload

🤖 Generated with Claude Code

Rohit0301 and others added 2 commits September 3, 2026 10:18
…nitizers

Math equations (block-math-equation nodes) were silently stripped on save
because both the frontend DOMPurify sanitizer and the backend OWASP HTML
sanitizer removed the unknown custom tag. Apply the same placeholder-protect
pattern already used for entity links in both sanitizers, add block-math-equation
to the OWASP allowlist, and fix the white-text-on-selection CSS bug.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…equations

- Add per-call nonce to placeholder names so literal __OM_MATH_EQ_*__
  text in descriptions cannot collide with generated placeholders (P1)
- Use replacer function () => eq so $ sequences in LaTeX are inserted
  verbatim rather than interpreted as replacement patterns (bug fix)
- Apply same function-replacer fix to entity link restoration
- Remove // Restore math equations comment that restated the code (P2)
- Apply same nonce to entity link placeholders for consistency

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@Rohit0301
Rohit0301 requested review from a team as code owners September 3, 2026 04:49
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added the UI UI specific issues label Sep 3, 2026
@Rohit0301 Rohit0301 self-assigned this Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@Rohit0301 Rohit0301 added the safe to test Add this label to run secure Github workflows on PRs label Sep 3, 2026
@gitar-bot

gitar-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

Backport of math equation preservation fix to the 2.0 branch. Frontend and backend sanitizers now protect <block-math-equation> tags through nonce-based placeholders and OWASP allowlisting, with CSS selection-state fix and comprehensive test coverage. No issues found.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 67%
67.11% (80555/120018) 51.63% (49401/95673) 52.52% (14733/28047)

@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 310522b2c975f62d73b81f2eb44ce3489c6a58f5 in Playwright run 33716469735, attempt 1.

✅ 556 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 51m 4s

⏱️ Max setup 3m 6s · max shard execution 17m 20s · max shard-job elapsed before upload 21m 6s · reporting 3s

🌐 207.94 requests/attempt · 2.82 app boots/UI scenario · 4.33% common-shard skew

Optimization targets still in progress:

  • Browser traffic was 207.94 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.82 per UI scenario (1630 boots / 577 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 141 0 0 0 0 0
✅ Shard chromium-02 136 0 0 0 0 0
✅ Shard chromium-03 123 0 0 0 0 0
✅ Shard data-asset-rules-01 63 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard ingestion-01 1 0 0 0 0 0
✅ Shard reindex-01 2 0 0 0 0 0
✅ Shard search-01 11 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@Rohit0301
Rohit0301 merged commit d620b01 into 2.0 Sep 3, 2026
166 of 180 checks passed
@Rohit0301
Rohit0301 deleted the backport-32313-2.0 branch September 3, 2026 06:33

This branch was previously deployed

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

Labels

safe to test Add this label to run secure Github workflows on PRs UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants