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

Bambda to Filter Authenticated Requests #59

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Changes from 2 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
48 changes: 48 additions & 0 deletions Proxy/HTTP/FilterAuthenticated.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Filters authenticated 200 OK requests in Proxy HTTP history. See four config values below.
*
* @author joe-ds (https://github.com/joe-ds)
**/

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

if (!response.isStatusCodeClass(StatusCodeClass.CLASS_2XX_SUCCESS) || !requestResponse.hasResponse()) {
joe-ds marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

var configNoFilter = true; // If set to false, won't show JS, GIF, JPG, PNG, CSS.
var configNotInScopeOnly = true; // If set to false, 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.
joe-ds marked this conversation as resolved.
Show resolved Hide resolved

var inScope = request.isInScope();
joe-ds marked this conversation as resolved.
Show resolved Hide resolved
var authHeader = request.hasHeader("Authorization");

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

var path = requestResponse.request().pathWithoutQuery().toLowerCase();
joe-ds marked this conversation as resolved.
Show resolved Hide resolved
var mimeType = requestResponse.mimeType();
var filterDenyList = mimeType != MimeType.CSS
&& mimeType != MimeType.IMAGE_UNKNOWN
&& mimeType != MimeType.IMAGE_JPEG
&& mimeType != MimeType.IMAGE_GIF
&& mimeType != MimeType.IMAGE_PNG
&& mimeType != MimeType.IMAGE_BMP
&& mimeType != MimeType.IMAGE_TIFF
&& mimeType != MimeType.UNRECOGNIZED
&& mimeType != MimeType.SOUND
&& mimeType != MimeType.VIDEO
&& mimeType != MimeType.FONT_WOFF
&& mimeType != MimeType.FONT_WOFF2
&& mimeType != MimeType.APPLICATION_UNKNOWN
&& !path.endsWith(".js")
&& !path.endsWith(".gif")
&& !path.endsWith(".jpg")
&& !path.endsWith(".png")
&& !path.endsWith(".css");

return (authHeader || sessionCookie) && (configNoFilter || filterDenyList) && (configNotInScopeOnly || inScope);