Skip to content

Add new stubs definitions to System.Web #19456

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

Merged
merged 12 commits into from
May 13, 2025

Conversation

5idg5
Copy link
Contributor

@5idg5 5idg5 commented May 2, 2025

@Copilot Copilot AI review requested due to automatic review settings May 2, 2025 21:30
@5idg5 5idg5 requested a review from a team as a code owner May 2, 2025 21:30
@github-actions github-actions bot added the C# label May 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that test suites loading the new System.Web API Controller definitions have their dependencies satisfied by adding the Microsoft.AspNetCore.App framework project to the extractor options.

  • Updated extractor options in security feature and experimental query tests to include Microsoft.AspNetCore.App.csproj
  • Introduced new stub definitions for System.Web.cs and System.Net.cs (not shown) and ensured dependent tests reference the appropriate frameworks

Reviewed Changes

Copilot reviewed 49 out of 49 changed files in this pull request and generated no comments.

Show a summary per file
File Description
csharp/ql/test/query-tests/Security Features/CWE-134/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-114/AssemblyPathInjection/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-112/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-099/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-094/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-091/XMLInjection/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-090/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-079/StoredXSS/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-022/TaintedPath/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/query-tests/Security Features/CWE-020/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-614/RequireSSLSystemWeb/HttpCookiesTrue/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-614/RequireSSLSystemWeb/FormsTrue/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-614/RequireSSLSystemWeb/ConfigFalse/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-614/RequireSSLSystemWeb/ConfigEmpty/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-614/RequireSSLFalseSystemWeb/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-1004/CookieWithoutHttpOnlySystemWeb/HttpCookiesTrue/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-1004/CookieWithoutHttpOnlySystemWeb/ConfigFalse/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-1004/CookieWithoutHttpOnlySystemWeb/ConfigEmpty/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/Security Features/CWE-1004/CookieHttpOnlyFalseSystemWeb/options Added AspNetCore.App project reference to extractor options
csharp/ql/test/experimental/CWE-918/options Added AspNetCore.App project reference to extractor options
Comments suppressed due to low confidence (5)

csharp/ql/test/query-tests/Security Features/CWE-134/options:3

  • After adding the ASP.NET Core framework load, also include the System.Net.cs stub in the options so tests can access the newly added System.Net definitions.
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj

csharp/ql/test/query-tests/Security Features/CWE-114/AssemblyPathInjection/options:3

  • Include the System.Net.cs stub here as well so that any queries depending on System.Net types will resolve correctly.
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj

csharp/ql/test/query-tests/Security Features/CWE-112/options:3

  • Add a loader for the System.Net.cs stub after the System.Web.cs line to cover new System.Net definitions in tests.
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj

csharp/ql/test/query-tests/Security Features/CWE-099/options:3

  • Ensure the System.Net.cs stub is also loaded here so that tests exercising System.Net APIs will pass with the new definitions.
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj

csharp/ql/test/query-tests/Security Features/CWE-094/options:3

  • After including the ASP.NET Core stub, add the System.Net.cs stub so that any queries relying on new System.Net definitions are resolved in this test.
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj

@5idg5
Copy link
Contributor Author

5idg5 commented May 6, 2025

Reverted the changes in System.Net.cs as it was conflicting with the existing definition of the type HttpResponseMessage here ->

public class HttpResponseMessage : System.IDisposable
{
public System.Net.Http.HttpContent Content { get => throw null; set { } }
public HttpResponseMessage() => throw null;
public HttpResponseMessage(System.Net.HttpStatusCode statusCode) => throw null;
public void Dispose() => throw null;
protected virtual void Dispose(bool disposing) => throw null;
public System.Net.Http.HttpResponseMessage EnsureSuccessStatusCode() => throw null;
public System.Net.Http.Headers.HttpResponseHeaders Headers { get => throw null; }
public bool IsSuccessStatusCode { get => throw null; }
public string ReasonPhrase { get => throw null; set { } }
public System.Net.Http.HttpRequestMessage RequestMessage { get => throw null; set { } }
public System.Net.HttpStatusCode StatusCode { get => throw null; set { } }
public override string ToString() => throw null;
public System.Net.Http.Headers.HttpResponseHeaders TrailingHeaders { get => throw null; }
public System.Version Version { get => throw null; set { } }
. Nothing additional needed, existing definition will suffice.

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

Thank you for adding these ❤️
It looks like some of the tests are failing.

@5idg5 5idg5 changed the title Add new stubs definitions to System.Web and System.Net Add new stubs definitions to System.Web May 9, 2025
@5idg5
Copy link
Contributor Author

5idg5 commented May 9, 2025

Hey @michaelnebel or @hvitved

I've pushed some more changes that led to more successful unit tests, but I'm not aware of the intricacies with the public repo testing, so can't figure out the solution for rest of the failures below. Could you please troubleshoot and help to progress this PR?

 FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/CfgConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/DataFlowConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/PrimaryQlClass.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/SsaConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/VariableCaptureConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/DB-CHECK
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/InsecureXMLSettings.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/UntrustedDataInsecureXml.qlref
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/UseXmlSecureResolver.qlref
FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspDirective.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspElement.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspOpenTag.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/CfgConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/DataFlowConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/PrimaryQlClass.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/SsaConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/VariableCaptureConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CodeBehind.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/DB-CHECK
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/comments.ql

@michaelnebel
Copy link
Contributor

michaelnebel commented May 12, 2025

Hey @michaelnebel or @hvitved

I've pushed some more changes that led to more successful unit tests, but I'm not aware of the intricacies with the public repo testing, so can't figure out the solution for rest of the failures below. Could you please troubleshoot and help to progress this PR?

 FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/CfgConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/DataFlowConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/PrimaryQlClass.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/SsaConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/VariableCaptureConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/DB-CHECK
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/InsecureXMLSettings.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/UntrustedDataInsecureXml.qlref
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/UseXmlSecureResolver.qlref
FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspDirective.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspElement.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspOpenTag.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/CfgConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/DataFlowConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/PrimaryQlClass.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/SsaConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/VariableCaptureConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CodeBehind.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/DB-CHECK
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/comments.ql

Very understandable that this causes problems.

  • In the ASP test, the extractor options are inlined in directly in the .cs file (as the asp extractor doesn't support the nostdlib and noconfig options)
  • The test for CWE-611 should preferably be compiled against dll's (as dll meta information is read). To continue doing so, I think that the best approach is to make sure that the content of System.Web.cs doesn't depend on ASP.NET - I will try and re-factor those parts of the stub into a separate file.

I will open a PR, where you can cherry-pick the last three commits (as I don't have permissions to push to this branch): #19473

@5idg5
Copy link
Contributor Author

5idg5 commented May 12, 2025

Hey @michaelnebel or @hvitved
I've pushed some more changes that led to more successful unit tests, but I'm not aware of the intricacies with the public repo testing, so can't figure out the solution for rest of the failures below. Could you please troubleshoot and help to progress this PR?

 FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/CfgConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/DataFlowConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/PrimaryQlClass.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/SsaConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/CONSISTENCY/VariableCaptureConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/DB-CHECK
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/InsecureXMLSettings.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/UntrustedDataInsecureXml.qlref
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/query-tests/Security Features/CWE-611/UseXmlSecureResolver.qlref
FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspDirective.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspElement.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/AspOpenTag.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/CfgConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/DataFlowConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/PrimaryQlClass.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/SsaConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CONSISTENCY/VariableCaptureConsistency.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/CodeBehind.ql
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/DB-CHECK
  FAILED: /home/runner/work/semmle-code/semmle-code/ql/csharp/ql/test/library-tests/asp/basic/comments.ql

Very understandable that this causes problems.

  • In the ASP test, the extractor options are inlined in directly in the .cs file (as the asp extractor doesn't support the nostdlib and noconfig options)
  • The test for CWE-611 should preferably be compiled against dll's (as dll meta information is read). To continue doing so, I think that the best approach is to make sure that the content of System.Web.cs doesn't depend on ASP.NET - I will try and re-factor those parts of the stub into a separate file.

I will open a PR, where you can cherry-pick the last three commits (as I don't have permissions to push to this branch): #19473

Sounds good, thank you!

@5idg5
Copy link
Contributor Author

5idg5 commented May 13, 2025

Tests passed, ready for approval and merge!

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@michaelnebel michaelnebel merged commit 0c0e1d0 into github:main May 13, 2025
16 checks passed
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.

2 participants