Skip to content

Commit

Permalink
Merge pull request #1838 from akto-api-security/hotfix/fix_default_bl…
Browse files Browse the repository at this point in the history
…ock_filter

Fixing default block filter
notshivansh authored Dec 18, 2024
2 parents 487415f + 0026eac commit 206b831
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -2820,16 +2820,49 @@ private static void makeFirstUserAdmin(BackwardCompatibility backwardCompatibili
}

private static void addDefaultAdvancedFilters(BackwardCompatibility backwardCompatibility){
if(backwardCompatibility.getAddDefaultFilters() == 0){
if(backwardCompatibility.getAddDefaultFilters() == 0 || backwardCompatibility.getAddDefaultFilters() < 1734502264){
String contentAllow = "id: DEFAULT_ALLOW_FILTER\nfilter:\n url:\n regex: '.*'";
String contentBlock = "id: DEFAULT_BLOCK_FILTER\nfilter:\n response_code:\n gte: 400";
String contentBlock = "id: DEFAULT_BLOCK_FILTER\n" +
"filter:\n" +
" or:\n" +
" - response_code:\n" +
" gte: 400\n" +
" - response_headers:\n" +
" for_one:\n" +
" key:\n" +
" eq: content-type\n" +
" value:\n" +
" contains_either:\n" +
" - html\n" +
" - text/html\n" +
" - request_headers:\n" +
" for_one:\n" +
" key:\n" +
" eq: host\n" +
" value:\n" +
" regex: .*localhost.*";

if(!DashboardMode.isMetered()){
contentBlock = "id: DEFAULT_BLOCK_FILTER\nfilter:\n response_code:\n gte: 400";
}


AdvancedTrafficFiltersAction action = new AdvancedTrafficFiltersAction();
action.setYamlContent(contentAllow);
action.saveYamlTemplateForTrafficFilters();

action.setYamlContent(contentBlock);
action.saveYamlTemplateForTrafficFilters();
if(backwardCompatibility.getAddDefaultFilters() != 0 && DashboardMode.isMetered()){
Bson defaultFilterQ = Filters.eq(Constants.ID, "DEFAULT_BLOCK_FILTER");
YamlTemplate blockTemplate = AdvancedTrafficFiltersDao.instance.findOne(defaultFilterQ);
if((blockTemplate.getUpdatedAt() - blockTemplate.getCreatedAt()) <= 10){
AdvancedTrafficFiltersDao.instance.deleteAll(defaultFilterQ);
action.setYamlContent(contentBlock);
action.saveYamlTemplateForTrafficFilters();
}
}else{
action.setYamlContent(contentBlock);
action.saveYamlTemplateForTrafficFilters();
}

BackwardCompatibilityDao.instance.updateOne(
Filters.eq("_id", backwardCompatibility.getId()),
Original file line number Diff line number Diff line change
@@ -38,8 +38,9 @@ public static BasicDBList getFilterTemplates(Map<String, FilterConfig> configs){
public static List<Bson> getDbUpdateForTemplate(String content, String userEmail) throws Exception{
try {
String author = userEmail;
int createdAt = Context.now();
int updatedAt = Context.now();
int timeNow = Context.now();
int createdAt = timeNow;
int updatedAt = timeNow;

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

0 comments on commit 206b831

Please sign in to comment.