Skip to content

Fixes #32276: preserve math equations through frontend and backend sanitizers - #32313

Merged
Rohit0301 merged 3 commits into
mainfrom
fix-issue-32276
Sep 2, 2026
Merged

Rohit0301 merged 3 commits into
mainfrom
fix-issue-32276

Conversation

@Rohit0301

@Rohit0301 Rohit0301 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #32276

Math equations inserted via the BlockEditor's MathEquation node ($$...$$ syntax) rendered correctly during editing but were silently stripped on save. The bug existed in two independent layers:

  1. Frontend (sanitize.utils.ts) — DOMPurify strips unknown HTML tags by default. Applied the same placeholder-protect pattern already used for entity links: stash <block-math-equation> tags before sanitizing, restore after.
  2. Backend (DescriptionSanitizer.java) — The OWASP HTML sanitizer uses an explicit allowlist. Added block-math-equation element with math_equation (any LaTeX value, rendered client-side by KaTeX — not executable) and isediting (restricted to "true"/"false" only).
  3. CSS (math-equation.less) — Fixed a selection-state bug where background-color: black + color: white made KaTeX text invisible when the node was clicked, and added user-select: none to prevent the browser's native text-selection highlight from washing out the rendered equation.
Screenshot 2026-08-31 at 11 20 45 PM Screenshot 2026-08-31 at 11 30 58 PM

Type of change:

  • Bug fix

High-level design:

Both sanitizers (frontend DOMPurify and backend OWASP) independently strip any HTML tag not on their respective allowlists. The <block-math-equation> custom tag used by Tiptap's MathEquation extension fell through both. The fix mirrors the existing entity-link placeholder strategy in both layers rather than weakening the sanitizers' overall policies. The isediting attribute is gated to boolean strings only; math_equation is allowed freely because LaTeX content is text rendered by KaTeX — it cannot execute JavaScript.

Tests:

Use cases covered

  • Math equation typed with $$x^2$$ syntax persists after save and page reload
  • block-math-equation tag with math_equation attribute survives both sanitizers
  • isediting attribute with a non-boolean value (XSS attempt) is stripped by backend
  • Math equation alongside entity links: both are preserved independently

Unit tests

  • Frontend Jest: src/utils/sanitize.utils.test.ts — 3 new cases added (standalone tag, mixed HTML, alongside entity links). 13/13 tests pass.
  • Backend JUnit: DescriptionSanitizerTest.java — 2 new cases added (element preserved, non-boolean isediting rejected). 28/28 tests pass.

Backend integration tests

  • Not applicable (no new REST endpoints; change is in the sanitization utility called by existing PATCH handlers).

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • New E2E spec: playwright/e2e/Features/BlockEditorMathEquations.spec.ts
    • Types $$x^2 + y^2 = z^2$$ into the description editor to trigger the Tiptap input rule
    • Asserts the block-math-equation node is created in the editor before saving
    • Saves and asserts the rendered equation is visible in asset-description-container
    • Reloads the page and asserts the equation persists (full round-trip regression test)

Manual testing performed

  1. Opened any Table entity description editor in the local stack
  2. Typed $$x^2 + y^2 = z^2$$ — equation node rendered correctly in editor
  3. Clicked Save — verified PATCH payload contains <block-math-equation ...> (not stripped by frontend)
  4. Confirmed backend stored the tag (previously it was stripped)
  5. Reopened the page — equation rendered correctly in view mode
  6. Clicked the equation node — text remained black (not white) with grey selection highlight

UI screen recording / screenshots:

TODO: attach screen recording showing equation entry → save → reload round-trip. Opening as draft until recording is attached.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #32276 above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • For UI changes: screen recording marked TODO above (opening as draft).
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing.

Greptile Summary

The PR preserves BlockEditor math equations across frontend and backend sanitization and improves their selected-state styling.

  • Protects math-equation and entity-link markup with per-call nonce placeholders before frontend sanitization.
  • Allows the math-equation element and constrained attributes through the backend sanitizer.
  • Adds frontend, backend, and end-to-end regression coverage for save-and-reload persistence.
  • Removes the problematic selected-node colors and prevents native text selection on rendered equations.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
openmetadata-ui/src/main/resources/ui/src/utils/sanitize.utils.ts Replaces fixed placeholders with per-call nonce-scoped placeholders and restores math-equation markup after DOMPurify.
openmetadata-service/src/main/java/org/openmetadata/service/util/DescriptionSanitizer.java Allows the custom math-equation element, its equation value, and boolean-only editing state.
openmetadata-ui/src/main/resources/ui/src/components/BlockEditor/Extensions/MathEquation/math-equation.less Removes selected-node colors that obscured equations and exposes the edit control without native text selection.
openmetadata-ui/src/main/resources/ui/src/utils/sanitize.utils.test.ts Covers preservation of standalone and mixed math-equation markup through frontend sanitization.
openmetadata-service/src/test/java/org/openmetadata/service/util/DescriptionSanitizerTest.java Covers backend preservation and rejection of a non-boolean editing attribute.
openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/BlockEditorMathEquations.spec.ts Exercises equation creation, saving, rendering, and persistence after reload.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[BlockEditor math equation] --> B[Frontend placeholder protection]
    B --> C[DOMPurify sanitization]
    C --> D[Restore protected markup]
    D --> E[PATCH description]
    E --> F[Backend allowlist sanitizer]
    F --> G[Persist description]
    G --> H[Reload and render equation]
Loading

Reviews (2): Last reviewed commit: "fix(sanitize): nonce-based placeholders ..." | Re-trigger Greptile

…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]>
@github-actions github-actions Bot added the UI UI specific issues label Aug 31, 2026
@github-actions

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 marked this pull request as ready for review August 31, 2026 18:04
@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit c92aa8169cf1ecfc23ec80043913566622e6a365 in Playwright run 33424023102, attempt 1.

✅ 550 passed · ❌ 0 failed · 🟡 2 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) 52m 15s

⏱️ Max setup 4m 14s · max shard execution 16m 33s · max shard-job elapsed before upload 20m 5s · reporting 7s

🌐 218.62 requests/attempt · 2.82 app boots/UI scenario · 11.38% common-shard skew

Optimization targets still in progress:

  • Browser traffic was 218.62 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.82 per UI scenario (1620 boots / 575 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard chromium-01 150 0 0 0 0 0
🟡 Shard chromium-02 118 0 1 0 0 0
🟡 Shard chromium-03 127 0 1 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 33 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
🟡 2 flaky test(s) (passed on retry)
  • Pages/Entity.spec.ts › Delete File (shard chromium-02, 1 retry)
  • Pages/Entity.spec.ts › Tag Add, Update and Remove for child entities (shard chromium-03, 1 retry)

📦 Download artifacts

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

@github-actions

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!

…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]>
@github-actions

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!

@gitar-bot

gitar-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Preserves math equations through frontend and backend sanitizers using placeholder protection and allowlist updates. A potential collision issue with the restore logic was fixed to prevent LaTeX content containing '$' from being corrupted.

✅ 1 resolved
✅ Bug: Math equation restore corrupts LaTeX containing '$'

📄 openmetadata-ui/src/main/resources/ui/src/utils/sanitize.utils.ts:48-51
In getSanitizeContent, restored math equations are re-inserted via restoredContent.replace(MATH_EQUATION${index}_, eq). When the second argument of String.prototype.replace is a string, $ sequences are interpreted as special replacement patterns ($$ → $, $&, $\``, $'). LaTeX content stored in math_equationroutinely contains$(e.g. the$$x^2 + y^2 = z^2$$/$x^2$delimiters shown in the backend test), so the restored tag will be silently mangled — defeating the fix. The new frontend Jest tests use</code>x^2<code>and</code>y=mx+b<code>(no$`), so they miss it. Pass a replacer function so the string is inserted verbatim.

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

@Rohit0301 Rohit0301 added the safe to test Add this label to run secure Github workflows on PRs label Aug 31, 2026
@Rohit0301 Rohit0301 self-assigned this Aug 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 68%
68.56% (90804/132427) 53% (57133/107787) 54.64% (17318/31691)

@sonarqubecloud

Copy link
Copy Markdown

@Rohit0301
Rohit0301 enabled auto-merge September 1, 2026 06:56
@Rohit0301
Rohit0301 disabled auto-merge September 1, 2026 06:57
@Rohit0301
Rohit0301 added this pull request to the merge queue Sep 1, 2026
@Rohit0301
Rohit0301 removed this pull request from the merge queue due to a manual request Sep 1, 2026
@Rohit0301
Rohit0301 added this pull request to the merge queue Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-09-01T13:29:47Z)

No failing check on merge-queue commit e28e3a5 — invalidated by an entry ahead in the queue, or a required check timed out.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 1, 2026
@Rohit0301
Rohit0301 added this pull request to the merge queue Sep 2, 2026
Rohit0301 added a commit that referenced this pull request Sep 2, 2026
… sanitizers (1.13) (#32402)

* Fixes #32276: preserve math equations through frontend and backend sanitizers

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]>

* fix(sanitize): nonce-based placeholders + function replacer for math 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]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Merged via the queue into main with commit e4a8a73 Sep 2, 2026
173 of 190 checks passed
@Rohit0301
Rohit0301 deleted the fix-issue-32276 branch September 2, 2026 11:08
Rohit0301 added a commit that referenced this pull request Sep 3, 2026
…nitizers (#32313)

* Fixes #32276: preserve math equations through frontend and backend sanitizers

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]>

* fix(sanitize): nonce-based placeholders + function replacer for math 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]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Rohit0301 added a commit that referenced this pull request Sep 3, 2026
…backend sanitizers (#32509)

* Fixes #32276: preserve math equations through frontend and backend sanitizers

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]>

* fix(sanitize): nonce-based placeholders + function replacer for math 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]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
shrabantipaul-collate pushed a commit to PRADDZY/OpenMetadata that referenced this pull request Sep 3, 2026
…nd backend sanitizers (open-metadata#32313)

* Fixes open-metadata#32276: preserve math equations through frontend and backend sanitizers

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]>

* fix(sanitize): nonce-based placeholders + function replacer for math 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]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>

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.

LaTeX/Math equations are silently stripped from descriptions on save

3 participants