Skip to content

Commit 2ce8fe8

Browse files
committed
Refactored ajax spider configuration.
1 parent 74e0a0a commit 2ce8fe8

5 files changed

Lines changed: 27 additions & 13 deletions

File tree

‎scanners/zap-extended/scanner/scbzapv2/zap_spider.py‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, zap: ZAPv2, config: ZapConfiguration):
3333
self.__zap = zap
3434
self.__config = config
3535

36-
def start_spider_by_url(self, url: str, ajax: bool) -> int:
36+
def start_spider_by_url(self, url: str) -> int:
3737
""" Starts a ZAP Spider for the given url, based on the given configuration and ZAP instance.
3838
3939
Parameters
@@ -44,24 +44,26 @@ def start_spider_by_url(self, url: str, ajax: bool) -> int:
4444
True if the ajax spider must be used instead of the traditional spider, otherwise false.
4545
"""
4646
spiderId = -1
47+
ajax_config=False
4748

4849
if self.__config.has_spider_configurations:
49-
logging.info('Trying to start Spider (Ajax: %s) by configuration target url %s', str(ajax), url)
5050

5151
context=self.__config.get_context_by_url(url)
5252

5353
spider_config=None
5454
if "name" in context:
55-
spider_config=self.__config.get_spider_by_context_name(str(context["name"]))
55+
spider_config = self.__config.get_spider_by_context_name(str(context["name"]))
56+
ajax = bool(spider_config["ajax"]) if "ajax" in spider_config else False
5657

57-
spiderId = self._start_spider(spider_config=spider_config, ajax=ajax)
58+
logging.info('Trying to start Spider (Ajax: %s) by configuration target url %s', str(ajax), url)
59+
spiderId = self._start_spider(spider_config=spider_config, ajax=ajax_config)
5860
else:
5961
logging.error("There is no spider specific configuration found.")
6062

6163

6264
return int(spiderId)
6365

64-
def start_spider_by_index(self, index: int, ajax: bool) -> int:
66+
def start_spider_by_index(self, index: int) -> int:
6567
""" Starts a ZAP Spider with the given index for the spiders configuration, based on the given configuration and ZAP instance.
6668
6769
Parameters
@@ -72,14 +74,18 @@ def start_spider_by_index(self, index: int, ajax: bool) -> int:
7274
True if the ajax spider must be used instead of the traditional spider, otherwise false.
7375
"""
7476
spiderId = -1
77+
ajax_config=False
7578

7679
if self.__config.has_spider_configurations:
80+
spider_config = self.__config.get_spider_by_index(index)
81+
ajax = bool(spider_config["ajax"]) if "ajax" in spider_config else False
82+
7783
logging.debug('Trying to start Spider (Ajax: %s) by configuration index %s', str(ajax), str(index))
78-
spiderId = self._start_spider(spider_config=self.__config.get_spider_by_index(index), ajax=ajax)
84+
spiderId = self._start_spider(spider_config=spider_config, ajax=ajax)
7985

8086
return int(spiderId)
8187

82-
def start_spider_by_name(self, name: str, ajax: bool) -> int:
88+
def start_spider_by_name(self, name: str) -> int:
8389
""" Starts a ZAP Spider with the given name for the spiders configuration, based on the given configuration and ZAP instance.
8490
8591
Parameters
@@ -90,8 +96,16 @@ def start_spider_by_name(self, name: str, ajax: bool) -> int:
9096
True if the ajax spider must be used instead of the traditional spider, otherwise false.
9197
"""
9298

99+
spiderId = -1
100+
93101
if self.__config.has_spider_configurations:
94-
self._start_spider(spider_config=self.__config.get_spider_by_name(name), ajax=ajax)
102+
spider_config = self.__config.get_spider_by_name(name)
103+
ajax = bool(spider_config["ajax"]) if "ajax" in spider_config else False
104+
105+
logging.debug('Trying to start Spider (Ajax: %s) by configuration index %s', str(ajax), str(index))
106+
spiderId = self._start_spider(spider_config=spider_config, ajax=ajax)
107+
108+
return int(spiderId)
95109

96110
def wait_until_http_spider_finished(self, spider_id: int):
97111
""" Wait until the running ZAP Spider finished and log results.

scanners/zap-extended/scanner/tests/mocks/empty-files/2_zap-extended-scan-config.yaml renamed to scanners/zap-extended/scanner/tests/mocks/empty-files/1_zap-extended-scan-config.yaml

File renamed without changes.

‎scanners/zap-extended/scanner/tests/mocks/scan-full-juiceshop-local/1_zap-extended-scan-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ scanners:
7373
# Int: The max time in minutes any individual rule will be allowed to run for, default: 0 unlimited
7474
maxRuleDurationInMins: 1
7575
# Int: The max time in minutes the active scanner will be allowed to run for, default: 0 unlimited
76-
maxScanDurationInMins: 5
76+
maxScanDurationInMins: 2
7777
# Int: The max number of threads per host, default: 2
7878
threadPerHost: 5
7979
# Int: The delay in milliseconds between each request, use to reduce the strain on the target, default 0

‎scanners/zap-extended/scanner/tests/test_integration_docker_local.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_bodgeit_scan(get_bodgeit_url, get_juiceshop_url, get_zap_instance: ZAPv
108108
if config and config.has_spider_configurations:
109109
# Starting to configure the ZAP Spider Instance based on the given Configuration
110110
zap_spider = ZapConfigureSpider(zap, config)
111-
spider_id = zap_spider.start_spider_by_url(target, False)
111+
spider_id = zap_spider.start_spider_by_url(target)
112112

113113
assert int(zap.spider.status(spider_id)) > 0
114114

@@ -159,7 +159,7 @@ def test_juiceshop_scan(get_bodgeit_url, get_juiceshop_url, get_zap_instance: ZA
159159
if config and config.has_spider_configurations:
160160
# Starting to configure the ZAP Spider Instance based on the given Configuration
161161
zap_spider = ZapConfigureSpider(zap, config)
162-
spider_id = zap_spider.start_spider_by_url(target, True)
162+
spider_id = zap_spider.start_spider_by_url(target)
163163

164164
assert zap.ajaxSpider.status == 'running'
165165

‎scanners/zap-extended/scanner/tests/test_integration_zap_local.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_bodgeit_scan(get_bodgeit_url, get_juiceshop_url, get_zap_instance: ZAPv
108108
if config and config.has_spider_configurations:
109109
# Starting to configure the ZAP Spider Instance based on the given Configuration
110110
zap_spider = ZapConfigureSpider(zap, config)
111-
spider_id = zap_spider.start_spider_by_url(target, False)
111+
spider_id = zap_spider.start_spider_by_url(target)
112112

113113
assert int(zap.spider.status(spider_id)) > 0
114114

@@ -159,7 +159,7 @@ def test_juiceshop_scan(get_bodgeit_url, get_juiceshop_url, get_zap_instance: ZA
159159
if config and config.has_spider_configurations:
160160
# Starting to configure the ZAP Spider Instance based on the given Configuration
161161
zap_spider = ZapConfigureSpider(zap, config)
162-
spider_id = zap_spider.start_spider_by_url(target, True)
162+
spider_id = zap_spider.start_spider_by_url(target)
163163

164164
assert zap.ajaxSpider.status == 'running'
165165

0 commit comments

Comments
 (0)