rspec/rules/S5167/csharp/rule.adoc

39 lines
716 B
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:50:28 +02:00
include::../description.adoc[]
=== Noncompliant code example
2020-06-30 12:50:28 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2020-06-30 12:50:28 +02:00
----
string value = Request.QueryString["value"];
Response.AddHeader("X-Header", value); // Noncompliant
----
=== Compliant solution
2020-06-30 12:50:28 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2020-06-30 12:50:28 +02:00
----
string value = Request.QueryString["value"];
// Allow only alphanumeric characters
if (value == null || !Regex.IsMatch(value, "^[a-zA-Z0-9]+$"))
{
throw new Exception("Invalid value");
}
Response.AddHeader("X-Header", value);
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]