2222import java .awt .event .KeyEvent ;
2323import java .nio .charset .StandardCharsets ;
2424import java .util .Base64 ;
25+ import org .apache .commons .httpclient .URI ;
26+ import org .apache .commons .httpclient .URIException ;
2527import org .apache .commons .lang3 .StringUtils ;
2628import org .apache .logging .log4j .LogManager ;
2729import org .apache .logging .log4j .Logger ;
2830import org .parosproxy .paros .core .scanner .Alert ;
2931import org .parosproxy .paros .extension .history .ExtensionHistory ;
3032import org .parosproxy .paros .model .HistoryReference ;
33+ import org .parosproxy .paros .model .SiteNode ;
3134import org .zaproxy .addon .client .ClientUtils ;
3235import org .zaproxy .zap .extension .alert .ExtensionAlert ;
3336import org .zaproxy .zap .utils .Stats ;
3437
3538public 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