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:
+44
@@ -139,6 +139,50 @@ public sealed class SecretsStorePathSpellingTests : IDisposable
|
||||
Assert.True(Inside(Path.Combine(longDir, "secrets.db"), shortDir!));
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void An_ordinary_local_share_pointing_at_the_content_root_is_inside_on_windows()
|
||||
{
|
||||
Skip.IfNot(OperatingSystem.IsWindows(), "Windows path semantics");
|
||||
string root = Path.Combine(_base, "app");
|
||||
string share = "zbtest" + Guid.NewGuid().ToString("N")[..8];
|
||||
Skip.IfNot(CreateShare(share, root), "cannot create an SMB share here (needs Administrators)");
|
||||
try
|
||||
{
|
||||
Assert.True(Inside($@"\\localhost\{share}\data\secrets.db", root));
|
||||
Assert.True(Inside($@"\\{Environment.MachineName}\{share}\secrets.db", root));
|
||||
Assert.False(Inside($@"\\localhost\{share}\secrets.db", Path.Combine(_base, "outside")));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_ = NetShareDel(null, share, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CreateShare(string name, string path)
|
||||
{
|
||||
var info = new ShareInfo2 { shi2_netname = name, shi2_type = 0, shi2_max_uses = uint.MaxValue, shi2_path = path };
|
||||
return NetShareAdd(null, 2, ref info, out _) == 0;
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
|
||||
private struct ShareInfo2
|
||||
{
|
||||
public string shi2_netname;
|
||||
public uint shi2_type;
|
||||
public string? shi2_remark;
|
||||
public uint shi2_permissions;
|
||||
public uint shi2_max_uses;
|
||||
public uint shi2_current_uses;
|
||||
public string shi2_path;
|
||||
public string? shi2_passwd;
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("netapi32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
|
||||
private static extern uint NetShareAdd(string? server, uint level, ref ShareInfo2 buf, out uint parmErr);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("netapi32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
|
||||
private static extern uint NetShareDel(string? server, string netName, uint reserved);
|
||||
|
||||
private static string? ShortName(string path)
|
||||
{
|
||||
char[] buffer = new char[1024];
|
||||
|
||||
Reference in New Issue
Block a user