Skip to content

Commit

Permalink
Scrub log messages (#2289)
Browse files Browse the repository at this point in the history
Co-authored-by: Keegan Caruso <[email protected]>
  • Loading branch information
2 people authored and brentschmaltz committed Sep 7, 2023
1 parent 32d7da7 commit c73ce83
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/Microsoft.IdentityModel.JsonWebTokens/JsonWebToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ internal void ReadToken(string encodedJson)

// header cannot be empty
if (hChars.IsEmpty)
throw LogHelper.LogExceptionMessage(new ArgumentException(LogHelper.FormatInvariant(LogMessages.IDX14307, encodedJson)));
throw LogHelper.LogExceptionMessage(new ArgumentException(LogMessages.IDX14307));

byte[] headerAsciiBytes = new byte[hChars.Length];
#if NET6_0_OR_GREATER
Expand Down Expand Up @@ -463,7 +463,7 @@ internal void ReadToken(string encodedJson)

ReadOnlyMemory<char> initializationVectorChars = encodedJson.AsMemory(Dot2 + 1, Dot3 - Dot2 - 1);
if (initializationVectorChars.IsEmpty)
throw LogHelper.LogExceptionMessage(new ArgumentException(LogHelper.FormatInvariant(LogMessages.IDX14308, encodedJson)));
throw LogHelper.LogExceptionMessage(new ArgumentException(LogMessages.IDX14308));

try
{
Expand All @@ -476,7 +476,7 @@ internal void ReadToken(string encodedJson)

ReadOnlyMemory<char> authTagChars = encodedJson.AsMemory(Dot4 + 1);
if (authTagChars.IsEmpty)
throw LogHelper.LogExceptionMessage(new ArgumentException(LogHelper.FormatInvariant(LogMessages.IDX14310, encodedJson)));
throw LogHelper.LogExceptionMessage(new ArgumentException(LogMessages.IDX14310));

try
{
Expand All @@ -489,7 +489,7 @@ internal void ReadToken(string encodedJson)

ReadOnlyMemory<char> cipherTextBytes = encodedJson.AsMemory(Dot3 + 1, Dot4 - Dot3 - 1);
if (cipherTextBytes.IsEmpty)
throw LogHelper.LogExceptionMessage(new ArgumentException(LogHelper.FormatInvariant(LogMessages.IDX14306, encodedJson)));
throw LogHelper.LogExceptionMessage(new ArgumentException(LogMessages.IDX14306));

try
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.IdentityModel.Tokens.Jwt/JwtSecurityToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private void DecodeJws(string payload)
}
catch (Exception ex)
{
throw LogHelper.LogExceptionMessage(new ArgumentException(LogHelper.FormatInvariant(LogMessages.IDX12723, payload, RawData), ex));
throw LogHelper.LogExceptionMessage(new ArgumentException(LogHelper.FormatInvariant(LogMessages.IDX12723, payload), ex));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ private JwtSecurityToken CreateJwtSecurityTokenPrivate(
}

if (LogHelper.IsEnabled(EventLogLevel.Informational))
LogHelper.LogInformation(LogMessages.IDX12722, rawHeader, rawPayload, rawSignature);
LogHelper.LogInformation(LogMessages.IDX12722, rawHeader, rawPayload);

if (encryptingCredentials != null)
{
Expand Down Expand Up @@ -856,7 +856,7 @@ public override ClaimsPrincipal ValidateToken(string token, TokenValidationParam
int tokenPartCount = JwtTokenUtilities.CountJwtTokenPart(token, JwtConstants.MaxJwtSegmentCount + 1);

if (tokenPartCount != JwtConstants.JwsSegmentCount && tokenPartCount != JwtConstants.JweSegmentCount)
throw LogHelper.LogExceptionMessage(new SecurityTokenMalformedException(LogHelper.FormatInvariant(LogMessages.IDX12741, token)));
throw LogHelper.LogExceptionMessage(new SecurityTokenMalformedException(LogMessages.IDX12741));

if (tokenPartCount == JwtConstants.JweSegmentCount)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ private string CreateTokenPrivate(
catch(Exception ex)
{
if (LogHelper.IsEnabled(EventLogLevel.Error))
LogHelper.LogExceptionMessage(new SecurityTokenException(LogHelper.FormatInvariant(LogMessages.IDX14307, ex, payload)));
LogHelper.LogExceptionMessage(new SecurityTokenException(LogMessages.IDX14307, ex));
}

payload = jsonPayload != null ? jsonPayload.ToString(Formatting.None) : payload;
Expand Down Expand Up @@ -1390,7 +1390,7 @@ public override async Task<TokenValidationResult> ValidateTokenAsync(SecurityTok

var jwt = token as JsonWebToken;
if (jwt == null)
return new TokenValidationResult { Exception = LogHelper.LogExceptionMessage(new SecurityTokenMalformedException(LogHelper.FormatInvariant(LogMessages.IDX14100, token))), IsValid = false };
return new TokenValidationResult { Exception = LogHelper.LogExceptionMessage(new SecurityTokenMalformedException(LogMessages.IDX14100)), IsValid = false };

try
{
Expand Down Expand Up @@ -1438,7 +1438,7 @@ private static TokenValidationResult ReadToken(string token, TokenValidationPara
{
return new TokenValidationResult
{
Exception = LogHelper.LogExceptionMessage(new SecurityTokenMalformedException(LogHelper.FormatInvariant(LogMessages.IDX14100, LogHelper.MarkAsSecurityArtifact(token, JwtTokenUtilities.SafeLogJwtToken), ex))),
Exception = LogHelper.LogExceptionMessage(new SecurityTokenMalformedException(LogMessages.IDX14100, ex)),
IsValid = false
};
}
Expand Down

0 comments on commit c73ce83

Please sign in to comment.