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

Member Username cannot be same as a member's id #17097

Open
AaronMorf opened this issue Sep 18, 2024 · 2 comments
Open

Member Username cannot be same as a member's id #17097

AaronMorf opened this issue Sep 18, 2024 · 2 comments
Labels
affected/v13 area/backend state/reproduced state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/bug

Comments

@AaronMorf
Copy link

AaronMorf commented Sep 18, 2024

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.4.0

Bug summary

The member username cannot be the same as the member id if the member is in the cache.

If the username is the id of another member and that member is cached, MemberService.GetByUsername will return the wrong member.

When trying to get the member using MemberService.GetByUsername, do not check the id, only the username.

Specifics

In the MemberRepository.cs where the username cache is created, it writes the same CacheKey as for the normal entity cache.
I guess this should be fixed.

Username Cache:

public IMember? GetByUsername(string? username) =>
_memberByUsernameCachePolicy.Get(username, PerformGetByUsername, PerformGetAllByUsername);

_memberByUsernameCachePolicy =
new DefaultRepositoryCachePolicy<IMember, string>(GlobalIsolatedCache, ScopeAccessor, DefaultOptions);

Entity Cache:

protected virtual IRepositoryCachePolicy<TEntity, TId> CreateCachePolicy()
=> new DefaultRepositoryCachePolicy<TEntity, TId>(GlobalIsolatedCache, ScopeAccessor, DefaultOptions);

Cache Key:

protected string GetEntityCacheKey(int id) => EntityTypeCacheKey + id;
protected string GetEntityCacheKey(TId? id)
{
if (EqualityComparer<TId>.Default.Equals(id, default))
{
return string.Empty;
}
if (typeof(TId).IsValueType)
{
return EntityTypeCacheKey + id;
}
return EntityTypeCacheKey + id?.ToString()?.ToUpperInvariant();
}

protected string EntityTypeCacheKey { get; } = $"uRepo_{typeof(TEntity).Name}_";

Steps to reproduce

Create a member and give them a random number (12345) as their username:
image
Check the new member's id and copy it (1499):
image
Now create another member with the copied id (1499) as their username. Click save and you will see that the username is already taken:
image
Once the cache is cleared (after 5 minutes or a reboot), a member can be created with the username of the first member created ID (1499) without the validation error:
image
When the cache is cleared (after 5 minutes or a reboot), save the first member (Test Member 12345) and try to get the new member by username (1499).
You will get the first member (Test Member 12345) instead of the correct member (Test Member 1499):
@using Umbraco.Cms.Core.Services @inject IMemberService memberService @{ var member = memberService.GetByUsername("1499"); if (member != null) { <p> Member: @member.Name </p> } }

OUTPUT: Member: Test Member 12345

EXPECTED OUTPUT: Member: Test Member 1499

Expected result / actual result

When reproducing you should see the error and the wrong cache.
The expected result would be to allow any username for a member, even if it is another member's id and to have the correct member returned.


This item has been added to our backlog AB#45490

Copy link

Hi there @AaronMorf!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@NguyenThuyLan
Copy link
Contributor

Thank @AaronMorf for reporting this issue. I confirm I was able to reproduce this on v13.6.0.

@bergmania bergmania added the state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks label Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected/v13 area/backend state/reproduced state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks type/bug
Projects
None yet
Development

No branches or pull requests

3 participants