Skip to content

Commit 4a0e2f2

Browse files
authored
Merge pull request #6418 from thc202/spiderAjax/third-party
spiderAjax: show flexible accesses
2 parents a6c55fc + 3ba8ad7 commit 4a0e2f2

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.parosproxy.paros.model.HistoryReference;
3939
import org.zaproxy.zap.extension.spiderAjax.AjaxSpiderResultsTableModel.ProcessedCellItem;
4040
import org.zaproxy.zap.extension.spiderAjax.SpiderListener.ResourceState;
41+
import org.zaproxy.zap.utils.DisplayUtils;
4142
import org.zaproxy.zap.view.table.HistoryReferencesTable;
4243

4344
@SuppressWarnings("serial")
@@ -119,6 +120,11 @@ private static class ProcessedCellItemIconHighlighter extends AbstractHighlighte
119120
new ImageIcon(
120121
AjaxSpiderResultsTable.class.getResource("/resource/icon/16/149.png"));
121122

123+
/** The icon that indicates the entry is a 3rd party one. */
124+
private static final ImageIcon THIRD_PARTY_ICON =
125+
DisplayUtils.getScaledIcon(
126+
AjaxSpiderResultsTable.class.getResource("/resource/icon/16/154.png"));
127+
122128
private final int columnIndex;
123129

124130
public ProcessedCellItemIconHighlighter(final int columnIndex) {
@@ -129,23 +135,26 @@ public ProcessedCellItemIconHighlighter(final int columnIndex) {
129135
protected Component doHighlight(Component component, ComponentAdapter adapter) {
130136
ProcessedCellItem cell = (ProcessedCellItem) adapter.getValue(columnIndex);
131137

132-
boolean processed = cell.getState() == ResourceState.PROCESSED;
133-
Icon icon = getProcessedIcon(processed);
134-
if (component instanceof IconAware) {
135-
((IconAware) component).setIcon(icon);
136-
} else if (component instanceof JLabel) {
137-
((JLabel) component).setIcon(icon);
138+
Icon icon = getProcessedIcon(cell.getState());
139+
if (component instanceof IconAware iconAware) {
140+
iconAware.setIcon(icon);
141+
} else if (component instanceof JLabel label) {
142+
label.setIcon(icon);
138143
}
139144

140-
if (component instanceof JLabel) {
141-
((JLabel) component).setText(processed ? "" : cell.getLabel());
145+
if (component instanceof JLabel label) {
146+
label.setText(cell.getState() == ResourceState.PROCESSED ? "" : cell.getLabel());
142147
}
143148

144149
return component;
145150
}
146151

147-
private static Icon getProcessedIcon(final boolean processed) {
148-
return processed ? PROCESSED_ICON : NOT_PROCESSED_ICON;
152+
private static Icon getProcessedIcon(ResourceState state) {
153+
return switch (state) {
154+
case PROCESSED -> PROCESSED_ICON;
155+
case THIRD_PARTY -> THIRD_PARTY_ICON;
156+
default -> NOT_PROCESSED_ICON;
157+
};
149158
}
150159

151160
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public class AjaxSpiderResultsTableModel
8585
addState(statesMap, ResourceState.OUT_OF_SCOPE, "outofscope");
8686
addState(statesMap, ResourceState.EXCLUDED, "excluded");
8787
addState(statesMap, ResourceState.IO_ERROR, "ioerror");
88+
addState(statesMap, ResourceState.THIRD_PARTY, "thirdparty");
8889
}
8990

9091
public AjaxSpiderResultsTableModel() {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ enum ResourceState {
2929
OUT_OF_SCOPE,
3030
OUT_OF_CONTEXT,
3131
EXCLUDED,
32-
IO_ERROR
32+
IO_ERROR,
33+
THIRD_PARTY,
3334
}
3435

3536
void spiderStarted();

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -408,27 +408,18 @@ public void handleMessage(HttpMessageHandlerContext ctx, HttpMessage httpMessage
408408

409409
ResourceState state =
410410
checkState(httpMessage.getRequestHeader().getURI().getEscapedURI());
411-
boolean processed = state == ResourceState.PROCESSED;
412411

413412
if (!ctx.isFromClient()) {
414-
if (target.getOptions().getScopeCheck() == ScopeCheck.STRICT) {
415-
notifyMessage(
416-
httpMessage,
417-
HistoryReference.TYPE_SPIDER_AJAX,
418-
getResourceState(httpMessage));
419-
return;
420-
}
421-
422413
notifyMessage(
423414
httpMessage,
424-
processed
425-
? HistoryReference.TYPE_SPIDER_AJAX
426-
: HistoryReference.TYPE_SPIDER_AJAX_TEMPORARY,
427-
httpMessage.isResponseFromTargetHost() ? state : ResourceState.IO_ERROR);
415+
HistoryReference.TYPE_SPIDER_AJAX,
416+
target.getOptions().getScopeCheck() == ScopeCheck.STRICT
417+
? getResourceState(httpMessage)
418+
: getResourceStateFlexible(httpMessage, state));
428419
return;
429420
}
430421

431-
if (!processed) {
422+
if (state != ResourceState.PROCESSED) {
432423
if (target.getOptions().getScopeCheck() == ScopeCheck.STRICT) {
433424
setOutOfScopeResponse(httpMessage);
434425
notifyMessage(httpMessage, HistoryReference.TYPE_SPIDER_AJAX_TEMPORARY, state);
@@ -462,6 +453,17 @@ private ResourceState getResourceState(HttpMessage httpMessage) {
462453
return ResourceState.PROCESSED;
463454
}
464455

456+
private ResourceState getResourceStateFlexible(
457+
HttpMessage httpMessage, ResourceState state) {
458+
if (!httpMessage.isResponseFromTargetHost()) {
459+
return ResourceState.IO_ERROR;
460+
}
461+
if (state != ResourceState.PROCESSED) {
462+
return ResourceState.THIRD_PARTY;
463+
}
464+
return state;
465+
}
466+
465467
public void setAllowAll(boolean allow) {
466468
this.allowAll = allow;
467469
}
@@ -476,7 +478,7 @@ private void notifyMessage(
476478
}
477479

478480
HistoryReference historyRef = new HistoryReference(session, historyType, httpMessage);
479-
if (state == ResourceState.PROCESSED) {
481+
if (state == ResourceState.PROCESSED || state == ResourceState.THIRD_PARTY) {
480482
historyRef.setCustomIcon("/resource/icon/10/spiderAjax.png", true);
481483
session.getSiteTree().addPath(historyRef, httpMessage);
482484
}

addOns/spiderAjax/src/main/resources/org/zaproxy/zap/extension/spiderAjax/resources/Messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ spiderajax.panel.table.cell.ioerror = I/O Error
218218
spiderajax.panel.table.cell.outofcontext = Out of Context
219219
spiderajax.panel.table.cell.outofscope = Out of Scope
220220
spiderajax.panel.table.cell.processed = Processed
221+
spiderajax.panel.table.cell.thirdparty = 3rd Party
221222
spiderajax.panel.table.header.processed = Processed
222223
spiderajax.panel.title = AJAX Spider
223224

0 commit comments

Comments
 (0)