Skip to content

Backport #32313: preserve math equations through frontend and backend sanitizers (1.13) - #32402

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

Rohit0301 merged 3 commits into
1.13from
backport-32313-to-1.13

Conversation

@Rohit0301

Copy link
Copy Markdown
Contributor

Summary

Backport of #32313 to the 1.13 release branch.

Math equations (<block-math-equation> nodes) inserted via BlockEditor's MathEquation extension were silently stripped on save in the 1.13 release. This backport applies the same two-layer fix:

  • Frontend (sanitize.utils.ts): nonce-based placeholder-protect pattern for <block-math-equation> tags around DOMPurify; function replacer to avoid $ regex interpretation in LaTeX strings
  • Backend (DescriptionSanitizer.java): adds block-math-equation element + math_equation / isediting attributes to the OWASP HTML sanitizer allowlist
  • CSS (math-equation.less): removes background-color: black + color: white from the selection state (KaTeX text was invisible when the node was clicked)

Cherry-picked commits (merge commit skipped):

  • 214b904a — initial fix
  • c92aa816 — nonce-based placeholders + function replacer improvement

Test plan

  • mvn test -pl openmetadata-service -Dtest=DescriptionSanitizerTest passes
  • yarn test sanitize.utils passes
  • BlockEditorMathEquations Playwright spec passes against a 1.13 stack

🤖 Generated with Claude Code

Rohit0301 and others added 2 commits September 1, 2026 23:03
…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 1, 2026 17:34
@github-actions

github-actions Bot commented Sep 1, 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 1, 2026
@github-actions

github-actions Bot commented Sep 1, 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 self-assigned this Sep 1, 2026
@Rohit0301 Rohit0301 added the safe to test Add this label to run secure Github workflows on PRs label Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 63%
63.52% (61271/96449) 44.9% (33673/74981) 46.8% (10263/21928)

@gitar-bot

gitar-bot Bot commented Sep 2, 2026

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

Backport of math equation preservation fix for frontend and backend sanitizers now includes nonce-based placeholders and function replacer for LaTeX strings. Three minor suggestions: the frontend regex [^>]* in the block-math-equation tag matcher may mis-parse attributes containing > characters (common in LaTeX); add a regression test for $ sequences in restored math equations to ensure the function replacer works correctly; and extract magic string literals "true"/"false" in the isediting matcher to named constants for consistency.

✅ 3 resolved
✅ Quality: Magic string literals "true"/"false" in isediting matcher

📄 openmetadata-service/src/main/java/org/openmetadata/service/util/DescriptionSanitizer.java:139-145
The isediting attribute matcher compares against raw string literals "true"/"false". Per the project's Java standards, boolean-valued string literals used in .equals() should be named constants (e.g. ATTR_TRUE/ATTR_FALSE) or derived from Boolean.toString. Minor, and consistent with existing lambdas in this file, but worth extracting for readability.

✅ Bug: Missing frontend regression test for '$' in restored replacement

📄 openmetadata-ui/src/main/resources/ui/src/utils/sanitize.utils.ts:45-59 📄 openmetadata-ui/src/main/resources/ui/src/utils/sanitize.utils.test.ts:90-104
The commit switched restore to .replace(placeholder, () => value) specifically so $ sequences ($$, $&, $', $\``) in LaTeX/entity strings are inserted verbatim instead of being interpreted as replacement patterns. None of the added tests exercise a restored value containing $(the math test usesmath_equation="x^2"), so the regression the fix targets is untested and could silently regress. Add a test with e.g. math_equation="$$x$$"` asserting the output is byte-identical to the input.

✅ Edge Case: Frontend regex mis-parses block-math-equation attrs containing '>'

📄 openmetadata-ui/src/main/resources/ui/src/utils/sanitize.utils.ts:21-22
The protection regex /<block-math-equation[^>]*>[\s\S]*?<\/block-math-equation>/g uses [^>]* for the opening tag, which stops at the first literal > inside an attribute value. LaTeX stored in math_equation frequently contains >/< (e.g. x > y). In simple cases the trailing </block-math-equation> still lets the match complete, but any > in the LaTeX before the tag close makes the tag-boundary parse fragile and could truncate protection for more complex nested content. Consider anchoring on the attribute quoting or matching non-greedily up to the first > that is not inside quotes, or rely on a DOM parse rather than regex.

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

@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

@Rohit0301
Rohit0301 merged commit e959fa3 into 1.13 Sep 2, 2026
80 of 114 checks passed
@Rohit0301
Rohit0301 deleted the backport-32313-to-1.13 branch September 2, 2026 08:12

This branch was previously deployed

1 inactive deployment
test — 867a366a Deployed Sep 2, 2026 by Rohit0301 via playwright-ci-postgresql (6, 6) #77600
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