Skip to content

Commit f903877

Browse files
authored
Merge pull request #6870 from psiinon/spider/stats
Client and AJAX spider stats
2 parents 021aadd + 476a83e commit f903877

File tree

10 files changed

+25
-4
lines changed

10 files changed

+25
-4
lines changed

addOns/callhome/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
7-
7+
### Added
8+
- AJAX Spider stats to telemetry.
89

910
## [0.16.0] - 2025-10-22
1011
### Added

addOns/callhome/src/main/java/org/zaproxy/addon/callhome/ExtensionCallHome.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ public boolean test(Entry<String, Long> t) {
327327
|| key.startsWith("stats.selenium.")
328328
|| key.startsWith("stats.sequence.")
329329
|| key.startsWith("stats.spider.")
330+
|| key.startsWith("stats.spiderAjax.")
330331
|| key.startsWith("stats.tech.")
331332
|| key.startsWith("stats.ui.")
332333
|| key.startsWith("stats.websockets.")

addOns/client/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
- Add optional parameters for the Client Spider API action `scan`:
99
- `numberOfBrowsers` - control concurrency (number of browser windows).
1010
- `scopeCheck` - select Scope Check (Flexible or Strict).
11+
- Spider stats.
1112

1213
## [0.17.0] - 2025-09-02
1314
### Added

addOns/client/src/main/java/org/zaproxy/addon/client/spider/ClientSpider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ public void run() {
249249
if (options.getMaxDuration() > 0) {
250250
maxTime = startTime + TimeUnit.MINUTES.toMillis(options.getMaxDuration());
251251
}
252+
Stats.incCounter("stats.client.spider.started");
252253
if (user != null) {
254+
Stats.incCounter("stats.client.spider.started.user");
253255
synchronized (this.extClient.getAuthenticationHandlers()) {
254256
this.extClient
255257
.getAuthenticationHandlers()
@@ -662,6 +664,7 @@ private void finished() {
662664
listener.scanFinshed(scanId, displayName);
663665
}
664666

667+
Stats.incCounter("stats.client.spider.time", timeTaken);
665668
Stats.incCounter("stats.client.spider.urls", crawledUrls.size());
666669
Stats.incCounter(
667670
"stats.client.spider.nodes", addedNodesModel.getRowCount() + contentLoaded);

addOns/spiderAjax/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
7+
### Added
8+
- Spider stats.
9+
710
### Fixed
811
- Correctly validate browser IDs.
912

addOns/spiderAjax/src/main/java/org/zaproxy/zap/extension/spiderAjax/SpiderThread.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import org.zaproxy.zap.model.ScanEventPublisher;
6969
import org.zaproxy.zap.network.HttpResponseBody;
7070
import org.zaproxy.zap.users.User;
71+
import org.zaproxy.zap.utils.Stats;
7172

7273
public class SpiderThread implements Runnable {
7374

@@ -92,6 +93,7 @@ public class SpiderThread implements Runnable {
9293
private boolean running;
9394
private final Session session;
9495
private static final Logger LOGGER = LogManager.getLogger(SpiderThread.class);
96+
private long startTime;
9597

9698
private HttpResponseHeader outOfScopeResponseHeader;
9799
private HttpResponseBody outOfScopeResponseBody;
@@ -339,16 +341,19 @@ public void run() {
339341
LOGGER.info(
340342
"Running Crawljax (with {}): {}", target.getOptions().getBrowserId(), displayName);
341343
this.running = true;
344+
this.startTime = System.currentTimeMillis();
342345
notifyListenersSpiderStarted();
343346
SpiderEventPublisher.publishScanEvent(
344347
ScanEventPublisher.SCAN_STARTED_EVENT,
345348
0,
346349
this.target.toTarget(),
347350
target.getStartUri().toString(),
348351
this.target.getUser());
352+
Stats.incCounter("stats.spiderAjax.started");
349353

350354
User user = target.getUser();
351355
if (user != null) {
356+
Stats.incCounter("stats.spiderAjax.started.user");
352357
for (AuthenticationHandler ah : extension.getAuthenticationHandlers()) {
353358
if (ah.enableAuthentication(user)) {
354359
authHandler = ah;
@@ -376,6 +381,7 @@ public void run() {
376381
LOGGER.error(e, e);
377382
} finally {
378383
this.running = false;
384+
Stats.incCounter("stats.spiderAjax.time", System.currentTimeMillis() - this.startTime);
379385
LOGGER.info("Stopping proxy...");
380386
stopProxy();
381387
LOGGER.info("Proxy stopped.");
@@ -440,6 +446,7 @@ public void handleMessage(HttpMessageHandlerContext ctx, HttpMessage httpMessage
440446
checkState(httpMessage.getRequestHeader().getURI().getEscapedURI());
441447

442448
if (!ctx.isFromClient()) {
449+
Stats.incCounter("stats.spiderAjax.urls.added");
443450
notifyMessage(
444451
httpMessage,
445452
HistoryReference.TYPE_SPIDER_AJAX,

addOns/spiderAjax/src/main/java/org/zaproxy/zap/extension/spiderAjax/automation/AjaxSpiderJob.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ public void runJob(AutomationEnvironment env, AutomationProgress progress) {
353353
this.sleep(500);
354354

355355
numUrlsFound = listener.getMessagesFound();
356+
// Should remove this at some point, but its almost certainly being used by existing AF
357+
// jobs
356358
Stats.incCounter("spiderAjax.urls.added", numUrlsFound - lastCount);
357359
lastCount = numUrlsFound;
358360

addOns/spiderAjax/src/main/javahelp/org/zaproxy/zap/extension/spiderAjax/resources/help/contents/automation.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <H2>Job: spiderAjax</H2>
5151
tests:
5252
- name: 'At least 100 URLs found' # String: Name of the test, default: statistic + operator + value
5353
type: 'stats' # String: Type of test, only 'stats' is supported for now
54-
statistic: 'spiderAjax.urls.added' # String: Name of an integer / long statistic, currently supported: 'spiderAjax.urls.added'
54+
statistic: 'stats.spiderAjax.urls.added' # String: Name of an integer / long statistic, currently supported: 'stats.spiderAjax.urls.added'
5555
operator: '&gt;=' # String ['==', '!=', '&gt;=', '&gt;', '&lt;', '&lt;=']: Operator used for testing
5656
value: 100 # Int: Change this to the number of URLs you expect to find
5757
onFail: 'info' # String [warn, error, info]: Change this to 'warn' or 'error' for the test to take effect
@@ -63,5 +63,8 @@ <H2>Job: spiderAjax</H2>
6363
rule installed and enabled. If either of those things are not done then the ajax spider will always run and a warning output.
6464
If they are both done and no "Modern Web Application" alert is raised then the assumption is made that this is a tradition app
6565
and therefore the ajax spider is not needed.
66+
67+
Previously the statistic "spiderAjax.urls.started" was specified. This is no longer recommended and will be removed at some point in the future.
68+
6669
</BODY>
6770
</HTML>

addOns/spiderAjax/src/main/resources/org/zaproxy/zap/extension/spiderAjax/resources/spiderAjax-max.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
tests:
2525
- name: 'At least X URLs found' # String: Name of the test, default: statistic + operator + value
2626
type: 'stats' # String: Type of test, only 'stats' is supported for now
27-
statistic: 'spiderAjax.urls.added' # String: Name of an integer / long statistic, currently supported: 'spiderAjax.urls.added'
27+
statistic: 'stats.spiderAjax.urls.added' # String: Name of an integer / long statistic, currently supported: 'stats.spiderAjax.urls.added'
2828
operator: '>=' # String ['==', '!=', '>=', '>', '<', '<=']: Operator used for testing
2929
value: 100 # Int: Change this to the number of URLs you expect to find
3030
onFail: 'info' # String [warn, error, info]: Change this to 'warn' or 'error' for the test to take effect

addOns/spiderAjax/src/main/resources/org/zaproxy/zap/extension/spiderAjax/resources/spiderAjax-min.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
tests:
1212
- name: 'At least X URLs found' # String: Name of the test, default: statistic + operator + value
1313
type: 'stats' # String: Type of test, only 'stats' is supported for now
14-
statistic: 'spiderAjax.urls.added' # String: Name of an integer / long statistic, currently supported: 'spiderAjax.urls.added'
14+
statistic: 'stats.spiderAjax.urls.added' # String: Name of an integer / long statistic, currently supported: 'stats.spiderAjax.urls.added'
1515
operator: '>=' # String ['==', '!=', '>=', '>', '<', '<=']: Operator used for testing
1616
value: 100 # Int: Change this to the number of URLs you expect to find
1717
onFail: 'info' # String [warn, error, info]: Change this to 'warn' or 'error' for the test to take effect

0 commit comments

Comments
 (0)