Skip to content

Commit

Permalink
Merge pull request #1803 from akto-api-security/hotfix_json_payload_v…
Browse files Browse the repository at this point in the history
…alidation

fix json validation
  • Loading branch information
notshivansh authored Dec 6, 2024
2 parents 4df198a + aae73e5 commit 1861331
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions libs/utils/src/main/java/com/akto/test_editor/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ public static double structureMatch(RawApi orig, RawApi cur) {

public static double calcStructureMatchPercentage(String payload, String compareWithPayload) {

boolean isOrigPAyloadJson = isJsonPayload(payload);
boolean isCurPAyloadJson = isJsonPayload(compareWithPayload);
boolean isOrigPAyloadJson = isValidJson(payload);
boolean isCurPAyloadJson = isValidJson(compareWithPayload);
if (!isOrigPAyloadJson && !isCurPAyloadJson) {
return 100;
}
Expand Down Expand Up @@ -478,6 +478,18 @@ public static boolean isJsonPayload(String payload) {
return true;
}

public static boolean isValidJson(String payload) {
try {
if (payload.length() == 0) {
return false;
}
mapper.readTree(payload);
return true;
} catch (Exception e) {
return false;
}
}

public static UrlModifierPayload fetchUrlModifyPayload(String payload) {
UrlModifierPayload urlModifierPayload = null;
try {
Expand Down

0 comments on commit 1861331

Please sign in to comment.