SanitizeUrl.NET
1.0.0
dotnet add package SanitizeUrl.NET --version 1.0.0
NuGet\Install-Package SanitizeUrl.NET -Version 1.0.0
<PackageReference Include="SanitizeUrl.NET" Version="1.0.0" />
paket add SanitizeUrl.NET --version 1.0.0
#r "nuget: SanitizeUrl.NET, 1.0.0"
// Install SanitizeUrl.NET as a Cake Addin #addin nuget:?package=SanitizeUrl.NET&version=1.0.0 // Install SanitizeUrl.NET as a Cake Tool #tool nuget:?package=SanitizeUrl.NET&version=1.0.0
SanitizeUrl.NET
SanitizeUrl.NET is a lightweight .NET library that sanitizes URLs by removing potentially harmful or unwanted characters. Inspired by Braintree's Sanitize URL for JavaScript, this package ensures URLs are safe for use in web applications, preventing XSS attacks and other vulnerabilities. Easy to integrate, with minimal overhead, making it ideal for secure URL handling in any .NET project.
Installation
To use SanitizeUrl.NET in your C# project, you need to install the NuGet package. Follow these simple steps:
Using NuGet Package Manager
- Open Your Project: Open your project in Visual Studio or your preferred IDE.
- Open the Package Manager Console: Navigate to
Tools
→NuGet Package Manager
→Package Manager Console
. - Install SanitizeUrl.NET: Type the following command and press Enter:
Install-Package SanitizeUrl.NET
Using .NET CLI
Alternatively, you can use .NET Core CLI to install SanitizeUrl.NET. Open your command prompt or terminal and run:
dotnet add package SanitizeUrl.NET
Verifying the Installation
After installation, make sure that SanitizeUrl.NET is listed in your project dependencies to confirm successful installation.
Usage
using SanitizeUrl;
Console.WriteLine(UrlSanitizer.SanitizeUrl("https://example.com")); // 'https://example.com'
Console.WriteLine(UrlSanitizer.SanitizeUrl("http://example.com")); // 'http://example.com'
Console.WriteLine(UrlSanitizer.SanitizeUrl("www.example.com")); // 'http://www.example.com'
Console.WriteLine(UrlSanitizer.SanitizeUrl("mailto:hello@example.com")); // 'mailto:hello@example.com'
Console.WriteLine(
UrlSanitizer.SanitizeUrl("https://example.com")
); // 'https://example.com'
Console.WriteLine(UrlSanitizer.SanitizeUrl("javascript:alert(document.domain)")); // 'about:blank'
Console.WriteLine(UrlSanitizer.SanitizeUrl("jAvasCrIPT:alert(document.domain)")); // 'about:blank'
Console.WriteLine(UrlSanitizer.SanitizeUrl("JaVaScRiP%0at:alert(document.domain)")); // 'about:blank'
// HTML encoded javascript:alert('XSS')
Console.WriteLine(
UrlSanitizer.SanitizeUrl("javascript:alert('XSS')")
); // 'about:blank'
Support the Project
If you find this project useful, consider supporting it by buying me a coffee. Your support is greatly appreciated!
Contributing
Contributions are welcome! If you have a feature to propose or a bug to fix, create a new pull request.
License
This project is licensed under the MIT License.
Acknowledgment
This project is inspired by and built upon the sanitize-url project.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 95 | 9/22/2024 |