From 2b5b6573c9631393ba2566b091dbaeace6e462b1 Mon Sep 17 00:00:00 2001 From: Greg Villicana <58237075+grvillic@users.noreply.github.com> Date: Thu, 6 Jun 2024 21:02:09 -0700 Subject: [PATCH] Sanitize another Docker telemetry event (#1164) --- .../DockerService.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.ComponentDetection.Common/DockerService.cs b/src/Microsoft.ComponentDetection.Common/DockerService.cs index ee49394e4..3484b81fe 100644 --- a/src/Microsoft.ComponentDetection.Common/DockerService.cs +++ b/src/Microsoft.ComponentDetection.Common/DockerService.cs @@ -71,7 +71,7 @@ public async Task ImageExistsLocallyAsync(string image, CancellationToken }; try { - var imageInspectResponse = await Client.Images.InspectImageAsync(image, cancellationToken); + var imageInspectResponse = await this.InspectImageAndSanitizeVarsAsync(image, cancellationToken); record.ImageInspectResponse = JsonSerializer.Serialize(imageInspectResponse); return true; } @@ -82,6 +82,13 @@ public async Task ImageExistsLocallyAsync(string image, CancellationToken } } + private async Task InspectImageAndSanitizeVarsAsync(string image, CancellationToken cancellationToken = default) + { + var imageInspectResponse = await Client.Images.InspectImageAsync(image, cancellationToken); + this.SanitizeEnvironmentVariables(imageInspectResponse); + return imageInspectResponse; + } + public async Task TryPullImageAsync(string image, CancellationToken cancellationToken = default) { using var record = new DockerServiceTryPullImageTelemetryRecord @@ -135,10 +142,7 @@ public async Task InspectImageAsync(string image, Cancellation }; try { - var imageInspectResponse = await Client.Images.InspectImageAsync(image, cancellationToken); - - this.SanitizeEnvironmentVariables(imageInspectResponse); - + var imageInspectResponse = await this.InspectImageAndSanitizeVarsAsync(image, cancellationToken); record.ImageInspectResponse = JsonSerializer.Serialize(imageInspectResponse); var baseImageRef = string.Empty;