Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Added fallback decoding for Base64 encoded strings #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,24 @@ public static ArrayList<HttpRequestResponse> importWStalker() {
String[] v = line.split(","); // Format: "base64(request),base64(response),url"

String url = v[3];
Base64Utils b64Decoder = LoggerPlusPlus.montoya.utilities().base64Utils();
HttpService httpService = HttpService.httpService(url);
HttpRequest httpRequest = HttpRequest.httpRequest(httpService, b64Decoder.decode(v[0], Base64DecodingOptions.URL));
HttpResponse httpResponse = HttpResponse.httpResponse(b64Decoder.decode(v[1], Base64DecodingOptions.URL));
Base64Utils b64Decoder = LoggerPlusPlus.montoya.utilities().base64Utils();

// Attempt to decode using standard Base64
ByteArray decodedRequest;
ByteArray decodedResponse;
try {
decodedRequest = b64Decoder.decode(v[0]);
decodedResponse = b64Decoder.decode(v[1]);
} catch (IllegalArgumentException e) {
// If decoding with standard Base64 fails, try URL-safe Base64 decoding
log.warn("Standard Base64 decoding failed, trying URL-safe Base64 decoding");
decodedRequest = b64Decoder.decode(v[0], Base64DecodingOptions.URL);
decodedResponse = b64Decoder.decode(v[1], Base64DecodingOptions.URL);
}

HttpRequest httpRequest = HttpRequest.httpRequest(httpService, decodedRequest);
HttpResponse httpResponse = HttpResponse.httpResponse(decodedResponse);
HttpRequestResponse requestResponse = HttpRequestResponse.httpRequestResponse(httpRequest, httpResponse);

requests.add(requestResponse);
Expand Down