Skip to content

1011008: Added New UG content for Input sanitization#7846

Open
ponselvajeganathan wants to merge 10 commits intodevelopmentfrom
1011008-sanitize
Open

1011008: Added New UG content for Input sanitization#7846
ponselvajeganathan wants to merge 10 commits intodevelopmentfrom
1011008-sanitize

Conversation

@ponselvajeganathan
Copy link
Collaborator

Description

Added New UG content for Input sanitization

Code Studio usage(Mandatory)

  • Code Studio used in this PR/MR?

    • Yes
    • No
  • If Yes: Primary use (choose one)

    • Generate new content
    • Refactor/improve existing content
    • Review assistance (explanations/summaries)
    • Other:
  • Outcome

    • Saved time
    • Neutral
    • Cost time
  • If “Cost time” explain in short (1 or 2 lines):

Type of Change

  • New documentation page
  • Update to existing documentation
  • Bug fix (broken links, typos, formatting issues)
  • Structural change (folders, navigation, index)
  • Content improvement (clarity, examples, screenshots)
  • Other (please describe):

Reviewer Checklist (Mandatory)

  • Reviewed the provided Code Studio usages related information
  • Content changes follow UG/Documentation guidelines
  • All provided information reviewed and verified
  • Links and previews checked

@ponselvajeganathan ponselvajeganathan added the cs:used AI was used in this PR label Mar 6, 2026
@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: FAILURE ❌
Source Compilation: SUCCESS ✅
Failure Reason: CI Failure with violation
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 8
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 0
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: SUCCESS ✅
Source Compilation: SUCCESS ✅
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 0
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 0
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0

First, install the package:

```
dotnet add package HtmlSanitizer
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggest Microsoft package, do not suggest third parties.


## TextBox / TextArea

Syncfusion **TextBox** and **TextArea** components bind plain text. Sanitize the value only if you render it as HTML.
Copy link
Collaborator

Choose a reason for hiding this comment

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

modify content like, syncfusion components support sanitization

{% endhighlight %}
{% endtabs %}

## Validation vs. Sanitization
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this validation topic required

Copy link
Collaborator

@kmkrish001 kmkrish001 left a comment

Choose a reason for hiding this comment

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

Address this comments.

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

The running CI Job is terminated due to changes committed on the source branch for this Merge Request and CI triggered for latest commit.

@SyncfusionBuild
Copy link
Contributor

CI Status: ABORTED ❌
Source Compilation: FAILURE ❌
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: SUCCESS ✅
Source Compilation: SUCCESS ✅
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 0
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 0
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0


# Input Sanitization with Syncfusion Blazor Components

Input sanitization ensures that any user-provided content whether typed, pasted, uploaded, or received from external sources is safe to process or display in a Syncfusion Blazor application. Because user input can contain unsafe HTML or script content, sanitization prevents malicious code execution and ensures application integrity.
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the introduction mention which syncfusion API using for sanitization, what are the components below covered.


## Built-In Sanitization Features

Several Syncfusion Blazor components include HTML sanitization capabilities to prevent harmful script or markup from being processed. Components that accept or render HTML content such as the Rich Text Editor have built-in mechanisms to remove unsafe elements before rendering.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not mentioning the built-in option API name

When enabled, automatically removes unsafe tags and attributes such as `<script>` tags, event attributes (such as onload, onclick), and other unsafe content before rendering it. This ensures only clean and safe HTML is allowed in the editor.

## How to Sanitize Input in Blazor

Copy link
Collaborator

Choose a reason for hiding this comment

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

explain this shortly with sample code.

The encoded value ensures the Grid displays safe text without interpreting any malicious input.

## See Also

Copy link
Collaborator

Choose a reason for hiding this comment

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

add csp topic in see also

Sanitized output: x
```

## Types of Attacks Prevented
Copy link
Collaborator

Choose a reason for hiding this comment

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

title not proper


{% endhighlight %}
{% endtabs %}

Copy link
Collaborator

Choose a reason for hiding this comment

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

attach playground sample link for this.

{% highlight razor %}

@page "/sanitize-example"

Copy link
Collaborator

Choose a reason for hiding this comment

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

components namespace not used, which packages...

### Rich Text Editor (RTE)

The Rich Text Editor allows users to input and render HTML content. To prevent unsafe markup from being inserted or displayed, enable the built‑in sanitizer using the `EnableHtmlSanitizer` property.

Copy link
Collaborator

Choose a reason for hiding this comment

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

how to disable the sanitization, if not needed.

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: FAILURE ❌
Source Compilation: SUCCESS ✅
Failure Reason: CI Failure with violation
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 0
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 1
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: SUCCESS ✅
Source Compilation: SUCCESS ✅
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 0
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 0
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0


{% previewsample "https://blazorplayground.syncfusion.com/embed/VXrxDAitJvkRyhWu?appbar=false&editor=false&result=true&errorlist=false&theme=bootstrap5" %}

## Custom Sanitization
Copy link
Collaborator

Choose a reason for hiding this comment

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

No content for this topic Custom Sanitization

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: SUCCESS ✅
Source Compilation: SUCCESS ✅
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 0
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 0
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: SUCCESS ✅
Source Compilation: SUCCESS ✅
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 0
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 0
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0


@using Syncfusion.Blazor.BlockEditor

<sfblockeditor enablehtmlsanitizer="true">
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this proper code to render block editor component in blazor ?


@using Syncfusion.Blazor.BlockEditor

<sfblockeditor enablehtmlsanitizer="false">
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the property enablehtmlsanitizer casing is correct ?


* [Paste Clean-up in Blazor Rich Text Editor](https://blazor.syncfusion.com/documentation/rich-text-editor/paste-cleanup)
* [Content Security Policy (CSP)](https://blazor.syncfusion.com/documentation/common/content-security-policy)
* [Paste Clean-up in Blazor Blcok Editor](https://sfblazor.azurewebsites.net/staging/documentation/block-editor/paste-cleanup)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Block Editor spelling mistakes

{
var cleaned = System.Net.WebUtility.HtmlEncode(UserText);
Items.Add(new ItemRecord { Content = cleaned });
Items = Items.ToList();
Copy link
Collaborator

Choose a reason for hiding this comment

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

unnecessary list reassignment: The code calls Items.Add(...) then Items = Items.ToList(); and StateHasChanged(). This is confusing.

Action: Replace with a clear pattern. Keep Items as List and call Items.Add(...) then StateHasChanged().

```
@code {
string userInput = "<script>alert('XSS')</script> Hello!";
string safeText = System.Net.WebUtility.HtmlEncode(userInput);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use System.Text.Encodings.Web.HtmlEncoder


* [Paste Clean-up in Blazor Rich Text Editor](https://blazor.syncfusion.com/documentation/rich-text-editor/paste-cleanup)
* [Content Security Policy (CSP)](https://blazor.syncfusion.com/documentation/common/content-security-policy)
* [Paste Clean-up in Blazor Blcok Editor](https://sfblazor.azurewebsites.net/staging/documentation/block-editor/paste-cleanup)
Copy link
Collaborator

Choose a reason for hiding this comment

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

do not add staging link


## Built-In Sanitization Features

Several Syncfusion Blazor components include HTML sanitization capabilities to prevent harmful script or markup from being processed. Components that accept or render HTML content such as the Rich Text Editor have built-in `EnableHtmlSanitizer` property to remove unsafe elements before rendering.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mentioned several components but RTE and Block editor alone described, add short details about other components.

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: SUCCESS ✅
Source Compilation: SUCCESS ✅
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 0
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 0
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0

@SyncfusionBuild
Copy link
Contributor

Build Status: INPROGRESS 🔃
Build Location: 1011008-sanitize

@SyncfusionBuild
Copy link
Contributor

CI Status: SUCCESS ✅
Source Compilation: SUCCESS ✅
Build Location: 1011008-sanitize
Technical Error(s): 0
Spelling Error(s): 0
Image Alt Text Error(s): 0
Image Size Error(s): 0
Image Name Error(s): 0
Front matter Error(s): 0
File Path Error(s): 0
CodeSnippet File Path Missing Error(s): 0
Toc Anchor Tags Validation Error(s): 0
MD Tag Validation Error(s): 0


## Overview

Input sanitization is a critical security practice in Syncfusion Blazor applications that handle user-generated content. Syncfusion Blazor components include built-in HTML sanitization (enabled by default in most cases) to safely process and render potentially untrusted content. This guide explains how these features work, focusing especially on the **Rich Text Editor**, **Block Editor** (using `EnableHtmlSanitizer` property), and **DataGrid**.
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of saying most cases add example like, Syncfusion Blazor components that accept HTML have a built‑in sanitizer (for example, the Rich Text Editor's EnableHtmlSanitizer property is enabled by default).

{% endhighlight %}
{% endtabs %}

When enabled the `EnableHtmlSanitizer` property, automatically removes unsafe tags and attributes such as `<script>` tags, event attributes (such as onload, onclick), and other unsafe content before rendering it. This ensures only clean and safe HTML is allowed in the editor.
Copy link
Collaborator

Choose a reason for hiding this comment

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

enabled the EnableHtmlSanitizer property - improvise the sentence.


When the EnableHtmlSanitizer property is enabled, the Block Editor automatically removes unsafe tags and attributes such as `<script>` tags, event attributes (like onload, onclick), javascript: URLs, and other harmful markup before rendering content. This ensures that only clean and trusted HTML remains in the editor output.

To disable the built-in sanitizer (not recommended for untrusted input), set the property to false:
Copy link
Collaborator

Choose a reason for hiding this comment

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

For disable example show in common section single place instead of each component.

@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Inputs
@using System.Text.Encodings.Web
Copy link
Collaborator

Choose a reason for hiding this comment

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

File shows @using System.Text.Encodings.Web but example uses System.Net.WebUtility.HtmlEncode


@code {
string userInput = "<script>alert('XSS')</script> Hello!";
string safeText = System.Net.WebUtility.HtmlEncode(userInput);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@using System.Text.Encodings.Web

@code {
string userInput = "<script>alert('XSS')</script> Hello!";
string safeText = HtmlEncoder.Default.Encode(userInput);
}

<div class="input-row">
<SfTextBox @bind-Value="UserText" Placeholder="Enter text" CssClass="w-100"></SfTextBox>

<SfButton CssClass="e-primary" OnClick="ProcessInputAsync" Type="Button">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Button OnClick attribute uses "ProcessInputAsync" while the method is named ProcessInput (mismatch)

</div>

<div class="mt-2">
<SfGrid @ref="UserGrid" DataSource="Items" AllowPaging="true">
Copy link
Collaborator

Choose a reason for hiding this comment

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

DataSource="Items" should be DataSource="@Items" (Razor binding)

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

Labels

cs:used AI was used in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants