Skip to content

[New Query - githubsecuritylab/cs/web/web-method-missing-access-control] - ASMX web methods that change data without an authorization check - #281

Draft
felickz wants to merge 2 commits into
mainfrom
copilot/add-query-for-asmx-web-methods
Draft

felickz wants to merge 2 commits into
mainfrom
copilot/add-query-for-asmx-web-methods

Conversation

@felickz

@felickz felickz commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

The standard cs/web/missing-function-level-access-control query only checks MVC controller actions and Web Forms event handlers. It never looks at [WebMethod] methods, which are ASMX operations and static page methods. This PR adds a query that reports those methods when they appear to change data and have no authorization check.

[WebMethod]
public string TransferBalance(long from, long to, double amount) // reported
{
    Withdraw(from, amount);
    Deposit(to, amount);
    return "OK";
}

Query (csharp/src/security/CWE-862/)

  • WebMethodActions.qll: WebMethodActionMethod is an ActionMethod that carries System.Web.Services.WebMethodAttribute.
    • It extends isEdit() with transfer, withdraw, deposit, update and remove.
    • These words are matched only as whole camelCase words and only against the method name.
  • WebMethodMissingAccessControl.ql:
    • The from clause is WebMethodActionMethod, so nothing the standard query already reports is reported again.
    • It reuses the standard needsAuth, hasAuthViaCode and hasAuthViaXml.
    • It replaces hasAuthViaAttribute with a version that skips System.Web.Mvc.AuthorizeAttribute, System.Web.Http.AuthorizeAttribute and their subclasses. Those are filters for the MVC and Web API pipelines and do not run for ASMX.
  • Metadata: @precision medium and @security-severity 7.5, as in the standard query. CWE-285, CWE-284 and CWE-862, plus the experimental tag. The default csharp.qls suite selects it.
  • Query help: WebMethodMissingAccessControl.qhelp.

Changes from the draft in the issue

  • The query has its own id, reports only web methods, and its message is "This web method is missing an authorization check."
  • The Web API Authorize attribute is treated like the MVC one: neither protects a web method.
  • The draft's Web.config was cut off. It is now complete, with <location path="ConfiguredService.asmx"> denying ?. That path is a prefix of the code-behind route WebConfig/ConfiguredService.asmx.cs.
  • The test uses a plain .expected file with BAD/GOOD comments instead of inline $ Alert markers, matching the other tests in this repository.

Test (csharp/test/security/CWE-862/WebMethodMissingAccessControl/)

  • Uses local System.Web stubs in Stubs.cs. The shared System.Web.cs stub has no WebService, HttpContext.User or MVC AuthorizeAttribute.
  • Reported (9):
    • plain BAD methods
    • methods protected only by MVC or Web API [Authorize], on the method or on the class
    • a static page method
    • the App_Code variant
    • a service in the WebConfig/ folder that no <location> rule covers
  • Not reported:
    • a check with IsAuthenticated or IsInRole
    • a non-MVC auth attribute on the method or the class
    • the service covered by the Web.config rule
    • read-only methods, including GetLastUpdated
    • an empty method, and a method without [WebMethod]
  • The standard query reports nothing on this test database.

Known limitations

  • Detection by name: whether a method changes data is guessed from its name. The standard words also match the class name and the file path, so a read-only method in an Admin class is reported.
  • No build: with build-mode: none, an IsInRole call on an unresolved IPrincipal is not recognized as a check. IsAuthenticated still is, through the %auth% name fallback.
  • Attribute names: attributes without "auth" in their name, such as PrincipalPermission, are not counted as authorization.

Follow-ups for the maintainer

  • Add a true positive from a real project.
  • Bump the version of githubsecuritylab/codeql-csharp-queries when cutting the release.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 06:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

…for [WebMethod] methods

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 06:46
@felickz felickz changed the title [WIP] Add query for ASMX web methods authorization check [New Query - githubsecuritylab/cs/web/web-method-missing-access-control] - ASMX web methods that change data without an authorization check Nov 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active findings identify missed access-control alerts, false positives on methods that are not remotely callable, and unsafe remediation guidance that omits required account authorization.

4 open issues

Review effort: Balanced

*/
class WebMethodActionMethod extends ActionMethod {
WebMethodActionMethod() {
this.getAnAttribute().getType() instanceof SystemWebServicesWebMethodAttributeClass
or
this.getName()
// separate camelCase words
.regexpReplaceAll("([a-z])([A-Z])", "$1_$2")
Comment on lines +30 to +32
attr.getType()
.getABaseType*()
.hasFullyQualifiedName(["System.Web.Mvc", "System.Web.Http"], "AuthorizeAttribute")
Comment on lines +54 to +55
The method is fixed by checking that the caller is authenticated (and, ideally, owns the debited
account):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C#: add a query for ASMX web methods that change data without an authorization check

3 participants