aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/Validation/AbsolutePathAttribute.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-16 08:47:11 -0500
committerGitHub <noreply@github.com>2026-05-16 08:47:11 -0500
commitdfffce208c34165b83e7b2a7192cbbc81cd3a47e (patch)
tree6716a4cefe9194283678d9b788491fd8c31874ea /src/slskd/Common/Validation/AbsolutePathAttribute.cs
parent5b9309b4dba91fe317f1c04bc02493cf3d1f18f3 (diff)
parent014c9616e1e3120a729896ddd9bd701e7d84ec9d (diff)
downloadslskd-dfffce208c34165b83e7b2a7192cbbc81cd3a47e.tar.gz
Merge branch 'master' into dependabot/npm_and_yarn/src/web/babel/plugin-transform-modules-systemjs-7.29.4
Diffstat (limited to 'src/slskd/Common/Validation/AbsolutePathAttribute.cs')
-rw-r--r--src/slskd/Common/Validation/AbsolutePathAttribute.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/slskd/Common/Validation/AbsolutePathAttribute.cs b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
new file mode 100644
index 00000000..4c9f5e53
--- /dev/null
+++ b/src/slskd/Common/Validation/AbsolutePathAttribute.cs
@@ -0,0 +1,63 @@
+// <copyright file="AbsolutePathAttribute.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.Validation
+{
+ using System.ComponentModel.DataAnnotations;
+
+ /// <summary>
+ /// Validates that the specified path is absolute.
+ /// </summary>
+ public class AbsolutePathAttribute : ValidationAttribute
+ {
+ protected override ValidationResult IsValid(object value, ValidationContext validationContext)
+ {
+ if (value != null && value is string str && !string.IsNullOrEmpty(str))
+ {
+ var path = value.ToString();
+
+ if (!FileSafety.IsPathAbsolute(path))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field must be an absolute file path.");
+ }
+
+ // unrelated to absolute/relative check; we disallow traversal segments across the board so check while we're here
+ if (FileSafety.ContainsTraversalSegments(path))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field contains one or more unsafe path traversal segments ('.' or '..')");
+ }
+ }
+
+ return ValidationResult.Success;
+ }
+ }
+} \ No newline at end of file