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

Use user-provided values as Utf8 #2492

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
Draft

Use user-provided values as Utf8 #2492

wants to merge 12 commits into from

Conversation

pmaytak
Copy link
Contributor

@pmaytak pmaytak commented Feb 21, 2024

Fixes #2495

  • Adds a ReadOnlyMemory<byte> property for UTF8 issuer in TokenValidationParameters, JsonWebToken, BaseConfiguration.
    • Uses these properties for comparison validation in Validators.ValidateIssuer
  • When creating a JsonWebToken, assign the current reader.ValueSpan to the UTF8 issuer property.

return _iss;
}
}
public override string Issuer => Encoding.UTF8.GetString(IssuerUtf8.ToArray());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Encoding.UTF8.GetString with ReadOnlySpan overload is only available on .NET Core 2.1+ (not Net Fx).
    • I assume ToArray allocates a new array.
  • Since IssuerUtf8 can change, we can't "cache" the string representation, so have to convert it to string each time.

SecurityToken securityToken,
TokenValidationParameters validationParameters,
BaseConfiguration configuration)
{
if (validationParameters == null)
throw LogHelper.LogArgumentNullException(nameof(validationParameters));

string issuer = Encoding.UTF8.GetString(issuerUtf8.ToArray());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll still need to convert the Memory to string in places like here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Convert user-provided values to UTF8 and use these to compare with UTF8 values from JWT
4 participants