forked from PortSwigger/bambdas
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from intrudir/main
Add getApexMethod bambda
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Extracts the "method" value from either the query string (GET requests) or JSON in the request body (POST requests). | ||
* This avoids dependencies on external libraries. | ||
# Author: Jonathan Conesa | ||
**/ | ||
|
||
if (requestResponse.finalRequest().path().contains("/api/apex/execute")) { | ||
try { | ||
// Check the HTTP method (GET or POST) | ||
String httpMethod = requestResponse.finalRequest().method(); | ||
|
||
if (httpMethod.equalsIgnoreCase("GET")) { | ||
// Extract the full URL | ||
String url = requestResponse.finalRequest().url(); | ||
|
||
// Locate the start of the query string | ||
int queryStartIndex = url.indexOf("?"); | ||
if (queryStartIndex != -1) { | ||
String queryString = url.substring(queryStartIndex + 1); // Extract query string | ||
String[] params = queryString.split("&"); // Split into individual parameters | ||
|
||
for (String param : params) { | ||
if (param.startsWith("method=")) { | ||
// Extract and return the value of the "method" parameter | ||
return param.substring(7); // Skip "method=" | ||
} | ||
} | ||
return "Error: 'method' key not found in query string"; | ||
} else { | ||
return "Error: No query string found in URL"; | ||
} | ||
} else if (httpMethod.equalsIgnoreCase("POST")) { | ||
// Extract the request body as a string | ||
String requestBody = requestResponse.finalRequest().bodyToString().trim(); | ||
|
||
// Ensure the body contains the "method" key | ||
if (requestBody.contains("\"method\":\"")) { | ||
int methodStartIndex = requestBody.indexOf("\"method\":\"") + 10; // Skip past "method":" length | ||
int methodEndIndex = requestBody.indexOf("\"", methodStartIndex); | ||
|
||
// Extract and return the "method" value | ||
return requestBody.substring(methodStartIndex, methodEndIndex); | ||
} else { | ||
return "Error: 'method' key not found in body"; | ||
} | ||
} else { | ||
return "Error: Unsupported HTTP method " + httpMethod; | ||
} | ||
} catch (Exception e) { | ||
// Return error details in case of an exception | ||
return "Error: Exception while processing - " + e.getMessage(); | ||
} | ||
} | ||
|
||
// Return empty string if the request doesn't match the target criteria | ||
return ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
| ||
# SalesForce Custom Column Bambdas | ||
|
||
## GetApexMethod | ||
Extracts the `method` value from calls to `api/apex/execute` when its passed in via query string in GET or JSON in POST. | ||
|
||
![getApexMethod](images/image.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.