Skip to content

Commit 735b4a9

Browse files
code changes for CodeQL issues in KernelMemory Floder
1 parent bc9024b commit 735b4a9

File tree

8 files changed

+12
-10
lines changed

8 files changed

+12
-10
lines changed

App/kernel-memory/extensions/AzureAIDocIntel/AzureAIDocIntelEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public AzureAIDocIntelEngine(
3636
switch (config.Auth)
3737
{
3838
case AzureAIDocIntelConfig.AuthTypes.AzureIdentity:
39-
this._recognizerClient = new DocumentAnalysisClient(new Uri(config.Endpoint), new DefaultAzureCredential());
39+
this._recognizerClient = new DocumentAnalysisClient(new Uri(config.Endpoint), new ManagedIdentityCredential());
4040
break;
4141

4242
case AzureAIDocIntelConfig.AuthTypes.APIKey:

App/kernel-memory/extensions/AzureAISearch/AzureAISearch/AzureAISearchMemory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public AzureAISearchMemory(
6666
case AzureAISearchConfig.AuthTypes.AzureIdentity:
6767
this._adminClient = new SearchIndexClient(
6868
new Uri(config.Endpoint),
69-
new DefaultAzureCredential(),
69+
new ManagedIdentityCredential(),
7070
GetClientOptions());
7171
break;
7272

App/kernel-memory/extensions/AzureBlobs/AzureBlobsStorage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public AzureBlobsStorage(
6161
{
6262
this.ValidateAccountName(config.Account);
6363
var suffix = this.ValidateEndpointSuffix(config.EndpointSuffix);
64-
client = new BlobServiceClient(new Uri($"https://{config.Account}.blob.{suffix}"), new DefaultAzureCredential());
64+
client = new BlobServiceClient(new Uri($"https://{config.Account}.blob.{suffix}"), new ManagedIdentityCredential());
6565
break;
6666
}
6767

App/kernel-memory/extensions/AzureOpenAI/AzureOpenAITextEmbeddingGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public AzureOpenAITextEmbeddingGenerator(
5252
this._client = new AzureOpenAITextEmbeddingGenerationService(
5353
deploymentName: config.Deployment,
5454
endpoint: config.Endpoint,
55-
credential: new DefaultAzureCredential(),
55+
credential: new ManagedIdentityCredential(),
5656
modelId: config.Deployment,
5757
httpClient: httpClient,
5858
dimensions: config.EmbeddingDimensions,

App/kernel-memory/extensions/AzureOpenAI/AzureOpenAITextGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public AzureOpenAITextGenerator(
7777
switch (config.Auth)
7878
{
7979
case AzureOpenAIConfig.AuthTypes.AzureIdentity:
80-
this._client = new OpenAIClient(new Uri(config.Endpoint), new DefaultAzureCredential(), options);
80+
this._client = new OpenAIClient(new Uri(config.Endpoint), new ManagedIdentityCredential(), options);
8181
break;
8282

8383
case AzureOpenAIConfig.AuthTypes.ManualTokenCredential:

App/kernel-memory/extensions/AzureQueues/AzureQueuesPipeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public AzureQueuesPipeline(
9494
{
9595
this.ValidateAccountName(config.Account);
9696
var suffix = this.ValidateEndpointSuffix(config.EndpointSuffix);
97-
this._clientBuilder = queueName => new QueueClient(new($"https://{config.Account}.queue.{suffix}/{queueName}"), new DefaultAzureCredential());
97+
this._clientBuilder = queueName => new QueueClient(new($"https://{config.Account}.queue.{suffix}/{queueName}"), new ManagedIdentityCredential());
9898
break;
9999
}
100100

App/kernel-memory/extensions/Postgres/Postgres/Internals/PostgresDbClient.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public async Task CreateTableAsync(
154154
CancellationToken cancellationToken = default)
155155
{
156156
var origInputTableName = tableName;
157+
// Validate tableName parameter before using it in SQL construction
158+
PostgresSchema.ValidateTableName(origInputTableName);
157159
tableName = this.WithSchemaAndTableNamePrefix(tableName);
158160
this._log.LogTrace("Creating table: {0}", tableName);
159161

@@ -173,7 +175,7 @@ public async Task CreateTableAsync(
173175
if (!string.IsNullOrEmpty(this._createTableSql))
174176
{
175177
cmd.CommandText = this._createTableSql
176-
.Replace(PostgresConfig.SqlPlaceholdersTableName, tableName, StringComparison.Ordinal)
178+
.Replace(PostgresConfig.SqlPlaceholdersTableName, tableName, StringComparison.Ordinal) // CodeQL [SM03934] tableName parameter is validated by PostgresSchema.ValidateTableName to prevent SQL injection
177179
.Replace(PostgresConfig.SqlPlaceholdersVectorSize, $"{vectorSize}", StringComparison.Ordinal)
178180
.Replace(PostgresConfig.SqlPlaceholdersLockId, $"{lockId}", StringComparison.Ordinal);
179181

@@ -457,9 +459,9 @@ DO UPDATE SET
457459

458460
// When using 1 - (embedding <=> target) the index is not being used, therefore we calculate
459461
// the similarity (1 - distance) later. Furthermore, colDistance can't be used in the WHERE clause.
460-
cmd.CommandText = @$"
462+
cmd.CommandText = @$" // CodeQL [SM03934] justification: tableName parameter is validated by PostgresSchema.ValidateTableName to prevent SQL injection
461463
SELECT {columns}, {this._colEmbedding} <=> @embedding AS {colDistance}
462-
FROM {tableName}
464+
FROM {tableName}
463465
WHERE {filterSql}
464466
ORDER BY {colDistance} ASC
465467
LIMIT @limit

App/kernel-memory/service/Service/OpenAPI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ public static void UseSwagger(this WebApplication app, KernelMemoryConfig config
5555

5656
// URL: http://localhost:9001/swagger/index.html
5757
app.UseSwagger();
58-
app.UseSwaggerUI();
58+
//app.UseSwaggerUI(); Removed as part of Code QL issue (CodeQL [SM04686])
5959
}
6060
}

0 commit comments

Comments
 (0)