Fix UserEnabled role being OR'd with action authorization roles FUUUUUCCCKK!!!!

Fixes #2064
This commit is contained in:
Jordan Dominion
2025-01-03 18:50:20 -05:00
parent 4605afe2ce
commit e7b1189620
3 changed files with 22 additions and 6 deletions
@@ -298,7 +298,10 @@ namespace Tgstation.Server.Host.Core
services
.AddScoped<GraphQL.Subscriptions.ITopicEventReceiver, ShutdownAwareTopicEventReceiver>()
.AddGraphQLServer()
.AddAuthorization()
.AddAuthorization(
options => options.AddPolicy(
TgsAuthorizeAttribute.PolicyName,
builder => builder.RequireRole(TgsAuthorizeAttribute.UserEnabledRole)))
.ModifyOptions(options =>
{
options.EnsureAllNodesCanBeResolved = true;
@@ -15,10 +15,15 @@ namespace Tgstation.Server.Host.Security
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
sealed class TgsAuthorizeAttribute : AuthorizeAttribute
{
/// <summary>
/// Policy used to apply global requirement of <see cref="UserEnabledRole"/>.
/// </summary>
public const string PolicyName = "Policy.UserEnabled";
/// <summary>
/// Role used to indicate access to the server is allowed.
/// </summary>
public const string UserEnabledRole = "Core.UserEnabled";
public const string UserEnabledRole = "Role.UserEnabled";
/// <summary>
/// Gets the <see cref="Api.Rights.RightsType"/> associated with the <see cref="TgsAuthorizeAttribute"/> if any.
@@ -130,8 +135,12 @@ namespace Tgstation.Server.Host.Security
private TgsAuthorizeAttribute(IEnumerable<string> roles)
{
var listRoles = roles.ToList();
listRoles.Add(UserEnabledRole);
Roles = String.Join(",", listRoles);
if (listRoles.Count != 0)
{
Roles = String.Join(",", listRoles);
}
Policy = PolicyName;
}
}
}
@@ -125,8 +125,12 @@ namespace Tgstation.Server.Host.Security
private TgsGraphQLAuthorizeAttribute(IEnumerable<string> roleNames)
{
var listRoles = roleNames.ToList();
listRoles.Add(TgsAuthorizeAttribute.UserEnabledRole);
Roles = [.. listRoles];
if (listRoles.Count != 0)
{
Roles = [.. listRoles];
}
Policy = TgsAuthorizeAttribute.PolicyName;
Apply = ApplyPolicy.Validation;
}
}