UrlSanitizer Class
Validates URLs to prevent XSS attacks by checking for dangerous protocols and patterns.
public static class UrlSanitizerExample
Check if a URL is safe:
Assert.True(UrlSanitizer.IsSafeUrl("https://example.com"));
Assert.False(UrlSanitizer.IsSafeUrl("javascript:alert('xss')"));Methods
| Name | Description |
|---|---|
| IsSafeSrcset(string?) | Determines whether a srcset value (used for responsive images) is safe by validating all URLs in the comma-separated list. |
| IsSafeUrl(string?) | Determines whether a URL is safe by checking if it uses an allowed protocol (http, https, mailto, ftp, tel, file) or is a relative URL, or a safe data URL. |