diff options
| author | tanaka takashi <isazaka@gmail.com> | 2026-08-11 21:53:57 +0900 |
|---|---|---|
| committer | tanaka takashi <isazaka@gmail.com> | 2026-08-11 21:53:57 +0900 |
| commit | 7c9794f8d4d05074b96bb525d19db4ee1f6b3e95 (patch) | |
| tree | cb8961ee170d9f6874513e8b1a99b06855bb0707 /src/Agent.Windows/Security/PathPolicy.cs | |
| parent | 6c3458a5ec37a5b69957ad17c84de58984698f25 (diff) | |
Complete runtime diagnostics and verification coverage
Diffstat (limited to 'src/Agent.Windows/Security/PathPolicy.cs')
| -rw-r--r-- | src/Agent.Windows/Security/PathPolicy.cs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Agent.Windows/Security/PathPolicy.cs b/src/Agent.Windows/Security/PathPolicy.cs index 4f6eec4..3de4804 100644 --- a/src/Agent.Windows/Security/PathPolicy.cs +++ b/src/Agent.Windows/Security/PathPolicy.cs @@ -18,7 +18,8 @@ public sealed class PathPolicy(IEnumerable<FilePolicyEntry> entries) public void Demand(string path, FileCapability required) { if (!IsAllowed(path, required)) - throw new SandboxPolicyException("policy.deny", $"'{path}' is not approved for {required}. Add the canonical path to sandbox.filesystem.{required.ToString().ToLowerInvariant()} and restart the server."); + throw new SandboxPolicyException("policy.deny", $"'{path}' is not approved for {required}. Add the canonical path to sandbox.filesystem.{required.ToString().ToLowerInvariant()} and restart the server.", + "filesystem", Path.GetFullPath(path), required.ToString().ToLowerInvariant(), $"sandbox.filesystem.{required.ToString().ToLowerInvariant()}"); } private static bool IsAtOrBelow(string candidate, string root) => @@ -43,7 +44,8 @@ public static class CanonicalPath { FileSystemInfo info = Directory.Exists(current) ? new DirectoryInfo(current) : new FileInfo(current); string? target = info.ResolveLinkTarget(returnFinalTarget: true)?.FullName ?? info.LinkTarget; - throw new SandboxPolicyException("path.reparse", $"Reparse points are not allowed: component='{current}'. Approve the resolved canonical target{(string.IsNullOrWhiteSpace(target) ? string.Empty : $" '{Path.GetFullPath(target)}'")} instead."); + throw new SandboxPolicyException("path.reparse", $"Reparse points are not allowed: component='{current}'. Approve the resolved canonical target{(string.IsNullOrWhiteSpace(target) ? string.Empty : $" '{Path.GetFullPath(target)}'")} instead.", + "filesystem", current, null, string.IsNullOrWhiteSpace(target) ? "sandbox.filesystem" : Path.GetFullPath(target)); } } if (requireExisting && !File.Exists(fullPath) && !Directory.Exists(fullPath)) throw new FileNotFoundException("Approved path does not exist.", fullPath); @@ -51,7 +53,12 @@ public static class CanonicalPath } } -public sealed class SandboxPolicyException(string code, string message) : UnauthorizedAccessException(message) +public sealed class SandboxPolicyException(string code, string message, string category = "policy", string? targetPath = null, + string? requiredPermission = null, string? resolution = null) : UnauthorizedAccessException(message) { public string Code { get; } = code; + public string Category { get; } = category; + public string? TargetPath { get; } = targetPath; + public string? RequiredPermission { get; } = requiredPermission; + public string? Resolution { get; } = resolution; } |
