|
12 | 12 | // limitations under the License.
|
13 | 13 | // ----------------------------------------------------------------------------------
|
14 | 14 |
|
| 15 | +using Microsoft.Security.Utilities; |
15 | 16 | using System.Collections.Generic;
|
16 |
| -using System.Text.RegularExpressions; |
| 17 | +using System.Linq; |
17 | 18 |
|
18 | 19 | namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Services
|
19 | 20 | {
|
@@ -44,67 +45,16 @@ internal class DefaultSanitizerService : ISanitizerService
|
44 | 45 | { "Microsoft.Azure.Storage.File.CloudFileDirectory", new[] { "Parent" } },
|
45 | 46 | };
|
46 | 47 |
|
47 |
| - private static readonly IEnumerable<string> SensitiveDataPatterns = new List<string>() |
48 |
| - { |
49 |
| - // AAD client app, most recent two versions. |
50 |
| - @"\b" // pre-match |
51 |
| - + @"[0-9A-Za-z-_~.]{3}7Q~[0-9A-Za-z-_~.]{31}\b|\b[0-9A-Za-z-_~.]{3}8Q~[0-9A-Za-z-_~.]{34}" // match |
52 |
| - + @"\b", // post-match |
53 |
| - |
54 |
| - // Prominent Azure provider 512-bit symmetric keys. |
55 |
| - @"\b" // pre-match |
56 |
| - + @"[0-9A-Za-z+/]{76}(APIM|ACDb|\+(ABa|AMC|ASt))[0-9A-Za-z+/]{5}[AQgw]==" // match |
57 |
| - + @"", // post-match |
58 |
| - |
59 |
| - // Prominent Azure provider 256-bit symmetric keys. |
60 |
| - @"\b" // pre-match |
61 |
| - + @"[0-9A-Za-z+/]{33}(AIoT|\+(ASb|AEh|ARm))[A-P][0-9A-Za-z+/]{5}=" // match |
62 |
| - + @"", // post-match |
63 |
| - |
64 |
| - // Azure Function key. |
65 |
| - @"\b" // pre-match |
66 |
| - + @"[0-9A-Za-z_\-]{44}AzFu[0-9A-Za-z\-_]{5}[AQgw]==" // match |
67 |
| - + @"", // post-match |
68 |
| - |
69 |
| - // Azure Search keys. |
70 |
| - @"\b" // pre-match |
71 |
| - + @"[0-9A-Za-z]{42}AzSe[A-D][0-9A-Za-z]{5}" // match |
72 |
| - + @"\b", // post-match |
73 |
| - |
74 |
| - // Azure Container Registry keys. |
75 |
| - @"\b" // pre-match |
76 |
| - + @"[0-9A-Za-z+/]{42}\+ACR[A-D][0-9A-Za-z+/]{5}" // match |
77 |
| - + @"\b", // post-match |
78 |
| - |
79 |
| - // Azure Cache for Redis keys. |
80 |
| - @"\b" // pre-match |
81 |
| - + @"[0-9A-Za-z]{33}AzCa[A-P][0-9A-Za-z]{5}=" // match |
82 |
| - + @"", // post-match |
83 |
| - |
84 |
| - // NuGet API keys. |
85 |
| - @"\b" // pre-match |
86 |
| - + @"oy2[a-p][0-9a-z]{15}[aq][0-9a-z]{11}[eu][bdfhjlnprtvxz357][a-p][0-9a-z]{11}[aeimquy4]" // match |
87 |
| - + @"\b", // post-match |
88 |
| - |
89 |
| - // NPM author keys. |
90 |
| - @"\b" // pre-match |
91 |
| - + @"npm_[0-9A-Za-z]{36}" // match |
92 |
| - + @"\b", // post-match |
93 |
| - }; |
| 48 | + private readonly SecretMasker _secretMasker = new SecretMasker(WellKnownRegexPatterns.HighConfidenceMicrosoftSecurityModels, generateCorrelatingIds: true); |
94 | 49 |
|
95 | 50 | public bool TrySanitizeData(string data, out string sanitizedData)
|
96 | 51 | {
|
97 | 52 | sanitizedData = string.Empty;
|
98 | 53 |
|
99 | 54 | if (!string.IsNullOrWhiteSpace(data))
|
100 | 55 | {
|
101 |
| - foreach (var pattern in SensitiveDataPatterns) |
102 |
| - { |
103 |
| - if (Regex.IsMatch(data, pattern)) |
104 |
| - { |
105 |
| - return true; |
106 |
| - } |
107 |
| - } |
| 56 | + var detections = _secretMasker.DetectSecrets(data); |
| 57 | + return detections.Any(); |
108 | 58 | }
|
109 | 59 |
|
110 | 60 | return false;
|
|
0 commit comments