fix(secrets): audit malformed ${secret:} tokens, cap SecretName at 450, resolve local UNC shares (scadaproj#52)
Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -7,6 +7,9 @@ namespace ZB.MOM.WW.Secrets.Abstractions;
|
||||
/// </summary>
|
||||
public readonly record struct SecretName
|
||||
{
|
||||
/// <summary>The longest permitted normalized name; matches the hub's <c>NVARCHAR(450)</c> name column.</summary>
|
||||
public const int MaxLength = 450;
|
||||
|
||||
private const string AllowedChars = "abcdefghijklmnopqrstuvwxyz0123456789._/-";
|
||||
|
||||
/// <summary>
|
||||
@@ -17,7 +20,7 @@ public readonly record struct SecretName
|
||||
/// <exception cref="ArgumentException">
|
||||
/// The value is null, empty, or whitespace; contains the path-traversal sequence
|
||||
/// <c>..</c>; is rooted (starts or ends with <c>/</c>) or contains an empty path
|
||||
/// segment (<c>//</c>); or contains any character outside <c>[a-z0-9._/-]</c> (after
|
||||
/// segment (<c>//</c>); or is longer than <see cref="MaxLength"/> (450) characters; or contains any character outside <c>[a-z0-9._/-]</c> (after
|
||||
/// trim and lowercasing).
|
||||
/// </exception>
|
||||
public SecretName(string value)
|
||||
@@ -31,6 +34,13 @@ public readonly record struct SecretName
|
||||
nameof(value));
|
||||
}
|
||||
|
||||
if (normalized.Length > MaxLength)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Secret name must be at most {MaxLength} characters (was {normalized.Length}).",
|
||||
nameof(value));
|
||||
}
|
||||
|
||||
if (normalized.Contains("..", StringComparison.Ordinal))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
|
||||
Reference in New Issue
Block a user