From ee9692ef49eec59dfa8e4338c652570e9623b9ce Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 7 Sep 2020 12:57:46 -0400 Subject: [PATCH 1/8] Bump API/Nuget versions for @MrStonedOne's changes --- build/Version.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/Version.props b/build/Version.props index d26a034fa2..cae79bbc9f 100644 --- a/build/Version.props +++ b/build/Version.props @@ -4,8 +4,8 @@ 4.5.1 2.1.0 - 7.3.1 - 8.3.1 + 7.3.2 + 8.3.2 5.2.5 0.4.0 1.1.0 From cce59ad915803824ee9e0fbc4e4f2b1851ffedb6 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 7 Sep 2020 12:58:07 -0400 Subject: [PATCH 2/8] Version bump to 4.5.2 --- build/Version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Version.props b/build/Version.props index cae79bbc9f..162738c49b 100644 --- a/build/Version.props +++ b/build/Version.props @@ -2,7 +2,7 @@ - 4.5.1 + 4.5.2 2.1.0 7.3.2 8.3.2 From 86a89261c3331ef261c98e1be9f2521f4a318f42 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 7 Sep 2020 13:33:58 -0400 Subject: [PATCH 3/8] Remove unused variable --- src/Tgstation.Server.Api/Rights/RightsHelper.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Api/Rights/RightsHelper.cs b/src/Tgstation.Server.Api/Rights/RightsHelper.cs index 27e550d41f..eeda047b88 100644 --- a/src/Tgstation.Server.Api/Rights/RightsHelper.cs +++ b/src/Tgstation.Server.Api/Rights/RightsHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; @@ -40,7 +40,6 @@ namespace Tgstation.Server.Api.Rights /// A representing the claim role name public static string RoleNames(TRight right) where TRight : Enum { - var flags = new List(); IEnumerable GetRoleNames() { foreach (Enum J in Enum.GetValues(right.GetType())) From 9b6163b94f055276740b661a47cc731b5b68c37b Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 7 Sep 2020 13:34:28 -0400 Subject: [PATCH 4/8] Fix instance header not being generated in swagger.json for /Job endpoint --- src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs b/src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs index c231e3c065..b928dd6f2a 100644 --- a/src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs +++ b/src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs @@ -11,7 +11,6 @@ using System.Net; using System.Net.Mime; using Tgstation.Server.Api; using Tgstation.Server.Api.Models; -using Tgstation.Server.Api.Rights; using Tgstation.Server.Host.Controllers; namespace Tgstation.Server.Host.Core @@ -228,7 +227,7 @@ namespace Tgstation.Server.Host.Core } }; - if (authAttributes.Any(attr => attr.RightsType.HasValue && RightsHelper.IsInstanceRight(attr.RightsType.Value))) + if (typeof(InstanceRequiredController).IsAssignableFrom(context.MethodInfo.DeclaringType)) operation.Parameters.Add(new OpenApiParameter { Reference = new OpenApiReference From 4a52b85f5a7e18a239a8ff6f80b1703d3b5016b8 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 7 Sep 2020 13:34:43 -0400 Subject: [PATCH 5/8] Cleaned up instance header validation --- .../Controllers/AdministrationController.cs | 2 +- .../Controllers/ApiController.cs | 33 +++++-------------- .../Controllers/HomeController.cs | 3 +- .../Controllers/InstanceController.cs | 2 +- .../Controllers/InstanceRequiredController.cs | 8 +++-- .../Controllers/UserController.cs | 4 +-- 6 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs index bb68d12467..c35de94da2 100644 --- a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs +++ b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs @@ -103,7 +103,7 @@ namespace Tgstation.Server.Host.Controllers databaseContext, authenticationContextFactory, logger, - false) + true) { this.gitHubClientFactory = gitHubClientFactory ?? throw new ArgumentNullException(nameof(gitHubClientFactory)); this.serverUpdater = serverUpdater ?? throw new ArgumentNullException(nameof(serverUpdater)); diff --git a/src/Tgstation.Server.Host/Controllers/ApiController.cs b/src/Tgstation.Server.Host/Controllers/ApiController.cs index 6c66ec832e..90a5c5f448 100644 --- a/src/Tgstation.Server.Host/Controllers/ApiController.cs +++ b/src/Tgstation.Server.Host/Controllers/ApiController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; @@ -48,11 +48,6 @@ namespace Tgstation.Server.Host.Controllers /// protected Models.Instance Instance { get; } - /// - /// If permissions are required to access the - /// - readonly bool requireInstance; - /// /// If are required /// @@ -64,14 +59,12 @@ namespace Tgstation.Server.Host.Controllers /// The value of /// The for the /// The value of - /// The value of /// The value of public ApiController( IDatabaseContext databaseContext, IAuthenticationContextFactory authenticationContextFactory, ILogger logger, - bool requireInstance, - bool requireHeaders = true) + bool requireHeaders) { DatabaseContext = databaseContext ?? throw new ArgumentNullException(nameof(databaseContext)); if (authenticationContextFactory == null) @@ -79,7 +72,6 @@ namespace Tgstation.Server.Host.Controllers Logger = logger ?? throw new ArgumentNullException(nameof(logger)); AuthenticationContext = authenticationContextFactory.CurrentAuthenticationContext; Instance = AuthenticationContext?.InstanceUser?.Instance; - this.requireInstance = requireInstance; this.requireHeaders = requireHeaders; } @@ -124,11 +116,11 @@ namespace Tgstation.Server.Host.Controllers protected ObjectResult Created(object payload) => StatusCode((int)HttpStatusCode.Created, payload); /// - /// Performs validation steps for an instance request. + /// Performs validation a request. /// /// The for the operation. /// A resulting in an appropriate on validation failure, otherwise. - protected virtual Task ValidateInstanceRequest(CancellationToken cancellationToken) + protected virtual Task ValidateRequest(CancellationToken cancellationToken) => Task.FromResult(null); /// @@ -193,20 +185,11 @@ namespace Tgstation.Server.Host.Controllers return; } - if (requireInstance) + var errorCase = await ValidateRequest(context.HttpContext.RequestAborted).ConfigureAwait(false); + if (errorCase != null) { - IActionResult errorCase = null; - if (!ApiHeaders.InstanceId.HasValue) - errorCase = BadRequest(new ErrorMessage(ErrorCode.InstanceHeaderRequired)); - else if (AuthenticationContext.InstanceUser == null) - errorCase = Forbid(); - - errorCase ??= await ValidateInstanceRequest(context.HttpContext.RequestAborted).ConfigureAwait(false); - if (errorCase != null) - { - await errorCase.ExecuteResultAsync(context).ConfigureAwait(false); - return; - } + await errorCase.ExecuteResultAsync(context).ConfigureAwait(false); + return; } } catch (HeadersException) diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index f8c5195413..58b20a3fe4 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; @@ -99,7 +99,6 @@ namespace Tgstation.Server.Host.Controllers databaseContext, authenticationContextFactory, logger, - false, (browserResolver ?? throw new ArgumentNullException(nameof(browserResolver))).Browser.Type != BrowserType.Generic && (controlPanelConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(controlPanelConfigurationOptions))).Enable) { diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index aacf3a0fe6..126458dba5 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -90,7 +90,7 @@ namespace Tgstation.Server.Host.Controllers databaseContext, authenticationContextFactory, logger, - false) + true) { this.jobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager)); this.instanceManager = instanceManager ?? throw new ArgumentNullException(nameof(instanceManager)); diff --git a/src/Tgstation.Server.Host/Controllers/InstanceRequiredController.cs b/src/Tgstation.Server.Host/Controllers/InstanceRequiredController.cs index a2474c0c34..2ec482ef59 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceRequiredController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceRequiredController.cs @@ -37,15 +37,19 @@ namespace Tgstation.Server.Host.Controllers databaseContext, authenticationContextFactory, logger, - true, true) { this.instanceManager = instanceManager ?? throw new ArgumentNullException(nameof(instanceManager)); } /// - protected override async Task ValidateInstanceRequest(CancellationToken cancellationToken) + protected override async Task ValidateRequest(CancellationToken cancellationToken) { + if (!ApiHeaders.InstanceId.HasValue) + return BadRequest(new ErrorMessage(ErrorCode.InstanceHeaderRequired)); + if (AuthenticationContext.InstanceUser == null) + return Forbid(); + if (ValidateInstanceOnlineStatus(instanceManager, Logger, Instance)) await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/Controllers/UserController.cs b/src/Tgstation.Server.Host/Controllers/UserController.cs index 5144039371..485216faa4 100644 --- a/src/Tgstation.Server.Host/Controllers/UserController.cs +++ b/src/Tgstation.Server.Host/Controllers/UserController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -58,7 +58,7 @@ namespace Tgstation.Server.Host.Controllers databaseContext, authenticationContextFactory, logger, - false) + true) { this.systemIdentityFactory = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory)); this.cryptographySuite = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite)); From 6ea3e198b2c8ad443897c0c9858d1f835cded44d Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 7 Sep 2020 13:38:31 -0400 Subject: [PATCH 6/8] Escape arguments with spaces in event scripts --- .../Components/StaticFiles/Configuration.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index de5bfb0174..5805339a58 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -480,7 +480,17 @@ namespace Tgstation.Server.Host.Components.StaticFiles using (var script = processExecutor.LaunchProcess( ioManager.ConcatPath(resolvedScriptsDir, I), resolvedScriptsDir, - String.Join(' ', parameters), + String.Join( + ' ', + parameters.Select(arg => + { + if (!arg.Contains(' ', StringComparison.Ordinal)) + return arg; + + arg = arg.Replace("\"", "\\\"", StringComparison.Ordinal); + + return $"\"{arg}\""; + })), true, true, true)) From 90ded79c77ba31c52a2268e0f0d6f166610d08b8 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 7 Sep 2020 13:41:12 -0400 Subject: [PATCH 7/8] Minor pull request template update --- .github/PULL_REQUEST_TEMPLATE.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 42203e2250..a2ac5f8698 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,6 @@ -[Release Notes]: # (Your PR should contain a detailed list of notable changes, titled appropriately. This includes any observable changes to the server or DMAPI. See examples below) +[Base Branch]: # (Please set the base branch of your pull request appropriately. If you only made a patch, code improvement, non-server code change, or comment/documentation update please target the `master` branch. Otherwise, target the `dev` branch.) + +[Release Notes]: # (Your PR should contain a detailed list of notable changes, titled appropriately. This includes any observable changes to the server or DMAPI. See examples below.) :cl: Description of your change. From 3a6d99472bf6290d03001b70cf706c6cb6e71751 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 7 Sep 2020 13:48:52 -0400 Subject: [PATCH 8/8] Further improve V3 discord mention parsing --- build/Version.props | 2 +- src/DMAPI/tgs.dm | 2 +- src/DMAPI/tgs/v3210/api.dm | 2 +- src/DMAPI/tgs/v3210/commands.dm | 2 +- src/DMAPI/tgs/v5/api.dm | 2 +- src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/Version.props b/build/Version.props index 162738c49b..4a6fc31913 100644 --- a/build/Version.props +++ b/build/Version.props @@ -6,7 +6,7 @@ 2.1.0 7.3.2 8.3.2 - 5.2.5 + 5.2.6 0.4.0 1.1.0 diff --git a/src/DMAPI/tgs.dm b/src/DMAPI/tgs.dm index 69afea8ea2..aef492020a 100644 --- a/src/DMAPI/tgs.dm +++ b/src/DMAPI/tgs.dm @@ -1,6 +1,6 @@ // tgstation-server DMAPI -#define TGS_DMAPI_VERSION "5.2.5" +#define TGS_DMAPI_VERSION "5.2.6" // All functions and datums outside this document are subject to change with any version and should not be relied on. diff --git a/src/DMAPI/tgs/v3210/api.dm b/src/DMAPI/tgs/v3210/api.dm index 9ed512f8f9..1b9d194e40 100644 --- a/src/DMAPI/tgs/v3210/api.dm +++ b/src/DMAPI/tgs/v3210/api.dm @@ -39,7 +39,7 @@ var/warned_custom_commands = FALSE /datum/tgs_api/v3210/ApiVersion() - return new /datum/tgs_version("3.2.1.1") + return new /datum/tgs_version("3.2.1.2") /datum/tgs_api/v3210/proc/trim_left(text) for (var/i = 1 to length(text)) diff --git a/src/DMAPI/tgs/v3210/commands.dm b/src/DMAPI/tgs/v3210/commands.dm index a8c3d318e5..8975179cb0 100644 --- a/src/DMAPI/tgs/v3210/commands.dm +++ b/src/DMAPI/tgs/v3210/commands.dm @@ -44,7 +44,7 @@ user.friendly_name = sender // Discord hack, fix the mention if it's only numbers (fuck you IRC trolls) - var/regex/discord_id_regex = regex(@"[0-9]+") + var/regex/discord_id_regex = regex(@"^[0-9]+$") if(discord_id_regex.Find(sender)) sender = "<@[sender]>" diff --git a/src/DMAPI/tgs/v5/api.dm b/src/DMAPI/tgs/v5/api.dm index d4326fc4a2..7c853cd7c1 100644 --- a/src/DMAPI/tgs/v5/api.dm +++ b/src/DMAPI/tgs/v5/api.dm @@ -18,7 +18,7 @@ var/initialized = FALSE /datum/tgs_api/v5/ApiVersion() - return new /datum/tgs_version("5.2.5") + return new /datum/tgs_version("5.2.6") /datum/tgs_api/v5/OnWorldNew(minimum_required_security_level) server_port = world.params[DMAPI5_PARAM_SERVER_PORT] diff --git a/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs b/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs index 321735a5b6..fc802ebccf 100644 --- a/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs +++ b/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs @@ -33,7 +33,7 @@ namespace Tgstation.Server.Host.Components.Interop /// /// The DMAPI being used. /// - public static readonly Version Version = new Version(5, 2, 5); + public static readonly Version Version = new Version(5, 2, 6); /// /// for use when communicating with the DMAPI.