Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML <br> tag not rendering in query results #31015

Open
2 of 3 tasks
hf-13 opened this issue Nov 21, 2024 · 1 comment
Open
2 of 3 tasks

HTML <br> tag not rendering in query results #31015

hf-13 opened this issue Nov 21, 2024 · 1 comment

Comments

@hf-13
Copy link

hf-13 commented Nov 21, 2024

Bug description

Description

When running a SQL query that includes an HTML <br> tag, Superset is not rendering the tag as expected. Instead, it's being stripped from the output.

Steps to Reproduce

  1. Run the following SQL query:
SELECT 'salary<=>salary<br>test' AS result;
  1. Expected result: The output should display the exact text as it appears in the query.
  2. Actual result: The output is displayed as "salarysalary" on a single line, with the <br> tag and subsequent text removed.

Configuration Attempted

The following configuration has been applied in a Kubernetes deployment using Helm:

FEATURE_FLAGS = {
 'ESCAPE_MARKDOWN_HTML': False,
}
HTML_SANITIZATION = True
HTML_SANITIZATION_SCHEMA_EXTENSIONS = {
 "attributes": {
     "*": ["style", "className", "class"],
 },
 "tagNames": ["br"]
}

It all was confirmed with superset shell

from superset.app import app
print(app.config)

Additional Information

  • Superset is deployed on Kubernetes using Helm.
  • The issue persists even with Talisman disabled (TALISMAN_ENABLED = False).
  • Various combinations of HTML sanitization settings have been tried without success.

Environment

  • Superset version: 4.0.2
  • Kubernetes version: 1.30
  • Helm chart version: 0.12.11
  • Database type: postgresql

Question

Is there a way to configure Superset to properly render HTML tags, specifically the <br> tag, in query results while maintaining security?

Screenshots/recordings

No response

Superset version

4.1.0

Python version

3.10

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Copy link

dosubot bot commented Nov 21, 2024

I found a similar issue related to HTML rendering in Superset. The issue of improper input validation and sanitization, which can affect how HTML tags are handled, was discussed in this closed issue. The suggested solution involved implementing a Content Security Policy (CSP) using the Talisman extension to mitigate XSS attacks by specifying valid sources for executable scripts.

In your case, since you are trying to render the <br> tag in query results, you have already attempted to extend the HTML sanitization schema to include the br tag. However, it seems that the sanitization process might still be stripping it out.

Here are a few things you can try:

  1. Verify HTML Sanitization Settings: Ensure that your HTML_SANITIZATION_SCHEMA_EXTENSIONS is correctly configured to allow the br tag. It seems you have already done this, but double-checking might help.

  2. Frontend Configuration: Check if the frontend configuration allows HTML rendering. The ResultSet component in Superset's frontend has a property allowHTML that controls HTML rendering in query results. This is set based on a local storage key LocalStorageKeys.SqllabIsRenderHtmlEnabled, which defaults to true [1].

  3. Test HTML Rendering: You can test if the HTML rendering is working by checking the ResultSet component's behavior. If the allowHTML flag is set to true, it should render HTML content.

  4. Review HTML Sanitization Tests: Superset includes tests for HTML sanitization, such as sanitizeHtml and sanitizeHtmlIfNeeded, which ensure that HTML content is handled safely [2]. Reviewing these tests might provide insights into how HTML tags are processed.

If these steps do not resolve the issue, it might be worth investigating further into the frontend code to ensure that the allowHTML setting is correctly applied and that no other configurations are overriding your settings.

To continue talking to Dosu, mention @dosu.

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

No branches or pull requests

1 participant