Skip to content

Commit 31789b7

Browse files
Merge pull request #38 from netboxlabs/features-2025.11.01
Potential fix for code scanning alert no. 13: Information exposure through an exception
2 parents 7617f37 + f533b72 commit 31789b7

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

netbox-event-driven-automation-flask-app/helpers/netbox_proxmox.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import urllib
77

88
from proxmoxer import ProxmoxAPI, ResourceException
9+
import logging
910

1011
class NetBoxProxmoxHelper:
1112
def __init__(self, cfg_data, proxmox_node, debug=False):
@@ -696,12 +697,15 @@ def __wait_for_migration_task(self, proxmox_node: str, proxmox_task_id: int):
696697
else:
697698
return 500, {'result': f"Task {proxmox_task_id} is stopped but exit status does not appear to be successful: {task_status['exit_status']}"}
698699
except ResourceException as e:
699-
return 500, {'content': f"Proxmox API error: {e}"}
700+
logging.error(f"Proxmox API ResourceException: {e}")
701+
return 500, {'content': "Proxmox API error occurred."}
700702
except requests.exceptions.ConnectionError as e:
701-
return 500, {'content': f"Failed to connect to Proxmox API: {e}"}
703+
logging.error(f"Proxmox API ConnectionError: {e}")
704+
return 500, {'content': "Failed to connect to Proxmox API."}
702705
except requests.exceptions.HTTPError as e:
703706
status = e.response.status_code
704-
return 500, {'content': f"HTTP {status}: {e.response.text}"}
707+
logging.error(f"Proxmox API HTTPError {status}: {e.response.text}")
708+
return 500, {'content': f"Proxmox API HTTP error occurred (code {status})."}
705709

706710

707711
def migrate_vm(self, proxmox_vmid: int, proxmox_node: str, proxmox_target_node: str):
@@ -714,12 +718,15 @@ def migrate_vm(self, proxmox_vmid: int, proxmox_node: str, proxmox_target_node:
714718
migrate_vm_task_id = self.proxmox_api.nodes(proxmox_node).qemu(proxmox_vmid).migrate.post(**migrate_vm_data)
715719
return self.__wait_for_migration_task(proxmox_node, migrate_vm_task_id)
716720
except ResourceException as e:
717-
return 500, {'result': f"Proxmox API error: {e}"}
718-
except requests.exceptions.ConnectionError:
719-
return 500, {'result': f"Failed to connect to Proxmox API: {e}"}
721+
logging.error(f"Proxmox API ResourceException: {e}")
722+
return 500, {'result': "Proxmox API error occurred."}
723+
except requests.exceptions.ConnectionError as e:
724+
logging.error(f"Proxmox API ConnectionError: {e}")
725+
return 500, {'result': "Failed to connect to Proxmox API."}
720726
except requests.exceptions.HTTPError as e:
721727
status = e.response.status_code
722-
return 500, {'result': f"HTTP {status}: {e.response.text}"}
728+
logging.error(f"Proxmox API HTTPError {status}: {e.response.text}")
729+
return 500, {'result': f"Proxmox API HTTP error occurred (code {status})."}
723730

724731

725732
def migrate_lxc(self, proxmox_vmid: int, proxmox_node: str, proxmox_target_node: str):
@@ -733,11 +740,14 @@ def migrate_lxc(self, proxmox_vmid: int, proxmox_node: str, proxmox_target_node:
733740
self.__wait_for_migration_task(proxmox_node, migrate_lxc_task_id)
734741
return 200, {'result': f"LXC (vmid: {proxmox_vmid}) has been migrated to node {proxmox_target_node}"}
735742
except ResourceException as e:
736-
return 500, {'result': f"Proxmox API error: {e}"}
737-
except requests.exceptions.ConnectionError:
738-
return 500, {'result': f"Failed to connect to Proxmox API: {e}"}
743+
logging.error(f"Proxmox API ResourceException: {e}")
744+
return 500, {'result': "Proxmox API error occurred."}
745+
except requests.exceptions.ConnectionError as e:
746+
logging.error(f"Proxmox API ConnectionError: {e}")
747+
return 500, {'result': "Failed to connect to Proxmox API."}
739748
except requests.exceptions.HTTPError as e:
740749
status = e.response.status_code
741-
return 500, {'result': f"HTTP {status}: {e.response.text}"}
750+
logging.error(f"Proxmox API HTTPError {status}: {e.response.text}")
751+
return 500, {'result': f"Proxmox API HTTP error occurred (code {status})."}
742752

743753

0 commit comments

Comments
 (0)