Skip to content

Commit 55cfd7a

Browse files
committed
Fixed IndexError when parsing malformed --modules-extra-args
- Added validation to check for '=' sign before splitting - Added validation to reject empty keys (e.g., '=value') - Used internationalized error messages with _() function - Added error_modules_extra_args_format and error_modules_extra_args_empty_key to locale - Used split('=', 1) to properly handle values containing '=' characters - Strip whitespace from keys Fixes issue #1199
1 parent 0cd1d0d commit 55cfd7a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

nettacker/core/arg_parser.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,20 @@ def parse_arguments(self):
736736
if options.modules_extra_args:
737737
all_args = {}
738738
for args in options.modules_extra_args.split("&"):
739-
value = args.split("=")[1]
739+
# Validate format
740+
if "=" not in args:
741+
die_failure(_("error_modules_extra_args_format").format(args))
742+
743+
# Split with maxsplit=1 to handle values containing '='
744+
parts = args.split("=", 1)
745+
key = parts[0].strip()
746+
value = parts[1]
747+
748+
# Validate key is not empty
749+
if not key:
750+
die_failure(_("error_modules_extra_args_empty_key"))
751+
752+
# Type conversion logic
740753
if value.lower() == "true":
741754
value = True
742755
elif value.lower() == "false":
@@ -756,7 +769,8 @@ def parse_arguments(self):
756769
value = int(value)
757770
except Exception:
758771
pass
759-
all_args[args.split("=")[0]] = value
772+
773+
all_args[key] = value
760774
options.modules_extra_args = all_args
761775

762776
options.timeout = float(options.timeout)

nettacker/locale/en.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ error_target_file: "Cannot specify the target(s), unable to open file: {0}"
3737
error_username: "Cannot specify the username(s), unable to open file: {0}"
3838
error_passwords: "Cannot specify the password(s), unable to open file: {0}"
3939
error_wordlist: "Cannot specify the word(s), unable to open file {0}"
40+
error_modules_extra_args_format: "Invalid format for --modules-extra-args: '{0}'\nExpected format: key1=value1&key2=value2\nExample: --modules-extra-args \"x_api_key=123&xyz_passwd=abc\""
41+
error_modules_extra_args_empty_key: "Invalid --modules-extra-args: empty key is not allowed\nEach argument must be in format: key=value"
4042
exclude_scan_method: choose scan method to exclude {0}
4143
file_write_error: file "{0}" is not writable!
4244
library_not_supported: library [{0}] is not support!

0 commit comments

Comments
 (0)