Skip to content

Commit 8d07aa3

Browse files
committed
client: use Sites tree for history references
Change the passive scan helper to search the Sites tree for the history references as it is less likely of missing the existing ones. Signed-off-by: thc202 <thc202@gmail.com>
1 parent 12a02cb commit 8d07aa3

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

addOns/client/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99

1010
### Changed
1111
- Updated Chrome and Firefox extensions to v0.1.5.
12+
- Reduce warnings when passive scanning.
1213

1314
### Fixed
1415
- Error logs to always include stack trace.

addOns/client/src/main/java/org/zaproxy/addon/client/pscan/ClientPassiveScanHelper.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@
2222
import java.awt.event.KeyEvent;
2323
import java.nio.charset.StandardCharsets;
2424
import java.util.Base64;
25+
import org.apache.commons.httpclient.URI;
26+
import org.apache.commons.httpclient.URIException;
2527
import org.apache.commons.lang3.StringUtils;
2628
import org.apache.logging.log4j.LogManager;
2729
import org.apache.logging.log4j.Logger;
2830
import org.parosproxy.paros.core.scanner.Alert;
2931
import org.parosproxy.paros.extension.history.ExtensionHistory;
3032
import org.parosproxy.paros.model.HistoryReference;
33+
import org.parosproxy.paros.model.SiteNode;
3134
import org.zaproxy.addon.client.ClientUtils;
3235
import org.zaproxy.zap.extension.alert.ExtensionAlert;
3336
import org.zaproxy.zap.utils.Stats;
3437

3538
public class ClientPassiveScanHelper {
3639

3740
private static final Logger LOGGER = LogManager.getLogger(ClientPassiveScanHelper.class);
38-
private static final int MAX_HREFS_TO_CHECK = 1000;
3941
private ExtensionAlert extAlert;
4042
private ExtensionHistory extHistory;
4143

@@ -46,21 +48,20 @@ public ClientPassiveScanHelper(ExtensionAlert extAlert, ExtensionHistory extHist
4648

4749
public HistoryReference findHistoryRef(String url) {
4850
url = ClientUtils.stripUrlFragment(url);
49-
int lastId = extHistory.getLastHistoryId();
5051

51-
// We don't expect to have to go too far back..
52-
int limit = Math.max(lastId - MAX_HREFS_TO_CHECK, 0);
53-
LOGGER.debug("Searching for history reference for {}", url);
54-
for (int i = lastId; i >= limit; i--) {
55-
HistoryReference hr = extHistory.getHistoryReference(i);
56-
if (hr != null && url.equals(hr.getURI().toString())) {
57-
LOGGER.debug("Found history reference {} for {}", hr.getHistoryId(), url);
52+
try {
53+
SiteNode node =
54+
extHistory.getModel().getSession().getSiteTree().findNode(new URI(url, true));
55+
if (node != null) {
56+
HistoryReference hr = node.getHistoryReference();
5857
Stats.incCounter("stats.client.pscan.href.found");
58+
LOGGER.debug("Found history reference {} for {}", hr.getHistoryId(), url);
5959
return hr;
6060
}
61+
} catch (URIException e) {
62+
LOGGER.warn("Failed to create URI from: {} Cause: {}", url, e.getMessage());
6163
}
62-
// Include the limit in case we change it in the future
63-
Stats.incCounter("stats.client.pscan.href.missing." + MAX_HREFS_TO_CHECK);
64+
Stats.incCounter("stats.client.pscan.href.missing");
6465
return null;
6566
}
6667

0 commit comments

Comments
 (0)