Skip to content

Commit 234e4a3

Browse files
committed
fix(store): Profile updating is handled in an insecure and potentially broken way
1 parent 4646de4 commit 234e4a3

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

autogpt_platform/backend/backend/server/v2/store/db.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ async def update_or_create_profile(
620620
"""
621621
Update the store profile for a user. Creates a new profile if one doesn't exist.
622622
Only allows updating if the user_id matches the owning user.
623+
If a field is None, it will not overwrite the existing value in the case of an update.
623624
624625
Args:
625626
user_id: ID of the authenticated user
@@ -630,8 +631,9 @@ async def update_or_create_profile(
630631
631632
Raises:
632633
HTTPException: If user is not authorized to update this profile
634+
DatabaseError: If profile cannot be updated due to database issues
633635
"""
634-
logger.debug(f"Updating profile for user {user_id}")
636+
logger.info(f"Updating profile for user {user_id} data: {profile}")
635637

636638
try:
637639
# Check if profile exists for user
@@ -641,16 +643,19 @@ async def update_or_create_profile(
641643

642644
# If no profile exists, create a new one
643645
if not existing_profile:
644-
logger.debug(f"Creating new profile for user {user_id}")
646+
logger.debug(
647+
f"No existing profile found. Creating new profile for user {user_id}"
648+
)
645649
# Create new profile since one doesn't exist
646650
new_profile = await prisma.models.Profile.prisma().create(
647651
data={
648652
"userId": user_id,
649653
"name": profile.name,
650654
"username": profile.username,
651655
"description": profile.description,
652-
"links": profile.links,
656+
"links": profile.links or [],
653657
"avatarUrl": profile.avatar_url,
658+
"isFeatured": False,
654659
}
655660
)
656661

@@ -666,16 +671,23 @@ async def update_or_create_profile(
666671
)
667672
else:
668673
logger.debug(f"Updating existing profile for user {user_id}")
674+
# Update only provided fields for the existing profile
675+
update_data = {}
676+
if profile.name is not None:
677+
update_data["name"] = profile.name
678+
if profile.username is not None:
679+
update_data["username"] = profile.username
680+
if profile.description is not None:
681+
update_data["description"] = profile.description
682+
if profile.links is not None:
683+
update_data["links"] = profile.links
684+
if profile.avatar_url is not None:
685+
update_data["avatarUrl"] = profile.avatar_url
686+
669687
# Update the existing profile
670688
updated_profile = await prisma.models.Profile.prisma().update(
671689
where={"id": existing_profile.id},
672-
data=prisma.types.ProfileUpdateInput(
673-
name=profile.name,
674-
username=profile.username,
675-
description=profile.description,
676-
links=profile.links,
677-
avatarUrl=profile.avatar_url,
678-
),
690+
data=prisma.types.ProfileUpdateInput(**update_data),
679691
)
680692
if updated_profile is None:
681693
logger.error(f"Failed to update profile for user {user_id}")

autogpt_platform/frontend/src/components/agptui/ProfileInfoForm.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const ProfileInfoForm = ({ profile }: { profile: CreatorDetails }) => {
2626
name: profileData.name,
2727
username: profileData.username,
2828
description: profileData.description,
29-
links: profileData.links,
29+
links: profileData.links.filter((link) => link), // Filter out empty links
3030
avatar_url: profileData.avatar_url,
3131
};
3232

@@ -225,11 +225,11 @@ export const ProfileInfoForm = ({ profile }: { profile: CreatorDetails }) => {
225225
defaultValue={link || ""}
226226
className="font-circular w-full border-none bg-transparent text-base font-normal text-neutral-900 placeholder:text-neutral-400 focus:outline-none dark:text-white dark:placeholder:text-neutral-500"
227227
onChange={(e) => {
228+
const newLinks = [...profileData.links];
229+
newLinks[linkNum - 1] = e.target.value;
228230
const newProfileData = {
229231
...profileData,
230-
links: profileData.links.map((link, index) =>
231-
index === linkNum - 1 ? e.target.value : link,
232-
),
232+
links: newLinks,
233233
};
234234
setProfileData(newProfileData);
235235
}}

0 commit comments

Comments
 (0)