Skip to content

Commit ffec695

Browse files
vidai-msftmsJinLei
andauthored
Integrate security library with secrets detection (#25935)
* Integrate security library with secrets detection * Update ChangeLog.md * Correct typo * Update Authentication.csproj --------- Co-authored-by: Jin Lei <[email protected]>
1 parent a86b8fc commit ffec695

File tree

3 files changed

+8
-56
lines changed

3 files changed

+8
-56
lines changed

src/Accounts/Accounts/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Updated `Connect-AzAccount` to fix a display issue in PowerShell ISE [#24556].
2727
* Updated the reference of Azure PowerShell Common to 1.3.100-preview.
2828
* Used Azure.Identity and Azure.Core directly for client assertion [#22628].
29+
* Integrated new detection library to expand the scope of secrets.
2930

3031
## Version 3.0.3
3132
* Reduced the frequency of displaying sign-in announcement messages.

src/Accounts/Authentication/Authentication.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<PackageReference Include="Azure.Identity.Broker" Version="1.1.0" />
1717
<PackageReference Include="Microsoft.Identity.Client" Version="4.61.3" />
1818
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.61.3" />
19-
<PackageReference Include="Microsoft.Identity.Client.Broker" Version="4.61.3"/>
19+
<PackageReference Include="Microsoft.Identity.Client.Broker" Version="4.61.3" />
20+
<PackageReference Include="Microsoft.Security.Utilities.Core" Version="1.8.0" />
2021
</ItemGroup>
2122

2223
<ItemGroup>

src/Accounts/Authentication/Sanitizer/Services/DefaultSanitizerService.cs

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.Security.Utilities;
1516
using System.Collections.Generic;
16-
using System.Text.RegularExpressions;
17+
using System.Linq;
1718

1819
namespace Microsoft.Azure.Commands.Common.Authentication.Sanitizer.Services
1920
{
@@ -44,67 +45,16 @@ internal class DefaultSanitizerService : ISanitizerService
4445
{ "Microsoft.Azure.Storage.File.CloudFileDirectory", new[] { "Parent" } },
4546
};
4647

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);
9449

9550
public bool TrySanitizeData(string data, out string sanitizedData)
9651
{
9752
sanitizedData = string.Empty;
9853

9954
if (!string.IsNullOrWhiteSpace(data))
10055
{
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();
10858
}
10959

11060
return false;

0 commit comments

Comments
 (0)