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

feat: Bambda to filter authorization values not equal to jwt bearer #61

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;
Loading