Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case. Fix Dot3 in read JWT. #2501

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Microsoft.IdentityModel.JsonWebTokens/JsonWebToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,10 @@ internal void ReadToken(ReadOnlyMemory<char> encodedTokenMemory)
// empty payload for JWE's {encrypted tokens}.
Payload = new JsonClaimSet();

if (Dot3 == encodedTokenSpan.Length) // TODO: Should this be encodedJsonSpan.Length - 1?
throw LogHelper.LogExceptionMessage(new ArgumentException(LogMessages.IDX14121));
pmaytak marked this conversation as resolved.
Show resolved Hide resolved

Dot3 = Dot2 + Dot3 + 1;

if (Dot3 == encodedTokenSpan.Length - 1)
throw LogHelper.LogExceptionMessage(new SecurityTokenMalformedException(LogMessages.IDX14121));

Dot4 = encodedTokenSpan.Slice(Dot3 + 1).IndexOf('.');
if (Dot4 == -1)
throw LogHelper.LogExceptionMessage(new SecurityTokenMalformedException(LogMessages.IDX14121));
Expand Down
7 changes: 7 additions & 0 deletions test/System.IdentityModel.Tokens.Jwt.Tests/JwtTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public static TheoryData<JwtTheoryData> InvalidNumberOfSegmentsData(IList<string
Token = "a"
});
theoryData.Add(new JwtTheoryData
{
CanRead = false,
ExpectedException = ExpectedException.SecurityTokenMalformedTokenException(errorStrings[0]),
TestId = "a.",
Token = "a."
});
theoryData.Add(new JwtTheoryData
{
CanRead = false,
ExpectedException = ExpectedException.SecurityTokenMalformedTokenException(errorStrings[1]),
Expand Down
Loading