Skip to content

Commit

Permalink
Merge pull request #61 from GangGreenTemperTatum/ganggreentempertatum…
Browse files Browse the repository at this point in the history
…/FilterAuthenticatedNonBearerTokens-bambda

feat: Bambda to filter authorization values not equal to jwt bearer
  • Loading branch information
ps-porpoise authored Mar 1, 2024
2 parents 36cb075 + 0de5cfe commit f3ca4d3
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Proxy/HTTP/FilterAuthenticatedNonBearerTokens.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Filter when an Authorization header is present, not empty and does not include a traditional bearer token (beginning with "ey")
*
* @author GangGreenTemperTatum (https://github.com/GangGreenTemperTatum)
**/

var configInScopeOnly = true; // If set to true, won't show out-of-scope items
var sessionCookieName = ""; // If given, will look for a cookie with that name.
var sessionCookieValue = ""; // If given, will check if cookie with sessionCookieName has this value.

var request = requestResponse.request();
var response = requestResponse.response();

if (configInScopeOnly && !request.isInScope()) {
return false;
}

if (!requestResponse.hasResponse() || !response.isStatusCodeClass(StatusCodeClass.CLASS_2XX_SUCCESS)) {
return false;
}

var hasAuthHeader = request.hasHeader("Authorization");
var authHeaderValue = hasAuthHeader ? String.valueOf(request.headerValue("Authorization")).toLowerCase() : null;

if (!hasAuthHeader || (authHeaderValue == null || authHeaderValue.isEmpty())) {
return false;
}

var excludeAuthorization =
authHeaderValue.contains("bearer") &&
authHeaderValue.contains("ey");

var sessionCookie = request.headerValue("Cookie") != null &&
!sessionCookieName.isEmpty() &&
request.hasParameter(sessionCookieName, HttpParameterType.COOKIE) &&
(sessionCookieValue.isEmpty() || sessionCookieValue.equals(String.valueOf(request.parameter(sessionCookieName, HttpParameterType.COOKIE).value())));

return !excludeAuthorization || sessionCookie;

0 comments on commit f3ca4d3

Please sign in to comment.