Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Refresh.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Refresh.Common.Extensions;

public static class StringExtensions
{
public static bool IsBlankHash(this string? hash)
{
return string.IsNullOrWhiteSpace(hash) || hash == "0";
}
}
2 changes: 1 addition & 1 deletion Refresh.Database/GameDatabaseContext.Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class GameDatabaseContext // Assets

public GameAsset? GetAssetFromHash(string hash)
{
if (hash == "0" || hash.StartsWith('g')) return null;
if (hash.IsBlankHash() || hash.StartsWith('g')) return null;

return this.GameAssetsIncluded
.FirstOrDefault(a => a.AssetHash == hash);
Expand Down
45 changes: 37 additions & 8 deletions Refresh.Interfaces.APIv3/Endpoints/UserApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,43 @@ public ApiResponse<ApiExtendedGameUserResponse> UpdateUser(RequestContext contex
GameUser user, ApiUpdateUserRequest body, IDataStore dataStore, DataContext dataContext, IntegrationConfig integrationConfig,
SmtpService smtpService)
{
if (body.IconHash != null && database.GetAssetFromHash(body.IconHash) == null)
return ApiNotFoundError.Instance;

if (body.VitaIconHash != null && database.GetAssetFromHash(body.VitaIconHash) == null)
return ApiNotFoundError.Instance;

if (body.BetaIconHash != null && database.GetAssetFromHash(body.BetaIconHash) == null)
return ApiNotFoundError.Instance;
// If any icon is requested to be reset, force its hash to be a specific value,
// to not allow uncontrolled values which would still count as blank/empty hash (e.g. unlimited whitespaces)
if (body.IconHash != null)
{
if (body.IconHash.IsBlankHash())
{
body.IconHash = "0";
}
else if (database.GetAssetFromHash(body.IconHash) == null)
{
return ApiNotFoundError.Instance;
}
}

if (body.VitaIconHash != null)
{
if (body.VitaIconHash.IsBlankHash())
{
body.VitaIconHash = "0";
}
else if (database.GetAssetFromHash(body.VitaIconHash) == null)
{
return ApiNotFoundError.Instance;
}
}

if (body.BetaIconHash != null)
{
if (body.BetaIconHash.IsBlankHash())
{
body.BetaIconHash = "0";
}
else if (database.GetAssetFromHash(body.BetaIconHash) == null)
{
return ApiNotFoundError.Instance;
}
}

if (body.EmailAddress != null && !smtpService.CheckEmailDomainValidity(body.EmailAddress))
return ApiValidationError.EmailDoesNotActuallyExistError;
Expand Down
15 changes: 9 additions & 6 deletions Refresh.Interfaces.Game/Endpoints/UserEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ public SerializedFriendsList GetFriends(RequestContext context, GameDatabaseCont
return null;
}
}
else
else if (data.IconHash.IsBlankHash())
{
// Force hash to be a specific value if the icon is supposed to be reset/default to a PSN avatar,
// to not allow uncontrolled values which would still count as blank/empty hash (e.g. unlimited whitespaces)
data.IconHash = "0";
}
else if (!dataContext.DataStore.ExistsInStore(data.IconHash))
{
//If the asset does not exist on the server, block the request
if (!dataContext.DataStore.ExistsInStore(data.IconHash))
{
dataContext.Database.AddErrorNotification("Profile update failed", "Your avatar failed to update because the asset was missing on the server.", user);
return null;
}
dataContext.Database.AddErrorNotification("Profile update failed", "Your avatar failed to update because the asset was missing on the server.", user);
return null;
}
}

Expand Down