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

Add Proxy HTTP filter examples. #6

Merged
merged 3 commits into from
Nov 27, 2023
Merged
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
16 changes: 16 additions & 0 deletions Proxy/HTTP/FilterOnCookieValue.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Filters Proxy HTTP history for requests with a specific Cookie value.
*
* @author LostCoder
**/

if (requestResponse.request().hasParameter("foo", HttpParameterType.COOKIE)) {
var cookieValue = requestResponse
.request()
.parameter("foo", HttpParameterType.COOKIE)
.value();

return cookieValue.contains("1337");
}

return false;
17 changes: 17 additions & 0 deletions Proxy/HTTP/FindJSONresponsesWithIncorrectContentType.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Finds JSON responses with wrong Content-Type
*
* The content is probably json but the content type is not application/json
*
* @author albinowax
**/

var contentType = requestResponse.hasResponse() ? requestResponse.response().headerValue("Content-Type") : null;

if (contentType != null && !contentType.contains("application/json")) {
String body = requestResponse.response().bodyToString().trim();

return body.startsWith( "{" ) || body.startsWith( "[" );
}

return false;
28 changes: 28 additions & 0 deletions Proxy/HTTP/FindRolesWithinJWTClaims.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Find role within JWT claims
*
* @author Trikster
**/

if (!requestResponse.hasResponse())
{
return false;
}

var body = requestResponse.response().bodyToString().trim();

if (requestResponse.response().hasHeader("authorization")) {
var authValue = requestResponse.response().headerValue("authorization");

if (authValue.startsWith("Bearer ey")) {
var tokens = authValue.split("\\.");

if (tokens.length == 3) {
var decodedClaims = utilities().base64Utils().decode(tokens[1], Base64DecodingOptions.URL).toString();

return decodedClaims.toLowerCase().contains("role");
}
}
}

return false;