Skip to content

Commit 45f321a

Browse files
committed
dcnm_fabric: hardening
Two bits of vulnerable code found when porting to ndfc-python. 1. plugins/modules/dcnm_fabric.py Accessing dictionary key directly can lead to a KeyError exception. 2. plugins/module_utils/fabric/replaced.py If user omits the DEPLOY parameter from their playbook (ndfc-python) the DEPLOY key would be None, and not get popped from the payload. This would cause NDFC to complain about an invalid key in the payload. We need to unconditionally pop DEPLOY here, if it's present. Hence, we've removed the value check (if DEPLOY is not None).
1 parent 308acb6 commit 45f321a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

plugins/module_utils/fabric/replaced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def _send_payloads(self):
468468

469469
for payload in self._payloads_to_commit:
470470
commit_payload = copy.deepcopy(payload)
471-
if commit_payload.get("DEPLOY", None) is not None:
471+
if "DEPLOY" in commit_payload:
472472
commit_payload.pop("DEPLOY")
473473
try:
474474
self._send_payload(commit_payload)

plugins/modules/dcnm_fabric.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,7 +3032,7 @@ def get_need(self):
30323032
fabric_name = want.get("FABRIC_NAME", None)
30333033
fabric_type = want.get("FABRIC_TYPE", None)
30343034

3035-
if self.features[fabric_type] is False:
3035+
if self.features.get("fabric_type") is False:
30363036
msg = f"{self.class_name}.{method_name}: "
30373037
msg += f"Features required for fabric {fabric_name} "
30383038
msg += f"of type {fabric_type} are not running on the "
@@ -3361,7 +3361,7 @@ def get_need(self):
33613361
self.need_create.append(want)
33623362
continue
33633363

3364-
if self.features[fabric_type] is False:
3364+
if self.features.get("fabric_type") is False:
33653365
msg = f"{self.class_name}.{method_name}: "
33663366
msg += f"Features required for fabric {fabric_name} "
33673367
msg += f"of type {fabric_type} are not running on the "

0 commit comments

Comments
 (0)