Implement checking for the Patchwork user agent (#1090)
Some checks failed
Continuous Integration / Build & Test (push) Has been cancelled
Upload Translations to Crowdin / crowdin-sync (push) Has been cancelled
Build Docker Image / Build and Publish (push) Has been cancelled
Qodana / qodana (push) Has been cancelled

* Implement checking for the Patchwork user agent, move logout into standalone method

* Quick fixes (awesome name)

* 403 user at login instead of logging out at /announce

* Move configuration and revert logout changes

* Rework parsing to check against GameVersion enum and game token GameVersion

* Fix logic error

oopsie

* Fix Zaprit suggestions

* Simplify patchwork game version test

* Test patchwork user agent with regex instead

* Fix Qodana warnings

* Fix remaining Qodana warnings
This commit is contained in:
FeTetra 2025-06-04 08:14:40 -04:00 committed by GitHub
commit aeba706391
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 85 additions and 4 deletions

View file

@ -3,6 +3,7 @@ using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Tickets;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
@ -212,6 +213,14 @@ public class LoginController : ControllerBase
return this.Forbid();
}
if (ServerConfiguration.Instance.Authentication.RequirePatchworkUserAgent)
{
if (!PatchworkHelper.IsValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString()))
{
return this.Forbid();
}
}
Logger.Success($"Successfully logged in user {user.Username} as {token.GameVersion} client", LogArea.Login);
user.LastLogin = TimeHelper.TimestampMillis;

View file

@ -38,5 +38,4 @@ public class LogoutController : ControllerBase
return this.Ok();
}
}

View file

@ -1,4 +1,4 @@
using System.Text;
using System.Text;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;