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

CA3003 triggers from CancellationToken #7423

Open
DanielRouxSA opened this issue Sep 27, 2024 · 0 comments
Open

CA3003 triggers from CancellationToken #7423

DanielRouxSA opened this issue Sep 27, 2024 · 0 comments

Comments

@DanielRouxSA
Copy link

DanielRouxSA commented Sep 27, 2024

Analyzer

Diagnostic ID: CA3003: Review code for regex injection vulnerabilities

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: SDK 8.0.400

Describe the bug

I have an ASP.NET web service which has a few controllers that interact with the file system. One of the controllers makes an async call to an SQL database and uses the result of that call as a parameter to System.IO calls. Given the async nature of the controller, I have added a CancellationToken parameter to the method, and pass it to the async database call. This eventually results in CA3003 triggering on the System.IO calls that use the string value (a folder path) that is returned from the database.

This seems to be a false positive to me, firstly because in ASP.NET the CancellationToken is injected, not provided from an external source. Additionally, I don't see how a CancellationToken could be used to taint file system operations.

Steps To Reproduce

Hereby a minimal example of a controller method that triggers CA3003 from a CancellationToken:

private async Task<IActionResult> PostV1Async(CancellationToken cancellationToken)
{
    string incrementalDownloadTempPath = await context.GetConfigStringAsync("IncrementalDownloadTempPath", cancellationToken);

    if (Directory.Exists(incrementalDownloadTempPath) == false) // CA3003 Potential file path injection vulnerability was found where 'bool Directory.Exists(string? path)' in method 'Task<IActionResult> ExampleController.PostV1Async(CancellationToken cancellationToken)' may be tainted by user-controlled data from 'CancellationToken cancellationToken' in method 'Task<IActionResult> ExampleController.PostAsync(string? sessionGUID, CancellationToken cancellationToken)'.
    {
        return StatusCode(StatusCodes.Status500InternalServerError, "The IncrementalDownloadTempPath directory does not exist.");
    }

    return Ok();
}

The above method is truncated; the full method performs additional work, but this minimal example is sufficient to demonstrate the analyzer triggering.

Expected behavior

CA3003 is not triggered from a CancellationToken.

Actual behavior

CA3003 is triggered from a CancellationToken.

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

No branches or pull requests

1 participant