fix: resolve F039 bare catches and F084 session secret exposure

F039 (regressed): Replace bare catch blocks with filtered catches that
exclude OutOfMemoryException and StackOverflowException, per D004.
- VmService.PingGuestAgent: catch now filters fatal exceptions
- ImportPveOvaCmdlet: catch now filters fatal exceptions + WriteVerbose

F084 (new): Add PveSession format view to PSProxmoxVE.format.ps1xml
that shows only Hostname, Port, AuthMode, IsExpired, and ServerVersion
in default table output. Sensitive properties (Ticket, ApiToken,
CsrfToken) are hidden from default display but remain accessible
via Select-Object * or direct property access.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-24 18:18:56 -05:00
parent 0789601e33
commit c0a37d5ef3
3 changed files with 62 additions and 2 deletions
+1 -1
View File
@@ -550,7 +550,7 @@ namespace PSProxmoxVE.Core.Services
client.PostAsync($"nodes/{Uri.EscapeDataString(node)}/qemu/{vmid}/agent/ping").GetAwaiter().GetResult();
return true;
}
catch
catch (Exception ex) when (ex is not OutOfMemoryException and not StackOverflowException)
{
return false;
}
@@ -274,9 +274,10 @@ namespace PSProxmoxVE.Cmdlets.Vms
var vm = vmService.GetVm(session, Node, vmId);
WriteObject(vm);
}
catch
catch (Exception ex) when (ex is not OutOfMemoryException and not StackOverflowException)
{
// If the VM isn't queryable yet (e.g. disk import still running), return basic info
WriteVerbose($"VM retrieval failed, returning basic info: {ex.Message}");
WriteObject(new PveVm
{
VmId = vmId,
+59
View File
@@ -1356,5 +1356,64 @@
</TableControl>
</View>
<!-- PSProxmoxVE.Core.Authentication.PveSession -->
<!-- Hides sensitive properties (Ticket, ApiToken, CsrfToken) from default output -->
<View>
<Name>PSProxmoxVE.Core.Authentication.PveSession</Name>
<ViewSelectedBy>
<TypeName>PSProxmoxVE.Core.Authentication.PveSession</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Hostname</Label>
<Width>25</Width>
<Alignment>Left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Port</Label>
<Width>6</Width>
<Alignment>Right</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>AuthMode</Label>
<Width>10</Width>
<Alignment>Left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Expired</Label>
<Width>8</Width>
<Alignment>Left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Version</Label>
<Width>15</Width>
<Alignment>Left</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>Hostname</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Port</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>AuthMode</PropertyName>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>if ($_.IsExpired) { 'Yes' } else { 'No' }</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>if ($_.ServerVersion) { $_.ServerVersion.ToString() } else { 'Unknown' }</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>