Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Blazor: Add non-local jump node for parameter passing #18930

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

egregius313
Copy link
Contributor

Establishes the pattern that when a variable is passed to a subcomponent, the reads of the set property are considered tainted.

For example, if in the following example Names was tainted,

@foreach (string name in Names)
{
    <DisplayName Name="name"/>
}

Then a read in the DisplayName component would be considered tainted

@* Bad: rendering unsanitized strings *@
<p>@((MarkupString)Name)</p>

@code {
   [Parameter]
   string Name { get; set; }
}

@github-actions github-actions bot added the C# label Mar 5, 2025
@egregius313
Copy link
Contributor Author

egregius313 commented Mar 5, 2025

I am running into an issue here: as far as I can tell from locally testing the characteristic predicate and getAJumpSuccessor, the class appears to be correct. But whenever I test it, the flow is not going from the source (the Name parameter in NameList.cs) to the sink ((MarkupString)TheName in Name.cs)

Update: It appears that changing them to share a variable fixed the issue (commit)

@egregius313 egregius313 requested review from hvitved and tamasvajk March 5, 2025 06:02
@@ -0,0 +1 @@
Security Features/CWE-079/XSS.ql

Check warning

Code scanning / CodeQL

Query test without inline test expectations Warning test

Query test does not use inline test expectations.
@egregius313 egregius313 marked this pull request as ready for review March 5, 2025 06:11
@egregius313 egregius313 requested a review from a team as a code owner March 5, 2025 06:11
@egregius313 egregius313 force-pushed the egregius313/csharp/blazor/parameter-passing-jumpnode branch from 96566b5 to 133c6fa Compare March 5, 2025 06:13
}

private class ComponentParameterJump extends DataFlow::NonLocalJumpNode {
ParameterPassingCall call;

Check notice

Code scanning / CodeQL

Field only used in CharPred Note

Field is only used in CharPred.
Copy link
Contributor

@tamasvajk tamasvajk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might be able to add a single line of code to the integration tests, and see if the flow is working there as well. You could add something like the below to the TestPage.razor:

<MyOutput Value="@QueryParam" />

and this should result in an XSS vulnerability.

Comment on lines +162 to +164
exists(NameOfExpr ne | ne = this.getArgument(1) |
result.getAnAccess() = ne.getAccess().(MemberAccess)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also work if instead of a nameof, the name of the property is directly referenced as a string literal?

@@ -0,0 +1 @@
Security Features/CWE-079/XSS.ql

Check warning

Code scanning / CodeQL

Query test without inline test expectations Warning

Query test does not use inline test expectations.
@@ -0,0 +1 @@
Security Features/CWE-079/XSS.ql

Check warning

Code scanning / CodeQL

Query test without inline test expectations Warning

Query test does not use inline test expectations.
@@ -0,0 +1 @@
Security Features/CWE-079/XSS.ql

Check warning

Code scanning / CodeQL

Query test without inline test expectations Warning

Query test does not use inline test expectations.
@Hamid054
Copy link

Hamid054 commented Mar 9, 2025

[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants