-
Notifications
You must be signed in to change notification settings - Fork 45
make max token length configurable #354
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,15 +13,24 @@ namespace Duende.AccessTokenManagement; | |||||
| [JsonConverter(typeof(StringValueJsonConverter<AccessToken>))] | ||||||
| public readonly record struct AccessToken : IStronglyTypedValue<AccessToken> | ||||||
| { | ||||||
| private const int Kilobyte = 1024; | ||||||
|
|
||||||
| public override string ToString() => Value; | ||||||
|
|
||||||
| // Officially, there's no max length for JWTs, but 32k is a good limit | ||||||
| public const int MaxLength = 32 * 1024; // 32k | ||||||
| // Officially, there's no max length for JWTs, but keep construction bounded. | ||||||
| // Runtime read boundaries apply the configurable limit. | ||||||
| public const int MaxLength = 100 * Kilobyte; | ||||||
|
|
||||||
| private static readonly ValidationRule<string>[] Validators = [ | ||||||
| ValidationRules.MaxLength(MaxLength) | ||||||
| ]; | ||||||
|
|
||||||
| private static ValidationRule<string>[] BuildValidators(int maxLength) | ||||||
| { | ||||||
| ArgumentOutOfRangeException.ThrowIfNegativeOrZero(maxLength); | ||||||
| return [ValidationRules.MaxLength(maxLength)]; | ||||||
|
||||||
| return [ValidationRules.MaxLength(maxLength)]; | |
| return [ValidationRules.MaxLength(Math.Min(maxLength, MaxLength))]; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,13 @@ namespace Duende.AccessTokenManagement; | |||||
| /// </summary> | ||||||
| public sealed class ClientCredentialsTokenManagementOptions | ||||||
| { | ||||||
| private const int Kilobyte = 1024; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Maximum allowed token length when reading tokens from external systems or caches. | ||||||
|
||||||
| /// Maximum allowed token length when reading tokens from external systems or caches. | |
| /// Maximum allowed token length when parsing token responses. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,14 +10,22 @@ namespace Duende.AccessTokenManagement; | |||||||
| [JsonConverter(typeof(StringValueJsonConverter<RefreshToken>))] | ||||||||
| public readonly record struct RefreshToken : IStronglyTypedValue<RefreshToken> | ||||||||
| { | ||||||||
| public const int MaxLength = 4 * 1024; | ||||||||
| private const int Kilobyte = 1024; | ||||||||
|
|
||||||||
| public const int MaxLength = 100 * Kilobyte; | ||||||||
| public override string ToString() => Value; | ||||||||
|
|
||||||||
| private static readonly ValidationRule<string>[] Validators = [ | ||||||||
| // Officially, there's no max length refresh tokens, but 4k is a good limit | ||||||||
| // Keep direct construction bounded. Runtime read boundaries apply the configurable limit. | ||||||||
| ValidationRules.MaxLength(MaxLength) | ||||||||
| ]; | ||||||||
|
|
||||||||
| private static ValidationRule<string>[] BuildValidators(int maxLength) | ||||||||
| { | ||||||||
| ArgumentOutOfRangeException.ThrowIfNegativeOrZero(maxLength); | ||||||||
| return [ValidationRules.MaxLength(maxLength)]; | ||||||||
|
||||||||
| return [ValidationRules.MaxLength(maxLength)]; | |
| var effectiveMaxLength = Math.Min(maxLength, MaxLength); | |
| return [ValidationRules.MaxLength(effectiveMaxLength)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new default
TokenMaxLengthof 4 KB is a breaking tightening compared to the previous behavior (access tokens were previously allowed up to 32 KB viaAccessToken.MaxLength). This will cause existing deployments with larger access tokens to start failing unless they opt in. If the intent is to preserve the prior default behavior while making it configurable, consider defaulting this to 32 KB (and documenting how to raise it for unusually large refresh tokens).