Skip to content

Commit f84b2a9

Browse files
Add support for view locations defined in code through RazoeViewEngineOptions
1 parent 4f5ecb8 commit f84b2a9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

csharp/ql/lib/semmle/code/csharp/security/dataflow/XSSFlowSteps.qll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@ private string getViewSearchTemplate(int i) {
113113
i = 0 and result = "/Views/{1}/{0}.cshtml"
114114
or
115115
i = 1 and result = "/Views/Shared/{0}.cshtml"
116+
or
117+
i = 2 and result = getAViewSearchTemplateInCode()
118+
}
119+
120+
/** Gets an additional template used for view discovery defined in code. */
121+
private string getAViewSearchTemplateInCode() {
122+
exists(StringLiteral str, MethodCall addCall |
123+
addCall.getTarget().hasQualifiedName("System.Collections.Generic", "IList", "Add") and
124+
DataFlow::localExprFlow(str, addCall.getArgument(0)) and
125+
addCall.getQualifier() = getAViewLocationList() and
126+
result = str.getValue()
127+
)
128+
}
129+
130+
/** Gets a list expression containing view search locations */
131+
private Expr getAViewLocationList() {
132+
result
133+
.(PropertyRead)
134+
.getProperty()
135+
.hasQualifiedName("Microsoft.AspNetCore.Mvc.Razor", "RazorViewEngineOptions",
136+
[
137+
"ViewLocationFormats", "PageViewLocationFormats", "AreaViewLocationFormats",
138+
"AreaPageViewLocationFormats"
139+
])
116140
}
117141

118142
/** A filepath that should be searched for a View call. */

0 commit comments

Comments
 (0)