fix(html): display strings with angle brackets in query results #38
+92
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix(html): display strings with angle brackets in query results
fix(sqllab): display strings with angle brackets in query results
SUMMARY
Fixes a bug where SQL Lab query results containing strings with angle brackets (like
<div>test</div>) were not displaying correctly. The issue occurred because HTML sanitization logic was incorrectly treating these strings as HTML and attempting to render them, which resulted in empty or missing cells.Root Cause:
When
renderResultCelldetected HTML-like strings viaisProbablyHTML(), it passed them tosafeHtmlSpan()which sanitized and attempted to render them as HTML usingdangerouslySetInnerHTML. For SQL query results, these should be displayed as literal text values, not rendered as HTML.Solution:
escapeHtml()utility function to properly escape HTML entities (<,>,&,",') for safe text displayrenderResultCell()to escape HTML-like strings when displaying SQL query results, ensuring they appear as literal text with visible angle bracketsescapeHtml()functionTechnical Changes:
New function:
escapeHtml()insuperset-frontend/packages/superset-ui-core/src/utils/html.tsx<div>test</div>→<div>test</div>)Updated:
renderResultCell()insuperset-frontend/src/components/FilterableTable/utils.tsxallowHTML=false: Always escapes HTML entitiesallowHTML=trueand string looks like HTML: Escapes it to display as literal text (for SQL results)dangerouslySetInnerHTMLwith escaped content so browser correctly decodes entities for displaySecurity:
The fix maintains security by escaping HTML entities, preventing XSS attacks while displaying all data correctly. Strings are displayed as text, not rendered as HTML.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
SELECT '<div>test</div>' as html_stringshowed empty cellAfter:
SELECT '<div>test</div>' as html_stringshows<div>test</div>with visible angle bracketsTESTING INSTRUCTIONS
html_stringshould show:<div>test</div>(with visible angle brackets)script_stringshould show:<script>alert("xss")</script>(escaped and visible)comparison_stringshould show:a < b and c > d(with visible angle brackets)<div>,<span>,<p>, etc.a <= 10 and b > 20Automated Tests:
escapeHtml()function (7 test cases covering various scenarios)<,>,&,",'charactersADDITIONAL INFORMATION