Skip to content

Commit

Permalink
Simplify response presence logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ps-porpoise authored Dec 13, 2023
1 parent e0185cf commit 9fa67f7
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions Proxy/HTTP/IncorrectContentLength.bambda
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
/**
* Finds responses whose body length do not match their stated Content-Length header.
*
* @author albinowax & PortSwiggerWiener <3
* @author albinowax
**/


if (requestResponse.request().url() != null && requestResponse.hasResponse()) {
HttpResponse response = requestResponse.response();

// Check if Content-Length header is present
String contentLengthHeader = response.headerValue("Content-Length");
if (contentLengthHeader != null) {
try {
int declaredContentLength = Integer.parseInt(contentLengthHeader);
int realContentLength = response.body().length();

// Check for mismatch between declared and actual content length
if (declaredContentLength != realContentLength) {
// Mismatch found, highlight and return true
requestResponse.annotations().setHighlightColor(HighlightColor.YELLOW);
requestResponse.annotations().setNotes("Content-Length mismatch detected");
return true;
}
} catch (NumberFormatException e) {
// Handle potential number format exception
e.printStackTrace();
}
}
if (!requestResponse.hasResponse()) {
return false;
}

// No Content-Length mismatch found or no Content-Length header
return false;
int realContentLength = requestResponse.response().body().length();
int declaredContentLength = Integer.parseInt(requestResponse.response().headerValue("Content-Length"));

return declaredContentLength != realContentLength;

0 comments on commit 9fa67f7

Please sign in to comment.