Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 7ea0901

Browse files
authored
Update .NET libraries which have security problems in transitive dependencies (#2967)
The existing versions of these libraries have dependencies on packages with known vulnerabilities. Updating the ADO packages fixes the following: - `Newtonsoft.Json` (High) GHSA-5crp-9r3c-p9vr - `System.Data.SqlClient` (Moderate) GHSA-8g2p-5pqh-5jmc - `System.Drawing.Common` (Critical) GHSA-rxg9-xrhp-64gj Updating the Identity packages fixes the following: - `System.Security.Cryptography.Xml` (Moderate) GHSA-2m65-m22p-9wjw Updating the System.Text.RegularExpressions package fixed: - `System.Text.RegularExpressions` (High) GHSA-cmhx-cq75-c4mj Updating the System.Net.Http package (in test project) fixed: - `System.Net.Http` (High) GHSA-7jgj-8wvc-jh57
1 parent 96db6d4 commit 7ea0901

15 files changed

+605
-691
lines changed

src/ApiService/ApiService/ApiService.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,16 @@
3737
<PackageReference Include="Azure.Storage.Queues" Version="12.11.0" />
3838
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
3939
<PackageReference Include="Microsoft.Graph" Version="4.37.0" />
40-
<PackageReference Include="Microsoft.Identity.Client" Version="4.46.2" />
41-
<PackageReference Include="Microsoft.Identity.Web.TokenCache" Version="1.23.1" />
40+
<PackageReference Include="Microsoft.Identity.Client" Version="4.52.0" />
41+
<PackageReference Include="Microsoft.Identity.Web.TokenCache" Version="2.7.0" />
4242
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.22.1" />
4343
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
4444
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.SignalRService" Version="1.7.0" />
45+
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
4546
<PackageReference Include="TaskTupleAwaiter" Version="2.0.0" />
4647
<PackageReference Include="Scriban" Version="5.5.0" />
4748
<PackageReference Include="Octokit" Version="2.0.1" />
48-
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="19.209.0-preview" />
49+
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="19.219.0-preview" />
4950
<PackageReference Include="SmartAnalyzers.CSharpExtensions.Annotations" Version="4.2.7" />
5051
</ItemGroup>
5152
<ItemGroup>

src/ApiService/ApiService/onefuzzlib/ConfigOperations.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ public ConfigOperations(ILogTracer log, IOnefuzzContext context, IMemoryCache ca
2222
_cache = cache;
2323
}
2424

25-
private sealed record InstanceConfigCacheKey();
26-
private static readonly InstanceConfigCacheKey _key = new(); // singleton key
25+
private static readonly object _instanceConfigCacheKey = new(); // singleton key; we only need hashcode/equality
2726
public Task<InstanceConfig> Fetch()
28-
=> _cache.GetOrCreateAsync(_key, async entry => {
27+
=> _cache.GetOrCreateAsync(_instanceConfigCacheKey, async entry => {
2928
entry = entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(1)); // cached for 1 minute
3029
var key = _context.ServiceConfiguration.OneFuzzInstanceName ?? throw new Exception("Environment variable ONEFUZZ_INSTANCE_NAME is not set");
3130
return await GetEntityAsync(key, key);
32-
});
31+
})!; // NULLABLE: only this class inserts _instanceConfigCacheKey so it cannot be null
3332

3433
public async Async.Task Save(InstanceConfig config, bool isNew = false, bool requireEtag = false) {
3534
var newConfig = config with { InstanceName = _context.ServiceConfiguration.OneFuzzInstanceName ?? throw new Exception("Environment variable ONEFUZZ_INSTANCE_NAME is not set") };
@@ -52,7 +51,7 @@ public async Async.Task Save(InstanceConfig config, bool isNew = false, bool req
5251
}
5352

5453
if (r.IsOk) {
55-
_ = _cache.Set(_key, newConfig);
54+
_ = _cache.Set(_instanceConfigCacheKey, newConfig);
5655
}
5756

5857
await _context.Events.SendEvent(new EventInstanceConfigUpdated(newConfig));

src/ApiService/ApiService/onefuzzlib/Creds.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,15 @@ public SubscriptionResource GetSubscriptionResource() {
9595
return ArmClient.GetSubscriptionResource(id);
9696
}
9797

98+
private static readonly object _baseRegionKey = new(); // we only need equality/hashcode
9899
public Async.Task<Region> GetBaseRegion() {
99-
return _cache.GetOrCreateAsync(nameof(GetBaseRegion), async _ => {
100+
return _cache.GetOrCreateAsync(_baseRegionKey, async _ => {
100101
var rg = await ArmClient.GetResourceGroupResource(GetResourceGroupResourceIdentifier()).GetAsync();
101102
if (rg.GetRawResponse().IsError) {
102103
throw new Exception($"Failed to get base region due to [{rg.GetRawResponse().Status}] {rg.GetRawResponse().ReasonPhrase}");
103104
}
104105
return Region.Parse(rg.Value.Data.Location.Name);
105-
});
106+
})!; // NULLABLE: only this method inserts _baseRegionKey so it cannot be null
106107
}
107108

108109
public Uri GetInstanceUrl() {
@@ -145,9 +146,10 @@ public async Async.Task<GenericResource> GetData(GenericResource resource) {
145146
return resource;
146147
}
147148

149+
private static readonly object _regionsKey = new(); // we only need equality/hashcode
148150
public Task<IReadOnlyList<Region>> GetRegions()
149151
=> _cache.GetOrCreateAsync<IReadOnlyList<Region>>(
150-
nameof(Creds) + "." + nameof(GetRegions),
152+
_regionsKey,
151153
async entry => {
152154
// cache for one day
153155
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(1);
@@ -156,8 +158,7 @@ public Task<IReadOnlyList<Region>> GetRegions()
156158
.GetLocationsAsync()
157159
.Select(x => Region.Parse(x.Name))
158160
.ToListAsync();
159-
});
160-
161+
})!; // NULLABLE: only this method inserts _regionsKey so it cannot be null
161162
}
162163

163164

src/ApiService/ApiService/onefuzzlib/LogAnalytics.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ private AccessToken GetToken() {
3131
return _creds.GetIdentity().GetToken(new TokenRequestContext(scopes));
3232
}
3333

34+
private static readonly object _monitorSettingsKey = new(); // we only need equality/hashcode
3435
public Async.Task<MonitorSettings> GetMonitorSettings() =>
35-
_cache.GetOrCreateAsync(nameof(GetMonitorSettings), entry => {
36+
_cache.GetOrCreateAsync(_monitorSettingsKey, entry => {
3637
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1);
3738
return GetMonitorSettingsInternal();
38-
});
39+
})!; // NULLABLE: only this method inserts _monitorSettingsKey so it cannot be null
3940

4041
public async Async.Task<MonitorSettings> GetMonitorSettingsInternal() {
4142
var token = GetToken();

src/ApiService/ApiService/onefuzzlib/Storage.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ public ArmClient GetMgmtClient() {
117117
return _armClient;
118118
}
119119

120+
private static readonly object _corpusAccountsKey = new(); // we only need equality/hashcode
120121
public IReadOnlyList<ResourceIdentifier> CorpusAccounts() {
121-
return _cache.GetOrCreate<IReadOnlyList<ResourceIdentifier>>("CorpusAccounts", cacheEntry => {
122+
return _cache.GetOrCreate<IReadOnlyList<ResourceIdentifier>>(_corpusAccountsKey, cacheEntry => {
122123
var skip = GetFuncStorage();
123124
var results = new List<ResourceIdentifier> { GetFuzzStorage() };
124125

@@ -147,7 +148,7 @@ public IReadOnlyList<ResourceIdentifier> CorpusAccounts() {
147148

148149
_log.Info($"corpus accounts: {JsonSerializer.Serialize(results)}");
149150
return results;
150-
});
151+
})!; // NULLABLE: only this method inserts _corpusAccountsKey so it cannot be null
151152
}
152153

153154
public ResourceIdentifier GetPrimaryAccount(StorageType storageType)
@@ -194,7 +195,7 @@ public Task<BlobServiceClient> GetBlobServiceClientForAccountName(string account
194195
var accountKey = await GetStorageAccountKey(accountName);
195196
var skc = new StorageSharedKeyCredential(accountName, accountKey);
196197
return new BlobServiceClient(GetBlobEndpoint(accountName), skc);
197-
});
198+
})!; // NULLABLE: only this method inserts BlobClientKey so result cannot be null
198199
}
199200

200201
sealed record TableClientKey(string AccountName);
@@ -204,7 +205,7 @@ public Task<TableServiceClient> GetTableServiceClientForAccountName(string accou
204205
var accountKey = await GetStorageAccountKey(accountName);
205206
var skc = new TableSharedKeyCredential(accountName, accountKey);
206207
return new TableServiceClient(GetTableEndpoint(accountName), skc);
207-
});
208+
})!; // NULLABLE: only this method inserts TableClientKey so result cannot be null
208209

209210
sealed record QueueClientKey(string AccountName);
210211
private static readonly QueueClientOptions _queueClientOptions = new() { MessageEncoding = QueueMessageEncoding.Base64 };
@@ -214,5 +215,5 @@ public Task<QueueServiceClient> GetQueueServiceClientForAccountName(string accou
214215
var accountKey = await GetStorageAccountKey(accountName);
215216
var skc = new StorageSharedKeyCredential(accountName, accountKey);
216217
return new QueueServiceClient(GetQueueEndpoint(accountName), skc, _queueClientOptions);
217-
});
218+
})!; // NULLABLE: only this method inserts QueueClientKey so result cannot be null
218219
}

src/ApiService/ApiService/onefuzzlib/VmssOperations.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private Task<string> GetInstanceIdForVmId(Guid scaleset, Guid vmId)
212212
} else {
213213
return foundInstanceId;
214214
}
215-
});
215+
})!; // NULLABLE: only this method inserts InstanceIdKey so it cannot be null
216216

217217
public async Async.Task<OneFuzzResult<VirtualMachineScaleSetVmResource>> GetInstanceVm(Guid name, Guid vmId) {
218218
_log.Info($"get instance ID for scaleset node: {name:Tag:VmssName}:{vmId:Tag:VmId}");
@@ -402,8 +402,9 @@ public IAsyncEnumerable<VirtualMachineScaleSetVmResource> ListVmss(Guid name)
402402
.GetVirtualMachineScaleSetVms()
403403
.SelectAwait(async vm => vm.HasData ? vm : await vm.GetAsync());
404404

405+
private sealed record AvailableSkusKey(Region region);
405406
public Async.Task<IReadOnlyList<string>> ListAvailableSkus(Region region)
406-
=> _cache.GetOrCreateAsync<IReadOnlyList<string>>($"compute-skus-{region}", async entry => {
407+
=> _cache.GetOrCreateAsync<IReadOnlyList<string>>(new AvailableSkusKey(region), async entry => {
407408
entry = entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(10));
408409

409410
var sub = _creds.GetSubscriptionResource();
@@ -428,7 +429,7 @@ public Async.Task<IReadOnlyList<string>> ListAvailableSkus(Region region)
428429
}
429430

430431
return skuNames;
431-
});
432+
})!; // NULLABLE: only this method inserts AvailableSkusKey so it cannot be null
432433

433434
private async Async.Task<HashSet<string>> ResolveInstanceIds(Guid scalesetId, IEnumerable<Node> nodes) {
434435

src/ApiService/ApiService/onefuzzlib/notifications/Ado.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ private static WorkItemTrackingHttpClient GetAdoClient(Uri baseUrl, string token
105105
return new WorkItemTrackingHttpClient(baseUrl, new VssBasicCredential("PAT", token));
106106
}
107107

108-
private static async Async.Task<Dictionary<string, WorkItemField>> GetValidFields(WorkItemTrackingHttpClient client, string? project) {
109-
return (await client.GetFieldsAsync(project, expand: GetFieldsExpand.ExtensionFields))
108+
private static async Async.Task<Dictionary<string, WorkItemField2>> GetValidFields(WorkItemTrackingHttpClient client, string? project) {
109+
return (await client.GetWorkItemFieldsAsync(project, expand: GetFieldsExpand.ExtensionFields))
110110
.ToDictionary(field => field.ReferenceName.ToLowerInvariant());
111111
}
112112

0 commit comments

Comments
 (0)