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#: Azure Function HttpTrigger SQL Injection is not being detected #15102

Open
DavidJFowler opened this issue Dec 14, 2023 · 1 comment
Open
Labels
question Further information is requested

Comments

@DavidJFowler
Copy link

Description of the issue

CodeQL scan is not picking up SQL Injection vulnerability in the following Azure Function trigger:

using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Logging;
using Dapper;

namespace DavidF.Demo.GithubActions.Functions;

public class HelloWorldFunction
{
    private readonly SqliteConnection _sqliteConnection;
    private readonly ILogger _logger;

    public HelloWorldFunction(ILoggerFactory loggerFactory, SqliteConnection sqliteConnection)
    {
        _sqliteConnection = sqliteConnection;
        _logger = loggerFactory.CreateLogger<HelloWorldFunction>();
    }

    [Function("HelloWorldFunction")]
    public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
    {
        _logger.LogInformation("C# HTTP trigger function processed a request.");

        var sql = $"SELECT * FROM USER WHERE Name = '{req.Query["name"]}'";

        _sqliteConnection.Open();

        var res = await _sqliteConnection.QueryAsync<UserDto>(sql);

        var response = req.CreateResponse(HttpStatusCode.OK);

        await response.WriteAsJsonAsync(res);

        return response;
    }

    public record UserDto(long Id, string Name);
}

Tested in GitHub actions and also locally using CLI:

c:\codeql\codeql.exe database analyze "codeql-db" --format=sarif-latest --output="codeql-output" --threads=0 '..\codeql\csharp\ql\src\Security Features\cwe-089\SqlInjection.ql'
@DavidJFowler DavidJFowler added the question Further information is requested label Dec 14, 2023
@tamasvajk
Copy link
Contributor

Thank you for reporting this issue. The reason for not finding the SQL injection is that we don't have any models for Azure Functions, so we don't find the req parameter as a flow source. I created an internal issue to model Azure Function libraries.

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

No branches or pull requests

2 participants