github / github/codeql

C#: Azure Function HttpTrigger SQL Injection is not being detected

Đang mở
#15,102 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

**Description of the issue**

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

```csharp
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();
}

[Function("HelloWorldFunction")]
public async Task 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(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:

```powershell
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'
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.