Skip to content

Commit 629f31c

Browse files
authored
fix: Remove AutoMapper dependency to remediate CVE-2026-32933 (#1457)
* fix: remove AutoMapper dependency to remediate CVE-2026-32933 Replace AutoMapper 10.1.1 (and AutoMapper.Extensions.Microsoft.DependencyInjection 8.1.1) with explicit manual property-by-property mapping in ConfigurationMapper.cs. Changes: - Add ConfigurationMapper with explicit MapFrom() for each Args type and ConfigFile - Add type-safe MergeSetting<T>() for config merge with conflict detection - Add explicit ToConfiguration() for InputConfiguration -> Configuration copy - Refactor ConfigPostProcessor to remove IMappingAction interface dependency - Update ConfigurationBuilder to use ConfigurationMapper directly - Update DI registration from AddAutoMapper() to AddTransient<ConfigPostProcessor>() - Remove AutoMapper from all 4 csproj files and Directory.Packages.props - Delete ConfigurationProfile.cs and 9 value converter files No reflection used - every mapped property is listed explicitly for auditability. All 829 unit tests pass. E2E CLI tests verified (generate, validate, redact, aggregate, config merge). * chore: remove .features from tracked files
1 parent 6e600cf commit 629f31c

24 files changed

Lines changed: 449 additions & 574 deletions

Directory.Packages.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
<ComponentDetectionPackageVersion>6.3.0</ComponentDetectionPackageVersion>
1111
</PropertyGroup>
1212
<ItemGroup>
13-
<PackageVersion Include="AutoMapper" Version="10.1.1" />
14-
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
1513
<PackageVersion Include="Microsoft.Build" Version="17.11.48" />
1614
<PackageVersion Include="Microsoft.Build.Framework" Version="17.11.48" />
1715
<PackageVersion Include="Microsoft.Build.Locator" Version="1.9.1" />

src/Microsoft.Sbom.Api/Config/ConfigPostProcessor.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.ComponentModel;
7-
using AutoMapper;
87
using Microsoft.Sbom.Api.Output.Telemetry;
98
using Microsoft.Sbom.Common;
109
using Microsoft.Sbom.Common.Config;
@@ -17,7 +16,7 @@ namespace Microsoft.Sbom.Api.Config;
1716
/// <summary>
1817
/// Runs finalizing operations on the configuration once it has been successfully parsed.
1918
/// </summary>
20-
public class ConfigPostProcessor : IMappingAction<IConfiguration, IConfiguration>
19+
public class ConfigPostProcessor
2120
{
2221
private readonly IEnumerable<ConfigValidator> configValidators;
2322
private readonly ConfigSanitizer configSanitizer;
@@ -30,7 +29,7 @@ public ConfigPostProcessor(IEnumerable<ConfigValidator> configValidators, Config
3029
this.fileSystemUtils = fileSystemUtils ?? throw new ArgumentNullException(nameof(fileSystemUtils));
3130
}
3231

33-
public void Process(IConfiguration source, IConfiguration destination, ResolutionContext context)
32+
public void Process(IConfiguration source, IConfiguration destination)
3433
{
3534
// Replace backslashes in directory paths with the OS-sepcific directory separator character.
3635
PathUtils.ConvertToOSSpecificPathSeparators(destination);

src/Microsoft.Sbom.Api/Config/ConfigurationBuilder.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Threading.Tasks;
5-
using AutoMapper;
65
using Microsoft.Sbom.Api.Config.Args;
76
using Microsoft.Sbom.Common.Config;
87
using PowerArgs;
@@ -13,12 +12,12 @@ namespace Microsoft.Sbom.Api.Config;
1312
/// <remarks>Throws an error if the same parameters are defined in both the config file and command line.</remarks>
1413
public class ConfigurationBuilder<T> : IConfigurationBuilder<T>
1514
{
16-
private readonly IMapper mapper;
15+
private readonly ConfigPostProcessor configPostProcessor;
1716
private readonly ConfigFileParser configFileParser;
1817

19-
public ConfigurationBuilder(IMapper mapper, ConfigFileParser configFileParser)
18+
public ConfigurationBuilder(ConfigPostProcessor configPostProcessor, ConfigFileParser configFileParser)
2019
{
21-
this.mapper = mapper;
20+
this.configPostProcessor = configPostProcessor;
2221
this.configFileParser = configFileParser;
2322
}
2423

@@ -31,23 +30,23 @@ public async Task<InputConfiguration> GetConfiguration(T args)
3130
{
3231
case ValidationArgs validationArgs:
3332
validationArgs.ManifestToolAction = ManifestToolActions.Validate;
34-
commandLineArgs = mapper.Map<InputConfiguration>(validationArgs);
33+
commandLineArgs = ConfigurationMapper.MapFrom(validationArgs);
3534
break;
3635
case GenerationArgs generationArgs:
3736
generationArgs.ManifestToolAction = ManifestToolActions.Generate;
38-
commandLineArgs = mapper.Map<InputConfiguration>(generationArgs);
37+
commandLineArgs = ConfigurationMapper.MapFrom(generationArgs);
3938
break;
4039
case RedactArgs redactArgs:
4140
redactArgs.ManifestToolAction = ManifestToolActions.Redact;
42-
commandLineArgs = mapper.Map<InputConfiguration>(redactArgs);
41+
commandLineArgs = ConfigurationMapper.MapFrom(redactArgs);
4342
break;
4443
case FormatValidationArgs formatValidationArgs:
4544
formatValidationArgs.ManifestToolAction = ManifestToolActions.ValidateFormat;
46-
commandLineArgs = mapper.Map<InputConfiguration>(formatValidationArgs);
45+
commandLineArgs = ConfigurationMapper.MapFrom(formatValidationArgs);
4746
break;
4847
case AggregationArgs aggregationArgs:
4948
aggregationArgs.ManifestToolAction = ManifestToolActions.Aggregate;
50-
commandLineArgs = mapper.Map<InputConfiguration>(aggregationArgs);
49+
commandLineArgs = ConfigurationMapper.MapFrom(aggregationArgs);
5150
break;
5251
default:
5352
throw new ValidationArgException($"Unsupported configuration type found {typeof(T)}");
@@ -59,10 +58,10 @@ await configFileParser.ParseFromJsonFile(commandLineArgs.ConfigFilePath.Value) :
5958
new ConfigFile();
6059

6160
// Convert config file arguments to configuration.
62-
var configFileArgs = mapper.Map<ConfigFile, InputConfiguration>(configFromFile);
61+
var configFileArgs = ConfigurationMapper.MapFrom(configFromFile);
6362

6463
// Combine both configs, include defaults.
65-
return mapper.Map(commandLineArgs, configFileArgs);
64+
return ConfigurationMapper.Merge(commandLineArgs, configFileArgs, configPostProcessor);
6665
}
6766
}
6867

0 commit comments

Comments
 (0)