Skip to content

Commit 206b831

Browse files
authored
Merge pull request #1838 from akto-api-security/hotfix/fix_default_block_filter
Fixing default block filter
2 parents 487415f + 0026eac commit 206b831

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,16 +2820,49 @@ private static void makeFirstUserAdmin(BackwardCompatibility backwardCompatibili
28202820
}
28212821

28222822
private static void addDefaultAdvancedFilters(BackwardCompatibility backwardCompatibility){
2823-
if(backwardCompatibility.getAddDefaultFilters() == 0){
2823+
if(backwardCompatibility.getAddDefaultFilters() == 0 || backwardCompatibility.getAddDefaultFilters() < 1734502264){
28242824
String contentAllow = "id: DEFAULT_ALLOW_FILTER\nfilter:\n url:\n regex: '.*'";
2825-
String contentBlock = "id: DEFAULT_BLOCK_FILTER\nfilter:\n response_code:\n gte: 400";
2825+
String contentBlock = "id: DEFAULT_BLOCK_FILTER\n" +
2826+
"filter:\n" +
2827+
" or:\n" +
2828+
" - response_code:\n" +
2829+
" gte: 400\n" +
2830+
" - response_headers:\n" +
2831+
" for_one:\n" +
2832+
" key:\n" +
2833+
" eq: content-type\n" +
2834+
" value:\n" +
2835+
" contains_either:\n" +
2836+
" - html\n" +
2837+
" - text/html\n" +
2838+
" - request_headers:\n" +
2839+
" for_one:\n" +
2840+
" key:\n" +
2841+
" eq: host\n" +
2842+
" value:\n" +
2843+
" regex: .*localhost.*";
2844+
2845+
if(!DashboardMode.isMetered()){
2846+
contentBlock = "id: DEFAULT_BLOCK_FILTER\nfilter:\n response_code:\n gte: 400";
2847+
}
2848+
28262849

28272850
AdvancedTrafficFiltersAction action = new AdvancedTrafficFiltersAction();
28282851
action.setYamlContent(contentAllow);
28292852
action.saveYamlTemplateForTrafficFilters();
28302853

2831-
action.setYamlContent(contentBlock);
2832-
action.saveYamlTemplateForTrafficFilters();
2854+
if(backwardCompatibility.getAddDefaultFilters() != 0 && DashboardMode.isMetered()){
2855+
Bson defaultFilterQ = Filters.eq(Constants.ID, "DEFAULT_BLOCK_FILTER");
2856+
YamlTemplate blockTemplate = AdvancedTrafficFiltersDao.instance.findOne(defaultFilterQ);
2857+
if((blockTemplate.getUpdatedAt() - blockTemplate.getCreatedAt()) <= 10){
2858+
AdvancedTrafficFiltersDao.instance.deleteAll(defaultFilterQ);
2859+
action.setYamlContent(contentBlock);
2860+
action.saveYamlTemplateForTrafficFilters();
2861+
}
2862+
}else{
2863+
action.setYamlContent(contentBlock);
2864+
action.saveYamlTemplateForTrafficFilters();
2865+
}
28332866

28342867
BackwardCompatibilityDao.instance.updateOne(
28352868
Filters.eq("_id", backwardCompatibility.getId()),

apps/dashboard/src/main/java/com/akto/utils/TrafficFilterUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ public static BasicDBList getFilterTemplates(Map<String, FilterConfig> configs){
3838
public static List<Bson> getDbUpdateForTemplate(String content, String userEmail) throws Exception{
3939
try {
4040
String author = userEmail;
41-
int createdAt = Context.now();
42-
int updatedAt = Context.now();
41+
int timeNow = Context.now();
42+
int createdAt = timeNow;
43+
int updatedAt = timeNow;
4344

4445
List<Bson> updates = new ArrayList<>(
4546
Arrays.asList(

0 commit comments

Comments
 (0)