-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZAP import accepts types other than "url" #269
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,17 +376,49 @@ def _setup_zap_automation(self): | |
|
||
def _setup_import_urls(self): | ||
"""If importUrlsFromFile exists: | ||
prepare an import job for URLs importUrlsFromFile _must_ be an existing file on the host | ||
Its content is a text file: a list of GET URLs, each of which will be scanned | ||
Prepare a URL import job. All ZAP's import job are supported: 'har', 'modsec2', 'url' (default), 'zap_messages' | ||
|
||
2 possibilities: | ||
1- [for backward compatibility] if importUrlsFromFile is a string: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to migrate between config versions, rather than try to handle two different schemas? I believe there is migration code already but I haven't looked closely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a new commit for this purpose |
||
it must point to an existing file on the host | ||
|
||
2- importUrlsFromFile is a dictionary: { "type": "<type>", "fileName": "<path/to/file>"} | ||
|
||
The filename of the import will always be copied in the `container_work_dir` as importUrls.txt | ||
""" | ||
job = {"name": "import", "type": "import", "parameters": {"type": "url"}} | ||
# Basic job config. The `type` parameter will be set later | ||
job = { | ||
"name": "import", | ||
"type": "import", | ||
"parameters": {"fileName": f"{self.container_work_dir}/importUrls.txt"}, | ||
} | ||
|
||
types = ("har", "modsec2", "url", "zap_messages") | ||
|
||
orig = self.my_conf("importUrlsFromFile") | ||
if not orig: | ||
source = "" # Location of the import file on the host | ||
|
||
conf = self.my_conf("importUrlsFromFile") | ||
if not conf: | ||
return | ||
dest = f"{self.container_work_dir}/importUrls.txt" | ||
self._include_file(orig, dest) | ||
job["parameters"]["fileName"] = dest | ||
if isinstance(conf, str): | ||
# Backward compatibility with previous behavior | ||
source = conf | ||
job["parameters"]["type"] = "url" | ||
|
||
elif isinstance(conf, dict): | ||
# "importUrlsFromFile" = { type, fileName } | ||
source = self.my_conf("importUrlsFromFile.fileName") | ||
if not source: | ||
raise ValueError("ZAP config error: importUrlsFromFile must have a `fileName` entry") | ||
job["parameters"]["type"] = self.my_conf("importUrlsFromFile.type", "url") | ||
|
||
else: | ||
raise ValueError("ZAP config error: importUrlsFromFile must be a dictionary") | ||
|
||
if not job["parameters"]["type"] in types: | ||
raise ValueError(f"ZAP config error: importUrlsFromFile.type must be within {types}") | ||
|
||
self._include_file(source, job["parameters"]["fileName"]) | ||
self.automation_config["jobs"].append(job) | ||
|
||
def _setup_export_site_tree(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this require a config schema version change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not if we keep backward compatibility: we can simply suggest only the new method, while keeping the old one valid for historical purpose.
[quick additional note: backward compatibility was removed based on next conversation]