Skip to content

Commit

Permalink
Merge pull request #1992 from akto-api-security/regex_replace_wordlis…
Browse files Browse the repository at this point in the history
…t_fix

handle regex replace for wordlist
  • Loading branch information
ayushaga14 authored Jan 16, 2025
2 parents fd6a0b3 + 44c6cbd commit b38ea96
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions libs/utils/src/main/java/com/akto/test_editor/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,13 @@ public static ExecutorSingleOperationResp modifySampleDataUtil(String operationT
String regex = regexInfo.get("regex");
String replaceWith = regexInfo.get("replace_with");
newPayload = Utils.applyRegexModifier(payload, regex, replaceWith);
} else if (key instanceof String && key != "" && ((String) key).contains("regex_replace")) {
Map<String, Map<String, String>> regexReplace = parseStringToMap((String) key);
String payload = rawApi.getRequest().getBody();
Map<String, String> regexInfo = regexReplace.get("regex_replace");
String regex = regexInfo.get("regex");
String replaceWith = regexInfo.get("replace_with");
newPayload = Utils.applyRegexModifier(payload, regex, replaceWith);
} else {
newPayload = key.toString();
}
Expand Down Expand Up @@ -938,5 +945,34 @@ public static ExecutorSingleOperationResp modifySampleDataUtil(String operationT

}

public static Map<String, Map<String, String>> parseStringToMap(String mapString) {

mapString = mapString.trim();
if (mapString.startsWith("{") && mapString.endsWith("}")) {
mapString = mapString.substring(1, mapString.length() - 1);
}

Map<String, Map<String, String>> resultMap = new HashMap<>();
String[] entries = mapString.split("=", 2);

String outerKey = entries[0].trim();
String innerMapString = entries[1].trim();

innerMapString = innerMapString.substring(1, innerMapString.length() - 1);

Map<String, String> innerMap = new HashMap<>();
String[] innerEntries = innerMapString.split(", ");

for (String innerEntry : innerEntries) {
String[] innerKeyValue = innerEntry.split("=", 2);
String innerKey = innerKeyValue[0].trim();
String innerValue = innerKeyValue[1].trim();
innerMap.put(innerKey, innerValue);
}

resultMap.put(outerKey, innerMap);
return resultMap;
}


}

0 comments on commit b38ea96

Please sign in to comment.