Merge pull request from GHSA-c8wx-65c7-q9r3

Co-authored-by: Slendy <josh@slendy.pw>
This commit is contained in:
sudokoko 2023-12-23 00:49:59 -05:00 committed by GitHub
parent e593d5c957
commit ef87606ba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41069 additions and 1 deletions

View file

@ -20,6 +20,7 @@ website notifications to indicate what went wrong.
- `LH-PUB-0008`: The level failed to publish because the root level is not an LBP3 Adventure level.
- `LH-PUB-0009`: The level failed to publish because the the user has reached their level publishing limit.
- **Fix:** Delete some of your previously published levels to make room for new ones.
- `LH-PUB-0010`: THe level failed to publish because the icon of the level is not a valid texture or image.
## Level Republishing

View file

@ -5,6 +5,7 @@ using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Entities.Token;
@ -157,6 +158,14 @@ public class PublishController : ControllerBase
return this.BadRequest();
}
if (!GameResourceHelper.IsValidTexture(slot.IconHash))
{
Logger.Warn("Rejecting level upload, invalid icon resource", LogArea.Publish);
await this.database.SendNotification(user.UserId,
$"{slot.Name} failed to publish because your level icon is invalid. (LH-PUB-0010)");
return this.BadRequest();
}
if (slot.Resources.Any(resource => !FileHelper.ResourceExists(resource)))
{
Logger.Warn("Rejecting level upload, missing resource(s)", LogArea.Publish);

View file

@ -4,6 +4,7 @@ using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Types.Users;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@ -85,7 +86,9 @@ public class UserController : ControllerBase
{
if (string.IsNullOrWhiteSpace(resource)) continue;
if (!FileHelper.ResourceExists(resource)) return this.BadRequest();
if (!FileHelper.ResourceExists(resource) && !resource.StartsWith('g')) return this.BadRequest();
if (!GameResourceHelper.IsValidTexture(resource)) return this.BadRequest();
}
if (update.IconHash != null) user.IconHash = update.IconHash;

View file

@ -0,0 +1,46 @@
using System.Collections.Immutable;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Resources;
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
public static class GameResourceHelper
{
private static readonly ImmutableList<string> textureGuids = ImmutableList<string>.Empty;
static GameResourceHelper()
{
List<string> guids = new();
using Stream? guidStream = typeof(GameResourceHelper).Assembly.GetManifestResourceStream("LBPUnion.ProjectLighthouse.Servers.GameServer.textureGuids.txt");
if (guidStream == null)
{
Logger.Warn("Failed to load texture guids, users may experience issues when setting level and profile icons", LogArea.Startup);
return;
}
using StreamReader reader = new(guidStream);
while (!reader.EndOfStream)
{
string? guid = reader.ReadLine();
if (guid == null) continue;
guids.Add(guid);
}
textureGuids = ImmutableList.Create(guids.ToArray());
}
public static bool IsValidTexture(string resource)
{
if (!FileHelper.IsResourceValid(resource)) return false;
if (resource.StartsWith("g"))
{
return textureGuids.Contains(resource[1..]);
}
return LbpFile.FromHash(resource)?.FileType is LbpFileType.Png or LbpFileType.Jpeg or LbpFileType.Plan
or LbpFileType.Painting or LbpFileType.Texture;
}
}

View file

@ -13,4 +13,8 @@
<ProjectReference Include="..\ProjectLighthouse\ProjectLighthouse.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="textureGuids.txt" />
</ItemGroup>
</Project>

File diff suppressed because it is too large Load diff