Skip to content

Commit ace3b3c

Browse files
felickzCopilot
andcommitted
Address CCR: require implicit-this receiver for bracket calls
Copilot Code Review correctly flagged that isBracketedForTagHelperAttribute never related the receivers of beginCall/writeLiteral/endCall, so a bracket on one page instance could theoretically be mistaken for a bracket around a WriteLiteral call on a different page (e.g. otherPage.BeginWriteTagHelperAttribute(); this.WriteLiteral(model); otherPage.EndWriteTagHelperAttribute();). Require all three calls to have an implicit his qualifier, which is how the Razor source generator always emits them, guaranteeing they act on the same page instance. Re-verified: XSS.ql compiles, all 6 CWE-079 tests pass, and the real customer reproduction database still shows the FP suppressed and the genuine Html.Raw positive control still reported. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 20c1033 commit ace3b3c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

  • csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsinks

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,23 @@ class MicrosoftAspNetCoreMvcHtmlHelperRawSink extends AspNetCoreHtmlSink {
196196
* are the immediately enclosing bracket around `writeLiteral` on every path that reaches it (that
197197
* is, the bracket opened by `beginCall` is still open, and not yet closed by some other `endCall`,
198198
* at the point `writeLiteral` executes).
199+
*
200+
* `beginCall`, `writeLiteral`, and `endCall` are additionally required to have an implicit `this`
201+
* qualifier, which is how the Razor source generator always emits these calls. This ensures all
202+
* three calls act on the same page instance, so a bracket on one page cannot be mistaken for a
203+
* bracket around a `WriteLiteral` call on a different page.
199204
*/
200205
private predicate isBracketedForTagHelperAttribute(Call writeLiteral) {
201206
exists(
202-
MicrosoftAspNetCoreMvcRazorPageBase page, Call beginCall, Call endCall, int i, int j, int k
207+
MicrosoftAspNetCoreMvcRazorPageBase page, MethodCall beginCall, MethodCall endCall, int i,
208+
int j, int k
203209
|
204210
writeLiteral = page.getWriteLiteralMethod().getACall() and
205211
beginCall = page.getBeginWriteTagHelperAttributeMethod().getACall() and
206212
endCall = page.getEndWriteTagHelperAttributeMethod().getACall() and
213+
writeLiteral.(QualifiableExpr).hasImplicitThisQualifier() and
214+
beginCall.hasImplicitThisQualifier() and
215+
endCall.hasImplicitThisQualifier() and
207216
writeLiteral.getBasicBlock().getNode(i) = beginCall.getControlFlowNode() and
208217
writeLiteral.getBasicBlock().getNode(j) = writeLiteral.getControlFlowNode() and
209218
writeLiteral.getBasicBlock().getNode(k) = endCall.getControlFlowNode() and

0 commit comments

Comments
 (0)