Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions tool/src/main/java/org/zaproxy/addon/migt/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -894,16 +894,6 @@ private void setup_tab_track() {
trackContainer.add(lblTrack, gbc);

txtScript = new JTextArea();
//rimuovere dopo
txtScript.setText("open | http://relying-party.org:8001/oidc/rp/landing |\n" +
"click | xpath=/html/body/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/span[2]/a |\n" +
"click | xpath=/html/body/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/span[2]/div/ul/li[2]/a |\n" +
"type | id=id_username | user\n" +
"type | id=id_password | oidcuser\n" +
"click | xpath=/html/body/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div[2]/div[1]/form/fieldset/div/div/div/div[3]/button/span[2] |\n" +
"click | id=agree |\n" +
"click | xpath=/html/body/div[2]/div/div/div/div/div/div/div/div/div/a |\n" +
"wait | 1000");

gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
Expand Down
58 changes: 34 additions & 24 deletions tool/src/main/java/org/zaproxy/addon/migt/ReqResPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class ReqResPanel extends JPanel {
private final JTextPane textPane;
private static final int MAX_LINE_LENGTH = 500;
private static final int MAX_LINE_LENGTH = 100;
private boolean isHexView = false;
private HTTPReqRes displayedMsg;
public JButton toggleButton;
Expand Down Expand Up @@ -47,15 +47,20 @@ public void setMessage(HTTPReqRes message, boolean isRequest) throws HttpMalform
private String wrapText(String text, int maxLineLength) {
if (text == null) return "";
StringBuilder wrappedText = new StringBuilder();
int start = 0;
while (start < text.length()) {
int end = Math.min(start + maxLineLength, text.length());
wrappedText.append(text, start, end).append("\n");
start = end;
String[] lines = text.split("\r?\n");

for (String line : lines) {
while (line.length() > maxLineLength) {
wrappedText.append(line, 0, maxLineLength).append("\n");
line = line.substring(maxLineLength);
}
wrappedText.append(line).append("\n");
}

return wrappedText.toString();
}


private String highlightKeywords(String text) {
String[] keywords = {"Host", "User-Agent", "Accept", "Connection", "Upgrade-Insecure-Requests", "Priority", "Accept-Language",
"Date",
Expand All @@ -79,25 +84,29 @@ private void toggleView() {
SwingUtilities.invokeLater(() -> {
StringBuilder sb = new StringBuilder("<html><body style='font-family:monospace;'>");

if (displayedMsg.isRequest) {
sb.append("<b>Request:</b><br><pre>");
sb.append(isHexView ? wrapHexText(convertToHex(displayedMsg.Req_header), 100) : highlightKeywords(wrapText(displayedMsg.Req_header, MAX_LINE_LENGTH)));


if (displayedMsg.Req_body != null) {
sb.append(isHexView ? wrapHexText(convertToHex(displayedMsg.Req_body), 100) : wrapText(displayedMsg.Req_body, MAX_LINE_LENGTH));

}
} else {
sb.append("<b>Response:</b><br><pre>");
sb.append(isHexView ? wrapHexText(convertToHex(displayedMsg.Res_header), 100) : highlightKeywords(wrapText(displayedMsg.Res_header, MAX_LINE_LENGTH)));


if (displayedMsg.Res_body != null) {
sb.append(isHexView ? wrapHexText(convertToHex(displayedMsg.Res_body), 100) : wrapText(displayedMsg.Res_body, MAX_LINE_LENGTH));

}
// Request
sb.append("<b>Request:</b><br><pre>");
sb.append(isHexView
? wrapHexText(convertToHex(displayedMsg.Req_header), 100)
: highlightKeywords(wrapText(displayedMsg.Req_header, MAX_LINE_LENGTH)));
if (displayedMsg.Req_body != null) {
sb.append(isHexView
? wrapHexText(convertToHex(displayedMsg.Req_body), 100)
: wrapText(displayedMsg.Req_body, MAX_LINE_LENGTH));
}
sb.append("</pre><br>");

// Response Section
sb.append("<b>Response:</b><br><pre>");
sb.append(isHexView
? wrapHexText(convertToHex(displayedMsg.Res_header), 100)
: highlightKeywords(wrapText(displayedMsg.Res_header, MAX_LINE_LENGTH)));
if (displayedMsg.Res_body != null) {
sb.append(isHexView
? wrapHexText(convertToHex(displayedMsg.Res_body), 100)
: wrapText(displayedMsg.Res_body, MAX_LINE_LENGTH));
}
sb.append("</pre>");

sb.append("</body></html>");
textPane.setText(sb.toString());
Expand All @@ -106,6 +115,7 @@ private void toggleView() {
});
}


private String wrapHexText(String hexText, int maxLineLength) {
StringBuilder wrappedText = new StringBuilder();
int currentLineLength = 0;
Expand Down
7 changes: 0 additions & 7 deletions tool/src/main/java/org/zaproxy/addon/migt/ZAPextender.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ public boolean onHttpRequestSend(HttpMessage msg) {
synchronized (mainPane.interceptedMessages) {

try {
getView().getOutputPanel().append(
"\n\n" + mainPane.interceptedMessages.get(mainPane.interceptedMessages.size() - 1).getHeadersString(true) +
"\n\n" + new String(mainPane.interceptedMessages.get(mainPane.interceptedMessages.size() - 1).getBody(true)));


mainPane.interceptedMessages.add(new HTTPReqRes(msg, messageIsRequest, msg.getHistoryRef().getHistoryId()));

Expand Down Expand Up @@ -276,9 +272,6 @@ public boolean onHttpResponseReceive(HttpMessage msg) {
try {

mainPane.interceptedMessages.add(new HTTPReqRes(msg, messageIsRequest, msg.getHistoryRef().getHistoryId()));
getView().getOutputPanel().append(
"\n\n" + mainPane.interceptedMessages.get(mainPane.interceptedMessages.size() - 1).getHeadersString(false) +
"\n\n" + new String(mainPane.interceptedMessages.get(mainPane.interceptedMessages.size() - 1).getBody(true)));
if (mainPane.defaultSession != null) {
mainPane.defaultSession.addMessage(msg, mainPane.FILTERING);
}
Expand Down
Loading