2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-01-27 13:42:22 +01:00
String representations of URIs or URLs are prone to parsing and encoding errors which can lead to vulnerabilities. The ``++System.Uri++`` class is a safe alternative and should be preferred.
2020-06-30 12:48:39 +02:00
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:39 +02:00
This rule raises an issue when a property is a string type and its name contains "uri", "Uri", "urn", "Urn", "url" or "Url".
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
using System;
namespace MyLibrary
{
public class MyClass
{
string myUri;
public string MyUri // Noncompliant
{
get { return myURI; }
set { myUri = value; }
}
}
}
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2020-06-30 12:48:39 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
using System;
namespace MyLibrary
{
public class MyClass
{
Uri myUri;
public Uri MyUri
{
get { return myURI; }
set { myUri = value; }
}
}
}
----