Skip to content

Commit

Permalink
Merge pull request #2081 from akto-api-security/hotfix/stop_graphql_e…
Browse files Browse the repository at this point in the history
…ndpoints_merge

clean code
  • Loading branch information
Ark2307 authored Feb 10, 2025
2 parents bd92fda + d974db9 commit f7b6e0e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public static URLTemplate tryParamteresingUrl(URLStatic newUrl){

int start = newUrl.getUrl().startsWith("http") ? 3 : 0;

if(GraphQLUtils.isGraphQLEndpoint(newUrl.getUrl())) {
if(HttpResponseParams.isGraphQLEndpoint(newUrl.getUrl())) {
return null; // Don't merge GraphQL endpoints
}

Expand Down Expand Up @@ -811,7 +811,7 @@ public static URLTemplate tryMergeUrls(URLStatic dbUrl, URLStatic newUrl) {
SuperType[] newTypes = new SuperType[newTokens.length];
int templatizedStrTokens = 0;

if(GraphQLUtils.isGraphQLEndpoint(dbUrl.getUrl()) || GraphQLUtils.isGraphQLEndpoint(newUrl.getUrl())) {
if(HttpResponseParams.isGraphQLEndpoint(dbUrl.getUrl()) || HttpResponseParams.isGraphQLEndpoint(newUrl.getUrl())) {
return null; // Don't merge GraphQL endpoints
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public static URLTemplate tryParamteresingUrl(URLStatic newUrl){

int start = newUrl.getUrl().startsWith("http") ? 3 : 0;

if(GraphQLUtils.isGraphQLEndpoint(newUrl.getUrl())) {
if(HttpResponseParams.isGraphQLEndpoint(newUrl.getUrl())) {
return null; // Don't merge GraphQL endpoints
}

Expand Down Expand Up @@ -597,7 +597,7 @@ public static URLTemplate tryMergeUrls(URLStatic dbUrl, URLStatic newUrl) {
SuperType[] newTypes = new SuperType[newTokens.length];
int templatizedStrTokens = 0;

if(GraphQLUtils.isGraphQLEndpoint(dbUrl.getUrl()) || GraphQLUtils.isGraphQLEndpoint(newUrl.getUrl())) {
if(HttpResponseParams.isGraphQLEndpoint(dbUrl.getUrl()) || HttpResponseParams.isGraphQLEndpoint(newUrl.getUrl())) {
return null; // Don't merge GraphQL endpoints
}

Expand Down
9 changes: 9 additions & 0 deletions libs/dao/src/main/java/com/akto/dto/HttpResponseParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ public static boolean isGraphql(HttpResponseParams responseParams) {
return isAllowedForParse && requestPayload.contains(QUERY);
}

public static boolean isGraphQLEndpoint(String url) {
for (String keyword : allowedPath) {
if (url.contains(keyword)) {
return true;
}
}
return false;
}

public int getTimeOrNow() {
return getTime() == 0 ? Context.now() : getTime();
}
Expand Down
3 changes: 2 additions & 1 deletion libs/dao/src/main/java/com/akto/dto/type/URLTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.UUID;

import com.akto.dao.context.Context;
import com.akto.dto.HttpResponseParams;
import com.akto.dto.type.SingleTypeInfo.SuperType;
import com.akto.dto.type.URLMethods.Method;

Expand Down Expand Up @@ -66,7 +67,7 @@ public boolean match(String[] url, Method urlMethod) {
String[] thatTokens = url;
if (thatTokens.length != this.tokens.length) return false;

if(Arrays.toString(url).contains("graphql") || Arrays.toString(url).contains("graph")) {
if(HttpResponseParams.isGraphQLEndpoint(Arrays.toString(url))) {
return false;
}

Expand Down
7 changes: 0 additions & 7 deletions libs/utils/src/main/java/com/akto/graphql/GraphQLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,4 @@ public List<OperationDefinition> parseGraphQLRequest(Map requestPayload) {
}
return result;
}

public static boolean isGraphQLEndpoint(String url) {
if(url.contains("graphql") || url.contains("graph")) {
return true;
}
return false;
}
}

0 comments on commit f7b6e0e

Please sign in to comment.