Skip to content
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
18 changes: 15 additions & 3 deletions src/main/java/com/glean/proxy/filters/LegacyRequestFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,23 @@ public HttpResponse clientToProxyRequest(HttpObject httpObject) {
final String[] splitPath = httpRequest.uri().split("/", 4);
if (splitPath.length < 3) {
LOGGER.severe(String.format("Unexpected legacy request format: %s", httpRequest.uri()));
return createBadRequestResponse("Bad Request to URI: " + httpRequest.uri());
}
if (!"webhook".equals(splitPath[2])) {
LOGGER.severe(String.format("Unknown intent: %s", splitPath[2]));
return null;

final String intent = splitPath[2];

boolean isIntentAllowed = switch (intent) {
case "webhook" -> true;
case "api", "rest" -> legacyProxy.isApiIngressAllowed();
default -> false;
};

if (!isIntentAllowed) {
LOGGER.severe(String.format("Unknown or disallowed intent: %s (allowApiIngress=%s)",
intent, legacyProxy.isApiIngressAllowed()));
return createBadRequestResponse("Bad Request to URI: " + httpRequest.uri());
}

final String path = httpRequest.uri();

final String target = legacyProxy.getTargetURL(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public boolean shouldUpgradeProtocol() {
return protocolUpgrade;
}

public boolean isApiIngressAllowed() {
return allowApiIngress;
}

public String getTargetURLForUpgradedProtocol(String pathWithPrefix) {
return String.format(
"%s%s", webhookTarget.replaceFirst("^http://", "https://"), pathWithPrefix);
Expand Down