Skip to content

Commit

Permalink
Merge pull request #1367 from akto-api-security/hotfix/api_groups_count
Browse files Browse the repository at this point in the history
use host header filter for counting apis in api groups
  • Loading branch information
avneesh-akto authored Aug 19, 2024
2 parents 105cdd2 + 2cbe5fc commit 1414e1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ public List<ApiCollection> fillApiCollectionsUrlCount(List<ApiCollection> apiCol
apiCollection.setUrlsCount(count);
} else if(ApiCollection.Type.API_GROUP.equals(apiCollection.getType())){
if (count == null) {
count = SingleTypeInfoDao.instance.countEndpoints(Filters.in(SingleTypeInfo._COLLECTION_IDS, apiCollectionId));
List<Bson> filters = SingleTypeInfoDao.filterForHostHostHeaderRaw();
filters.add(Filters.in(SingleTypeInfo._COLLECTION_IDS, apiCollectionId));
count = (int) SingleTypeInfoDao.instance.count(
Filters.and(filters)
);
}
apiCollection.setUrlsCount(count);
} else {
Expand Down
7 changes: 6 additions & 1 deletion libs/dao/src/main/java/com/akto/dao/SingleTypeInfoDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,18 @@ public static Bson filterForSTIUsingURL(int apiCollectionId, String url, URLMeth
);
}

public static Bson filterForHostHeader(int apiCollectionId, boolean useApiCollectionId) {
public static List<Bson> filterForHostHostHeaderRaw() {
List<Bson> filters = new ArrayList<>();
filters.add(Filters.eq(SingleTypeInfo._RESPONSE_CODE, -1));
filters.add(Filters.eq(SingleTypeInfo._IS_HEADER, true));
filters.add(Filters.eq(SingleTypeInfo._PARAM, "host"));
filters.add(Filters.eq(SingleTypeInfo.SUB_TYPE, SingleTypeInfo.GENERIC.getName()));

return filters;
}

public static Bson filterForHostHeader(int apiCollectionId, boolean useApiCollectionId) {
List<Bson> filters = filterForHostHostHeaderRaw();
if (useApiCollectionId) filters.add(Filters.eq(SingleTypeInfo._API_COLLECTION_ID, apiCollectionId));

return Filters.and(filters);
Expand Down

0 comments on commit 1414e1f

Please sign in to comment.