Restrict valid API user client IDs to 100 characters. (#18688)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Cms.Core.Security.OperationStatus;
|
||||
|
||||
@@ -20,7 +20,7 @@ public abstract class ClientCredentialsUserControllerBase : UserControllerBase
|
||||
.Build()),
|
||||
BackOfficeUserClientCredentialsOperationStatus.InvalidClientId => BadRequest(problemDetailsBuilder
|
||||
.WithTitle("Invalid client ID")
|
||||
.WithDetail("The specified client ID is invalid. A valid client ID can only contain [a-z], [A-Z], [0-9], and [-._~]. Furthermore, including the prefix it cannot be longer than 255 characters.")
|
||||
.WithDetail("The specified client ID is invalid. A valid client ID can only contain [a-z], [A-Z], [0-9], and [-._~]. Furthermore, including the prefix it cannot be longer than 100 characters.")
|
||||
.Build()),
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, problemDetailsBuilder
|
||||
.WithTitle("Unknown client credentials operation status.")
|
||||
|
||||
@@ -2680,7 +2680,7 @@ internal partial class UserService : RepositoryService, IUserService
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^[\w\d\-\._~]{1,255}$")]
|
||||
[GeneratedRegex(@"^[\w\d\-\._~]{1,100}$")]
|
||||
private static partial Regex ValidClientId();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1004,7 +1004,6 @@ public class UserServiceTests : UmbracoIntegrationTest
|
||||
[TestCase("@", UserClientCredentialsOperationStatus.InvalidClientId)]
|
||||
[TestCase("[", UserClientCredentialsOperationStatus.InvalidClientId)]
|
||||
[TestCase("]", UserClientCredentialsOperationStatus.InvalidClientId)]
|
||||
[TestCase("More_Than_255_characters_012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", UserClientCredentialsOperationStatus.InvalidClientId)]
|
||||
public async Task Can_Use_Only_Unreserved_Characters_For_ClientId(string clientId, UserClientCredentialsOperationStatus expectedResult)
|
||||
{
|
||||
// Arrange
|
||||
@@ -1017,6 +1016,20 @@ public class UserServiceTests : UmbracoIntegrationTest
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
|
||||
[TestCase("Less_Than_100_characters_0123456789012345678901234567890123456789012345678901234567890123456789", UserClientCredentialsOperationStatus.Success)]
|
||||
[TestCase("More_Than_100_characters_01234567890123456789012345678901234567890123456789012345678901234567890123456789", UserClientCredentialsOperationStatus.InvalidClientId)]
|
||||
public async Task Cannot_Create_Too_Long_ClientId(string clientId, UserClientCredentialsOperationStatus expectedResult)
|
||||
{
|
||||
// Arrange
|
||||
var user = await CreateTestUser(UserKind.Api);
|
||||
|
||||
// Act
|
||||
var result = await UserService.AddClientIdAsync(user.Key, clientId);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
|
||||
private Content[] BuildContentItems(int numberToCreate)
|
||||
{
|
||||
var template = TemplateBuilder.CreateTextPageTemplate();
|
||||
|
||||
Reference in New Issue
Block a user