Skip to content

Commit 67ab0df

Browse files
committed
C#: Add MarkupString as an HtmlSink
1 parent 0ff7512 commit 67ab0df

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| BlazorTest/Components/MyOutput.razor:5:53:5:57 | access to property Value |
2+
| BlazorTest/Components/Pages/TestPage.razor:11:48:11:55 | access to property UrlParam |
3+
| BlazorTest/Components/Pages/TestPage.razor:20:60:20:69 | access to property QueryParam |
4+
| BlazorTest/Components/Pages/TestPage.razor:29:53:29:63 | access to property InputValue1 |
5+
| BlazorTest/Components/Pages/TestPage.razor:38:53:38:63 | access to property InputValue2 |
6+
| BlazorTest/Components/Pages/TestPage.razor:47:53:47:68 | access to property Value |
7+
| BlazorTest/Components/Pages/TestPage.razor:56:53:56:63 | access to property InputValue3 |
8+
| BlazorTest/Components/Pages/TestPage.razor:65:53:65:63 | access to property InputValue4 |
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/** Provides definitions related to the namespace `Microsoft.AspNetCore.Components`. */
2+
3+
import csharp
4+
private import AspNetCore
5+
6+
/** The `Microsoft.AspNetCore.Components` namespace. */
7+
class MicrosoftAspNetCoreComponents extends Namespace {
8+
MicrosoftAspNetCoreComponents() {
9+
this.getParentNamespace() instanceof MicrosoftAspNetCoreNamespace and
10+
this.hasName("Components")
11+
}
12+
}
13+
14+
/** A struct in the `Microsoft.AspNetCore.Components` namespace. */
15+
class MicrosoftAspNetCoreComponentsStruct extends Struct {
16+
MicrosoftAspNetCoreComponentsStruct() {
17+
this.getNamespace() instanceof MicrosoftAspNetCoreComponents
18+
}
19+
}
20+
21+
/** The `Microsoft.AspNetCore.Components.MarkupString` struct. */
22+
class MicrosoftAspNetCoreComponentsMarkupStringStruct extends MicrosoftAspNetCoreComponentsStruct {
23+
MicrosoftAspNetCoreComponentsMarkupStringStruct() { this.hasName("MarkupString") }
24+
25+
/** Gets the explicit conversion operator from `string` to `StringStruct`. */
26+
ExplicitConversionOperator getOpExplicit() {
27+
result.getDeclaringType() instanceof MicrosoftAspNetCoreComponentsMarkupStringStruct and
28+
result.getReturnType() instanceof MicrosoftAspNetCoreComponentsMarkupStringStruct and
29+
result.getParameter(0).getType() instanceof StringType
30+
}
31+
}

csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsinks/Html.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import csharp
66
private import Remote
77
private import semmle.code.csharp.frameworks.microsoft.AspNetCore
8+
private import semmle.code.csharp.frameworks.microsoft.Blazor
89
private import semmle.code.csharp.frameworks.system.Net
910
private import semmle.code.csharp.frameworks.system.Web
1011
private import semmle.code.csharp.frameworks.system.web.Mvc
@@ -139,6 +140,23 @@ class HtmlString extends HtmlSink {
139140
}
140141
}
141142

143+
/**
144+
* An expression passed to the constructor of a `MarkupString` or converted to a `MarkupString`.
145+
*/
146+
class MarkupStringSink extends HtmlSink {
147+
MarkupStringSink() {
148+
exists(ObjectCreation oc |
149+
oc.getObjectType() instanceof MicrosoftAspNetCoreComponentsMarkupStringStruct and
150+
oc.getAnArgument() = this.getExpr()
151+
)
152+
or
153+
exists(OperatorCall oc |
154+
oc.getTarget() = any(MicrosoftAspNetCoreComponentsMarkupStringStruct s).getOpExplicit() and
155+
oc.getArgument(0) = this.getExpr()
156+
)
157+
}
158+
}
159+
142160
/**
143161
* An expression that is used as an argument to `Page.WriteLiteral`, typically in
144162
* a `.cshtml` file.

0 commit comments

Comments
 (0)