Repository navigation
fix(profiles): enforce per-account profile name uniqueness - #342
Conversation
Profile create and rename accepted any name, so one account could hold unlimited profiles all called "Laura" (every client allowed it too). Reject a create or rename whose trimmed, case-insensitive name matches another profile on the same account with 409 name_conflict. Scoping is per account by construction — the check runs against a single user's profile store, so different accounts can still each have a "Laura". Renames exclude the profile being updated, so re-saving a profile under its own name (e.g. avatar-only edits that resubmit the name) still works. Also reject whitespace-only names on create and rename; a name of " " previously passed the blank check. Additive-only per the v1 API rules: new 409 error code on existing endpoints, following the profile_limit_reached pattern. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds trimmed, case-insensitive profile-name validation on create and update, returning HTTP 409 ChangesProfile name conflict enforcement
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f944063fcc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
| } | ||
|
|
||
| if profileNameConflicts(existingProfiles, req.Name, "") { |
There was a problem hiding this comment.
Make profile name uniqueness atomic
When two profile creates (or renames) for the same account arrive concurrently with the same trimmed/case-folded name, both requests can pass this ListProfiles snapshot before either write commits, and then both writes succeed because the SQLite/Postgres profile stores only enforce the profile ID primary key, not normalized-name uniqueness. That leaves duplicate names despite the new name_conflict contract; the conflict check needs to be enforced in the store transaction or with a database constraint/unique index so one of the concurrent requests fails.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed the snapshot check isn't atomic — two concurrent same-name writes on one account can both pass it, since neither store constrains normalized names. Keeping this PR at the API layer (it fixes the user-facing bug and grandfathers existing duplicates safely) and tracking store-level enforcement in both backends as #343, including the typed conflict error and the pre-existing-duplicates migration concern.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/api/handlers/profiles.go`:
- Around line 363-372: Trim the profile name before persisting it so storage
matches the conflict check behavior. In the profile handler code around the
create/update paths (including the logic using profileNameConflicts), normalize
req.Name with whitespace trimming before assigning it to the stored profile
object, and make sure both the create flow and the update flow use the trimmed
value consistently so names like " main " are not saved with extra spaces.
- Around line 363-372: The name uniqueness check in CreateProfile/UpdateProfile
is only a handler pre-check, so concurrent writes can still create duplicate
profile names. Move the invariant into the store/DB layer behind the profiles
persistence path used by CreateProfile and UpdateProfile, enforcing a trimmed
case-insensitive unique name per user with a unique index or equivalent atomic
conflict handling, and keep the handler’s profileNameConflicts check only as a
fast early validation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9cb4ad21-1067-4139-ace1-9c14f2753f36
📒 Files selected for processing (2)
internal/api/handlers/profiles.gointernal/api/handlers/profiles_test.go
The conflict check compared trimmed names but create/rename persisted the raw input, so " Laura " could land with stray whitespace and render inconsistently. Normalize to the trimmed form before storage on both paths. Addresses the CodeRabbit review finding on PR Silo-Server#342. Co-Authored-By: Claude Fable 5 <[email protected]>
Also document the check-then-write race in profileNameConflicts: the userstore backends carry no unique index on name, so concurrent creates can still race past the guard, same as profile_limit_reached. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Pushed 77dc373 addressing the remaining review items:
|
A single account could create unlimited identically-named profiles. Silo-Server/silo-server#342 enforces per-account uniqueness server-side (409 name_conflict); this is the client half: - Shared List<Profile>.hasProfileNamed mirrors the server rule (trimmed, case-insensitive, per account) so create/edit forms on phone and TV fail fast before the network round-trip — and still guard against servers that predate the rule. Edit excludes the profile being renamed, so re-saving under your own name works. - Create and edit VMs on both platforms surface the server's error message (name_conflict, profile_limit_reached) instead of generic "Failed to create/update profile". Co-Authored-By: Claude Fable 5 <[email protected]>
* fix(profiles): enforce per-account profile name uniqueness Profile create and rename accepted any name, so one account could hold unlimited profiles all called "Laura" (every client allowed it too). Reject a create or rename whose trimmed, case-insensitive name matches another profile on the same account with 409 name_conflict. Scoping is per account by construction — the check runs against a single user's profile store, so different accounts can still each have a "Laura". Renames exclude the profile being updated, so re-saving a profile under its own name (e.g. avatar-only edits that resubmit the name) still works. Also reject whitespace-only names on create and rename; a name of " " previously passed the blank check. Additive-only per the v1 API rules: new 409 error code on existing endpoints, following the profile_limit_reached pattern. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(profiles): store the trimmed profile name The conflict check compared trimmed names but create/rename persisted the raw input, so " Laura " could land with stray whitespace and render inconsistently. Normalize to the trimmed form before storage on both paths. Addresses the CodeRabbit review finding on PR #342. Co-Authored-By: Claude Fable 5 <[email protected]> * test(profiles): cover whitespace-only rejection and rename trimming Also document the check-then-write race in profileNameConflicts: the userstore backends carry no unique index on name, so concurrent creates can still race past the guard, same as profile_limit_reached. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: rxwatcher <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Quick <[email protected]>
Problem
Profile create and rename accept any name, so a single account can hold unlimited identically-named profiles ("Laura", "laura", "Laura " — or five literal "Laura"s). Found during the 2026-07-08 Android profile QA pass. No client validates either, so every platform exposes the bug.
Approach
Reject a create or rename whose trimmed, case-insensitive name matches another profile on the same account, with
409 name_conflict("A profile with this name already exists"), following the existingprofile_limit_reachedpattern.storeProvider.ForUser), so different accounts can still each have a "Laura". Cross-account names are never visible to it.name == ""check on create, and renames had no blank check at all; both now reject with 400.Additive-only per the v1 API rules: a new error condition on existing endpoints, no field or status-code changes to success paths.
Tests
TestHandleCreateProfile_RejectsDuplicateName— " main " vs seeded "Main" → 409, nothing createdTestHandleUpdateProfile_RejectsDuplicateNameOnRename— rename "Kids" → "MAIN" → 409, name unchangedTestHandleUpdateProfile_AllowsKeepingOwnNameOnUpdate— self-name resave → 200go test ./internal/api/handlers/passes;go build ./...,go vet, gofmt clean.Risks / follow-up
message.No linked scope issue — small correctness fix out of device QA rather than a capability epic.
AI-use disclosure
Implemented with Claude Code (Claude Fable 5); reviewed and test-verified locally.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
409,name_conflict).400).Tests