Skip to content

Conversation

@rishiraj-58
Copy link

@rishiraj-58 rishiraj-58 commented Nov 18, 2025

Summary

Fixes issue where custom CSS styling in the Form node gets HTML encoded (turning > into > etc.), breaking CSS selectors. The sanitizeCustomCss function was using sanitize-html which HTML-encodes special characters, making CSS selectors like #n8n-form > div.form-header > p non-functional.

Changes:

  • Replace sanitize-html with regex-based sanitization for CSS
  • Preserves CSS syntax (>, <, &, etc.) while preventing XSS attacks
  • Removes closing </style> tags to prevent breaking out of style tag
  • Removes script tags and other HTML tags (maintains security)

Testing:

  • Verified CSS selectors with > work correctly (e.g., #n8n-form > div.form-header > p)
  • Verified script tags are still removed (security maintained)
  • Verified closing style tags are removed (prevents XSS breakout)
  • Tested with various CSS selectors containing >, <, & characters
image

Related Linear tickets, Github issues, and Community forum posts

Fixes #21959

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

Note

Update CSS sanitization to strip HTML/script and closing style tags without HTML-encoding, preserving CSS selectors.

  • Form utils (packages/nodes-base/nodes/Form/utils/utils.ts):
    • Update sanitizeCustomCss to use regex-based sanitization instead of sanitize-html.
      • Removes closing </style>, <script> blocks, and other HTML tags.
      • Preserves CSS characters (>, <, &) to avoid breaking selectors.
      • Trims sanitized output.

Written by Cursor Bugbot for commit 3194017. This will update automatically on new commits. Configure here.

rishiraj-58 and others added 2 commits November 18, 2025 16:26
Replace sanitize-html with regex-based sanitization for CSS to preserve
CSS syntax (>, <, &) while preventing XSS attacks. This fixes the issue
where CSS selectors with > were encoded as &gt; breaking the selectors.

- Remove closing style tags to prevent breaking out of <style> tag
- Remove script tags (case-insensitive, handles various formats)
- Remove any other HTML tags
- Preserve CSS syntax characters

Fixes n8n-io#21959
@n8n-assistant n8n-assistant bot added community Authored by a community member node/improvement New feature or request in linear Issue or PR has been created in Linear for internal review labels Nov 18, 2025
@n8n-assistant
Copy link

n8n-assistant bot commented Nov 18, 2025

Hey @rishiraj-58,

Thank you for your contribution. We appreciate the time and effort you’ve taken to submit this pull request.

Before we can proceed, please ensure the following:
• Tests are included for any new functionality, logic changes or bug fixes.
• The PR aligns with our contribution guidelines.

Regarding new nodes:
We no longer accept new nodes directly into the core codebase. Instead, we encourage contributors to follow our Community Node Submission Guide to publish nodes independently.

If your node integrates with an AI service that you own or represent, please email [email protected] and we will be happy to discuss the best approach.

About review timelines:
This PR has been added to our internal tracker as "GHC-5537". While we plan to review it, we are currently unable to provide an exact timeframe. Our goal is to begin reviews within a month, but this may change depending on team priorities. We will reach out when the review begins.

Thank you again for contributing to n8n.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 1 file

Prompt for AI agents (all 2 issues)

Understand the root cause of the following 2 issues and fix them.


<file name="packages/nodes-base/nodes/Form/utils/utils.ts">

<violation number="1" location="packages/nodes-base/nodes/Form/utils/utils.ts:128">
Rule violated: **Tests**

Community PR Guidelines §2 require PRs to include tests; this rewrite of the sanitizeCustomCss security logic ships without any automated unit or workflow tests verifying the new sanitization behavior.</violation>

<violation number="2" location="packages/nodes-base/nodes/Form/utils/utils.ts:135">
Entity-encoded closing tags (e.g. `&amp;lt;/style&amp;gt;`) are no longer stripped, letting attackers escape the `&lt;style&gt;` block and inject arbitrary HTML/JS when forms render custom CSS.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

// Remove script tags (case-insensitive, handles various formats)
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
// Remove any other HTML tags
.replace(/<[^>]*>/g, '')
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entity-encoded closing tags (e.g. &lt;/style&gt;) are no longer stripped, letting attackers escape the <style> block and inject arbitrary HTML/JS when forms render custom CSS.

Prompt for AI agents
Address the following comment on packages/nodes-base/nodes/Form/utils/utils.ts at line 135:

<comment>Entity-encoded closing tags (e.g. `&amp;lt;/style&amp;gt;`) are no longer stripped, letting attackers escape the `&lt;style&gt;` block and inject arbitrary HTML/JS when forms render custom CSS.</comment>

<file context>
@@ -123,13 +123,18 @@ export const prepareFormFields = (context: IWebhookFunctions, fields: FormFields
+			// Remove script tags (case-insensitive, handles various formats)
+			.replace(/&lt;script\b[^&lt;]*(?:(?!&lt;\/script&gt;)&lt;[^&lt;]*)*&lt;\/script&gt;/gi, &#39;&#39;)
+			// Remove any other HTML tags
+			.replace(/&lt;[^&gt;]*&gt;/g, &#39;&#39;)
+			.trim()
+	);
</file context>
Fix with Cubic

});
// Remove potentially dangerous HTML/script tags and prevent style tag breakout
// This preserves CSS syntax (>, <, &, etc.) while preventing XSS attacks
return (
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule violated: Tests

Community PR Guidelines §2 require PRs to include tests; this rewrite of the sanitizeCustomCss security logic ships without any automated unit or workflow tests verifying the new sanitization behavior.

Prompt for AI agents
Address the following comment on packages/nodes-base/nodes/Form/utils/utils.ts at line 128:

<comment>Community PR Guidelines §2 require PRs to include tests; this rewrite of the sanitizeCustomCss security logic ships without any automated unit or workflow tests verifying the new sanitization behavior.</comment>

<file context>
@@ -123,13 +123,18 @@ export const prepareFormFields = (context: IWebhookFunctions, fields: FormFields
-	});
+	// Remove potentially dangerous HTML/script tags and prevent style tag breakout
+	// This preserves CSS syntax (&gt;, &lt;, &amp;, etc.) while preventing XSS attacks
+	return (
+		css
+			// Remove closing style tags to prevent breaking out of &lt;style&gt; tag
</file context>
Fix with Cubic

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

Labels

community Authored by a community member in linear Issue or PR has been created in Linear for internal review node/improvement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Form node: Custom styling gets HTML encoded! (turning > into &gt; etc.)

1 participant