diff options
| -rw-r--r-- | .config/dotnet-tools.json | 20 | ||||
| -rw-r--r-- | src/slskd/Common/Dumper.cs | 181 | ||||
| -rw-r--r-- | src/slskd/Core/API/Controllers/ApplicationController.cs | 23 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 13 | ||||
| -rw-r--r-- | src/slskd/Program.cs | 5 | ||||
| -rw-r--r-- | src/slskd/slskd.csproj | 24 | ||||
| -rw-r--r-- | src/web/package-lock.json | 6 | ||||
| -rw-r--r-- | tests/slskd.Tests.Benchmarks/slskd.Tests.Benchmarks.csproj | 8 | ||||
| -rw-r--r-- | tests/slskd.Tests.Unit/slskd.Tests.Unit.csproj | 6 |
9 files changed, 42 insertions, 244 deletions
diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..79556b83 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,20 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-outdated-tool": { + "version": "4.8.1", + "commands": [ + "dotnet-outdated" + ], + "rollForward": false + }, + "dotnet-affected": { + "version": "7.0.1", + "commands": [ + "dotnet-affected" + ], + "rollForward": false + } + } +}
\ No newline at end of file diff --git a/src/slskd/Common/Dumper.cs b/src/slskd/Common/Dumper.cs deleted file mode 100644 index 8797d040..00000000 --- a/src/slskd/Common/Dumper.cs +++ /dev/null @@ -1,181 +0,0 @@ -// <copyright file="Dumper.cs" company="JP Dillingham"> -// ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ -// ▄▄▄▄▄▄█ █▄▄▄▄▄█ █▄▄▄▄▄█ █ -// █__ --█ █__ --█ ◄█ - █ -// █▄▄▄▄▄█▄▄█▄▄▄▄▄█▄▄█▄▄█▄▄▄▄▄█ -// ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━ ━ ━┉ ┉ ┉ -// │ Copyright (c) JP Dillingham. -// │ -// │ This program is free software: you can redistribute it and/or modify -// │ it under the terms of the GNU Affero General Public License as published -// │ by the Free Software Foundation, version 3. -// │ -// │ This program is distributed in the hope that it will be useful, -// │ but WITHOUT ANY WARRANTY; without even the implied warranty of -// │ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// │ GNU Affero General Public License for more details. -// │ -// │ You should have received a copy of the GNU Affero General Public License -// │ along with this program. If not, see https://www.gnu.org/licenses/. -// │ -// │ This program is distributed with Additional Terms pursuant to Section 7 -// │ of the AGPLv3. See the LICENSE file in the root directory of this -// │ project for the complete terms and conditions. -// │ -// │ https://slskd.org -// │ -// ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ╌ ╌╌╌╌ ╌ -// │ SPDX-FileCopyrightText: JP Dillingham -// │ SPDX-License-Identifier: AGPL-3.0-only -// ╰───────────────────────────────────────────╶──── ─ ─── ─ ── ──┈ ┈ -// </copyright> - -namespace slskd -{ - using System; - using System.Diagnostics; - using System.IO; - using System.Net.Http; - using System.Runtime.InteropServices; - using System.Threading.Tasks; - - /// <summary> - /// Dumps the contents of the application's memory to a .dmp file using dotnet-dump. - /// </summary> - /// <remarks> - /// <para> - /// Monitor https://docs.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump for tool updates. Currently supported - /// runtime IDs: - /// </para> - /// <list type="bullet"> - /// <listheader>Currently supported runtime IDs:</listheader> - /// <item>https://aka.ms/dotnet-dump/win-x86</item> - /// <item>https://aka.ms/dotnet-dump/win-x64</item> - /// <item>https://aka.ms/dotnet-dump/win-arm</item> - /// <item>https://aka.ms/dotnet-dump/win-arm64</item> - /// <item>https://aka.ms/dotnet-dump/osx-x64</item> - /// <item>https://aka.ms/dotnet-dump/linux-x64</item> - /// <item>https://aka.ms/dotnet-dump/linux-arm</item> - /// <item>https://aka.ms/dotnet-dump/linux-arm64</item> - /// <item>https://aka.ms/dotnet-dump/linux-musl-x64</item> - /// <item>https://aka.ms/dotnet-dump/linux-musl-arm64</item> - /// <item></item> - /// </list> - /// </remarks> - public class Dumper : IDisposable - { - private static readonly string URLTemplate = "https://aka.ms/dotnet-dump/$RID"; - - private string BinFile { get; set; } - private bool Disposed { get; set; } - - public void Dispose() - { - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - - public async Task<string> DumpAsync() - { - BinFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - var outputFile = Path.Combine(Path.GetTempPath(), $"slskd_{Path.GetRandomFileName()}.dmp"); - - var url = URLTemplate.Replace("$RID", GetRID()); - - await Download(url, BinFile); - - if (!System.OperatingSystem.IsWindows()) - { - await ExecAsync("/bin/chmod", $"+x \"{BinFile}\""); - } - - await ExecAsync(BinFile, $"collect --process-id {Environment.ProcessId} --type full --output \"{outputFile}\""); - - return outputFile; - } - - protected virtual void Dispose(bool disposing) - { - if (!Disposed) - { - if (disposing) - { - TryDelete(BinFile); - } - - Disposed = true; - } - } - - private async Task Download(string url, string destination) - { - using var http = new HttpClient(); - - using var localStream = new FileStream(destination, FileMode.OpenOrCreate); - using var remoteStream = await http.GetStreamAsync(url); - - await remoteStream.CopyToAsync(localStream); - } - - private async Task ExecAsync(string bin, string args) - { - using var process = new Process(); - process.StartInfo.FileName = bin; - process.StartInfo.Arguments = args; - process.Start(); - await process.WaitForExitAsync(); - - if (process.ExitCode != 0) - { - throw new SlskdException($"'{bin}' exited with code {process.ExitCode}"); - } - } - - private string GetRID() - { - // one of: x86, x64, arm, arm64, wasm, s390x - var arch = RuntimeInformation.ProcessArchitecture.ToString().ToLower(); - - // .RuntimeIdentifier returns a very specific (e.g. win10-x64) RID, and we need a generic one (e.g. win-x64). rather - // than trying to hack this up to derive a generic RID, only inspect this to see if this build targeted musl libc (we - // can't get this any other way) - var isMusl = RuntimeInformation.RuntimeIdentifier.ToLower().Contains("musl"); - - string os = default; - - // seems like there should be a way to just retrieve this, but there is not as of .NET 6 - if (System.OperatingSystem.IsLinux()) - { - os = "linux"; - } - else if (System.OperatingSystem.IsWindows()) - { - os = "win"; - } - else if (System.OperatingSystem.IsMacOS() || System.OperatingSystem.IsFreeBSD()) - { - os = "osx"; - } - - if (os == default) - { - throw new PlatformNotSupportedException($"Unable to determine operating system. RID is {RuntimeInformation.RuntimeIdentifier}; did someone forget to update Dumper.cs to reflect .NET targeting changes?"); - } - - return $"{os}-{(isMusl ? "musl-" : string.Empty)}{arch}"; - } - - private bool TryDelete(string file) - { - try - { - File.Delete(file); - return true; - } - catch (FileNotFoundException) - { - return false; - } - } - } -}
\ No newline at end of file diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index fc2e31a7..b90655aa 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -169,29 +169,6 @@ namespace slskd.Core.API } [ApiExplorerSettings(IgnoreApi = true)] - [HttpGet("dump")] - [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.AdministratorOnly)] - public async Task<IActionResult> DumpMemory() - { - if (OptionsAtStartup.Flags.Dumpable) - { - Log.Warning("Dumping application memory..."); - - using var dumper = new Dumper(); - var file = await dumper.DumpAsync(); - - Log.Warning("Dump complete"); - - // the dump contains everything in memory, including secrets. delete it once it has been sent - var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None, bufferSize: 4096, FileOptions.DeleteOnClose); - return File(stream, "application/octet-stream", "slskd.dmp"); - } - - Log.Warning("Unauthorized attempt to dump application memory; Flags.Dumpable is disabled"); - return Forbid(); - } - - [ApiExplorerSettings(IgnoreApi = true)] [HttpPost("loopback")] [Authorize(Policy = AuthPolicy.Any, Roles = AuthRole.ReadWriteOrAdministrator)] public IActionResult Loopback([FromBody] object body) diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index dd9c3d02..1f6ceac2 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -484,19 +484,6 @@ namespace slskd public bool Volatile { get; init; } = false; /// <summary> - /// Gets a value indicating whether real-time memory dumping via API is enabled. - /// </summary> - /// <remarks> - /// This can expose sensitive information, and should be turned on only to diagnose memory leaks. - /// As such, it is and must remain undocumented. - /// </remarks> - [Argument(default, "dumpable")] - [EnvironmentVariable("DUMPABLE")] - [Description("enable run-time memory dumps via api")] - [RequiresRestart] - public bool Dumpable { get; init; } = false; - - /// <summary> /// Gets a value indicating whether user-defined regular expressions are case sensitive. /// </summary> [Argument(default, "case-sensitive-regex")] diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 5347e5f5..372dc998 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -519,11 +519,6 @@ namespace slskd Log.Information("Using application directory {AppDirectory}", AppDirectory); Log.Information("Using configuration file {ConfigurationFile}", ConfigurationFile); - if (OptionsAtStartup.Flags.Dumpable) - { - Log.Warning("Application memory dumps are ENABLED; this can expose sensitive information, including environment variables from the shell. Disable Flags.Dumpable to disable."); - } - if (OptionsAtStartup.Flags.NoConfigWatch) { Log.Warning("Configuration watch DISABLED; all configuration changes will require a restart to take effect"); diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index 7e44e57d..f17e6046 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -44,38 +44,38 @@ </Target> <ItemGroup> - <PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="10.0.0" /> - <PackageReference Include="Dapper" Version="2.1.79" /> + <PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="10.2.1" /> + <PackageReference Include="Dapper" Version="2.1.89" /> <PackageReference Include="FluentFTP" Version="49.0.2" /> <PackageReference Include="IPAddressRange" Version="6.3.0" /> - <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.9" /> - <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.9" /> - <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.301"> + <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.13" /> + <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.13" /> + <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.402"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> - <PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.9" /> - <PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.9" /> - <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="10.0.9" /> + <PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.13" /> + <PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.13" /> + <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="10.0.13" /> <PackageReference Include="OneOf" Version="3.0.271" /> <PackageReference Include="prometheus-net" Version="8.2.1" /> <PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1" /> <PackageReference Include="prometheus-net.AspNetCore.HealthChecks" Version="8.2.1" /> <PackageReference Include="prometheus-net.DotNetRuntime" Version="4.4.1" /> <PackageReference Include="prometheus-net.SystemMetrics" Version="3.1.0" /> - <PackageReference Include="Serilog" Version="4.3.1" /> + <PackageReference Include="Serilog" Version="4.4.0" /> <PackageReference Include="Serilog.AspNetCore" Version="10.0.0" /> <PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" /> <PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" /> <PackageReference Include="Serilog.Sinks.File" Version="7.0.0" /> - <PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="9.0.1" /> + <PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="9.0.2" /> <PackageReference Include="Serilog.Sinks.Http" Version="9.2.1" /> <PackageReference Include="Soulseek" Version="10.0.2" /> - <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556"> + <PackageReference Include="StyleCop.Analyzers" Version="1.3.151-beta"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> - <PackageReference Include="Swashbuckle.AspNetCore" Version="10.2.3" /> + <PackageReference Include="Swashbuckle.AspNetCore" Version="10.3.1" /> <PackageReference Include="TagLibSharp" Version="2.3.0" /> <PackageReference Include="Utility.CommandLine.Arguments" Version="6.0.0" /> <PackageReference Include="Utility.EnvironmentVariables" Version="1.0.5" /> diff --git a/src/web/package-lock.json b/src/web/package-lock.json index a3e9c55e..f3d75bd4 100644 --- a/src/web/package-lock.json +++ b/src/web/package-lock.json @@ -10898,9 +10898,9 @@ } }, "node_modules/fast-uri": { - "version": "3.1.7", - "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.7.tgz", - "integrity": "sha512-dOvZVzjdZdz7phd9v6jCbwxrBW3fK6n8Rc0CtdmM4bumzMnxywBYhuph6J819RRw/ku+rLbelwfMunktuzVVHg==", + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz", + "integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==", "dev": true, "funding": [ { diff --git a/tests/slskd.Tests.Benchmarks/slskd.Tests.Benchmarks.csproj b/tests/slskd.Tests.Benchmarks/slskd.Tests.Benchmarks.csproj index 580612e4..3d022d41 100644 --- a/tests/slskd.Tests.Benchmarks/slskd.Tests.Benchmarks.csproj +++ b/tests/slskd.Tests.Benchmarks/slskd.Tests.Benchmarks.csproj @@ -14,15 +14,15 @@ <ItemGroup> <PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" /> - <PackageReference Include="BenchmarkDotNet" Version="0.15.4" /> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.7.0" /> + <PackageReference Include="BenchmarkDotNet" Version="0.15.8" /> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" /> <PackageReference Include="Moq" Version="4.16.1" /> <PackageReference Include="xunit" Version="2.9.3" /> - <PackageReference Include="xunit.runner.visualstudio" Version="3.1.5"> + <PackageReference Include="xunit.runner.visualstudio" Version="4.0.1"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="coverlet.msbuild" Version="10.0.1"> + <PackageReference Include="coverlet.msbuild" Version="10.1.0"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> diff --git a/tests/slskd.Tests.Unit/slskd.Tests.Unit.csproj b/tests/slskd.Tests.Unit/slskd.Tests.Unit.csproj index caf8e3c3..f6e4909a 100644 --- a/tests/slskd.Tests.Unit/slskd.Tests.Unit.csproj +++ b/tests/slskd.Tests.Unit/slskd.Tests.Unit.csproj @@ -14,14 +14,14 @@ <ItemGroup>
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.1" />
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.7.0" />
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.9.3" />
- <PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
+ <PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
- <PackageReference Include="coverlet.msbuild" Version="10.0.1">
+ <PackageReference Include="coverlet.msbuild" Version="10.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
|
