Skip to content

Commit 0d1fb0f

Browse files
authored
Merge pull request github#3509 from hvitved/csharp/html-raw
C#: Recognize more calls to `IHtmlHelper.Raw`
2 parents cafbe14 + ca531cb commit 0d1fb0f

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

csharp/ql/src/semmle/code/csharp/frameworks/microsoft/AspNetCore.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ class MicrosoftAspNetCoreMvcViewFeatures extends Namespace {
2727
}
2828
}
2929

30+
/** The 'Microsoft.AspNetCore.Mvc.Rendering' namespace. */
31+
class MicrosoftAspNetCoreMvcRendering extends Namespace {
32+
MicrosoftAspNetCoreMvcRendering() {
33+
getParentNamespace() instanceof MicrosoftAspNetCoreMvcNamespace and
34+
hasName("Rendering")
35+
}
36+
}
37+
3038
/** An attribute whose type is in the `Microsoft.AspNetCore.Mvc` namespace. */
3139
class MicrosoftAspNetCoreMvcAttribute extends Attribute {
3240
MicrosoftAspNetCoreMvcAttribute() {
@@ -191,11 +199,11 @@ class MicrosoftAspNetCoreMvcController extends Class {
191199
}
192200
}
193201

194-
/** The `Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper` class. */
195-
class MicrosoftAspNetCoreMvcHtmlHelperClass extends Class {
196-
MicrosoftAspNetCoreMvcHtmlHelperClass() {
197-
getNamespace() instanceof MicrosoftAspNetCoreMvcViewFeatures and
198-
hasName("HtmlHelper")
202+
/** The `Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper` interface. */
203+
class MicrosoftAspNetCoreMvcRenderingIHtmlHelperInterface extends Interface {
204+
MicrosoftAspNetCoreMvcRenderingIHtmlHelperInterface() {
205+
getNamespace() instanceof MicrosoftAspNetCoreMvcRendering and
206+
hasName("IHtmlHelper")
199207
}
200208

201209
/** Gets the `Raw` method. */

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,18 @@ class WebPageWriteLiteralToSink extends HtmlSink {
176176
abstract class AspNetCoreHtmlSink extends HtmlSink { }
177177

178178
/**
179-
* An expression that is used as an argument to `HtmlHelper.Raw`, typically in
179+
* An expression that is used as an argument to `IHtmlHelper.Raw`, typically in
180180
* a `.cshtml` file.
181181
*/
182182
class MicrosoftAspNetCoreMvcHtmlHelperRawSink extends AspNetCoreHtmlSink {
183183
MicrosoftAspNetCoreMvcHtmlHelperRawSink() {
184-
this.getExpr() =
185-
any(MicrosoftAspNetCoreMvcHtmlHelperClass h).getRawMethod().getACall().getAnArgument()
184+
exists(Call c, Callable target |
185+
c.getTarget() = target and
186+
target.hasName("Raw") and
187+
target.getDeclaringType().getABaseType*() instanceof
188+
MicrosoftAspNetCoreMvcRenderingIHtmlHelperInterface and
189+
this.getExpr() = c.getAnArgument()
190+
)
186191
}
187192
}
188193

0 commit comments

Comments
 (0)