Skip to content

Commit

Permalink
client: Export Client Map
Browse files Browse the repository at this point in the history
Signed-off-by: kingthorin <[email protected]>
  • Loading branch information
kingthorin committed Jan 6, 2025
1 parent d59041e commit 5588fb8
Show file tree
Hide file tree
Showing 5 changed files with 459 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import org.zaproxy.addon.client.ui.PopupMenuClientHistoryCopy;
import org.zaproxy.addon.client.ui.PopupMenuClientOpenInBrowser;
import org.zaproxy.addon.client.ui.PopupMenuClientShowInSites;
import org.zaproxy.addon.client.ui.PopupMenuExportClientMap;
import org.zaproxy.addon.commonlib.ExtensionCommonlib;
import org.zaproxy.addon.network.ExtensionNetwork;
import org.zaproxy.zap.ZAP;
Expand Down Expand Up @@ -291,6 +292,13 @@ public void hook(ExtensionHook extensionHook) {
.getMainFrame()
.getMainFooterPanel()
.addFooterToolbarRightComponent(pscanStatus.getCountLabel());

extensionHook
.getHookMenu()
.addPopupMenuItem(
new PopupMenuExportClientMap(
Constant.messages.getString("client.tree.popup.export.menu"),
this));
}
}

Expand Down Expand Up @@ -863,4 +871,8 @@ public void sessionModeChanged(Mode mode) {
}
}
}

public ClientMap getClientTree() {
return clientTree;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.zaproxy.addon.client.internal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.AllArgsConstructor;
Expand All @@ -30,12 +31,13 @@

@Getter
@AllArgsConstructor
public class ClientSideComponent {

public class ClientSideComponent implements Comparable<ClientSideComponent> {
public static final String REDIRECT = "Redirect";

public static final String CONTENT_LOADED = "ContentLoaded";

private static final List<String> STORAGE_TYPES =
List.of("Cookies", "localStorage", "sessionStorage");
private final Map<String, String> data;

private String tagName;
Expand All @@ -53,21 +55,29 @@ public ClientSideComponent(JSONObject json) {
data.put(key.toString(), json.get(key).toString());
}

this.tagName = json.getString("tagName");
this.id = json.getString("id");
this.parentUrl = json.getString("url");
this.type = json.getString("type");
this.tagName = json.optString("tagName", "");
this.id = json.optString("id", "");
this.parentUrl = json.optString("url", "");
this.type = json.optString("type", "");
if (json.containsKey("href")) {
this.href = json.getString("href");
} else {
this.href = "";
}
if (json.containsKey("text")) {
this.text = json.getString("text").trim();
} else {
this.text = "";
}
if (json.containsKey("tagType")) {
this.tagType = json.getString("tagType").trim();
} else {
this.tagType = "";
}
if (json.containsKey("formId")) {
this.formId = json.getInt("formId");
} else {
this.formId = Integer.MIN_VALUE;
}
}

Expand Down Expand Up @@ -99,12 +109,7 @@ public boolean isStorageEvent() {
if (type == null) {
return false;
}
switch (type) {
case "Cookies", "localStorage", "sessionStorage":
return true;
default:
return false;
}
return STORAGE_TYPES.contains(this.type);
}

@Override
Expand All @@ -124,4 +129,39 @@ public boolean equals(Object obj) {
&& Objects.equals(tagName, other.tagName)
&& Objects.equals(text, other.text);
}

@Override
public int compareTo(ClientSideComponent other) {
int result = this.getTypeForDisplay().compareTo(other.getTypeForDisplay());
if (result != 0) {
return result;
}
// Types are the same, check next relevant property(ies)
result = this.href.compareTo(other.href);
if (result != 0) {
return result;
}
result = this.text.compareTo(other.text);
if (result != 0) {
return result;
}
result = this.id.compareTo(other.id);
if (result != 0) {
return result;
}
result = this.tagName.compareTo(other.tagName);
if (result != 0) {
return result;
}
result = this.tagType.compareTo(other.tagType);
if (result != 0) {
return result;
}
if (this.formId > other.formId) {
return 1;
} else if (this.formId < other.formId) {
return -1;
}
return 0;
}
}
Loading

0 comments on commit 5588fb8

Please sign in to comment.