-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1714 from akto-api-security/hotfix/fix_payload_re…
…place_in_array Fixing replace body in test roles
- Loading branch information
Showing
8 changed files
with
116 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.akto.dto.test_editor; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import com.mongodb.BasicDBList; | ||
import com.mongodb.BasicDBObject; | ||
|
||
public class Util { | ||
public static boolean modifyValueInPayload(Object obj, String parentKey, String queryKey, Object queryVal){ | ||
boolean res = false; | ||
if (obj instanceof BasicDBObject) { | ||
BasicDBObject basicDBObject = (BasicDBObject) obj; | ||
|
||
Set<String> keySet = basicDBObject.keySet(); | ||
|
||
for(String key: keySet) { | ||
if (key == null) { | ||
continue; | ||
} | ||
Object value = basicDBObject.get(key); | ||
|
||
if (!( (value instanceof BasicDBObject) || (value instanceof BasicDBList) )) { | ||
if (key.equalsIgnoreCase(queryKey)) { | ||
basicDBObject.remove(key); | ||
basicDBObject.put(queryKey, queryVal); | ||
return true; | ||
} | ||
} | ||
|
||
if (value instanceof BasicDBList) { | ||
BasicDBList valList = (BasicDBList) value; | ||
if (valList.size() == 0 && key.equalsIgnoreCase(queryKey)) { | ||
List<Object> queryList = Collections.singletonList(queryVal); | ||
basicDBObject.remove(key); | ||
basicDBObject.put(queryKey, queryList); | ||
return true; | ||
} else if (valList.size() > 0 && !( (valList.get(0) instanceof BasicDBObject) || (valList.get(0) instanceof BasicDBList) ) && key.equalsIgnoreCase(queryKey)) { | ||
List<Object> queryList = Collections.singletonList(queryVal); | ||
basicDBObject.remove(key); | ||
basicDBObject.put(queryKey, queryList); | ||
return true; | ||
} | ||
} | ||
|
||
res = modifyValueInPayload(value, key, queryKey, queryVal); | ||
if (res) { | ||
break; | ||
} | ||
} | ||
} else if (obj instanceof BasicDBList) { | ||
for(Object elem: (BasicDBList) obj) { | ||
res = modifyValueInPayload(elem, parentKey, queryKey, queryVal); | ||
if (res) { | ||
break; | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.akto.dto.testing; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.akto.dto.OriginalHttpRequest; | ||
import com.akto.dto.testing.AuthParam.Location; | ||
import com.akto.util.CookieTransformer; | ||
import com.akto.util.JSONUtils; | ||
import com.mongodb.BasicDBObject; | ||
|
||
public class Utils { | ||
public static boolean isRequestKeyPresent(String key, OriginalHttpRequest request, Location where){ | ||
if (key == null) return false; | ||
String k = key.toLowerCase().trim(); | ||
if (where.toString().equals(AuthParam.Location.BODY.toString())) { | ||
BasicDBObject basicDBObject = BasicDBObject.parse(request.getBody()); | ||
BasicDBObject data = JSONUtils.flattenWithDots(basicDBObject); | ||
boolean exists = data.keySet().contains(key); | ||
if(!exists){ | ||
for(String payloadKey: data.keySet()){ | ||
if(payloadKey.contains(key)){ | ||
exists = true; | ||
break; | ||
} | ||
} | ||
} | ||
return exists; | ||
} else { | ||
Map<String, List<String>> headers = request.getHeaders(); | ||
List<String> cookieList = headers.getOrDefault("cookie", new ArrayList<>()); | ||
return headers.containsKey(k) || CookieTransformer.isKeyPresentInCookie(cookieList, k); | ||
} | ||
} | ||
} |
26 changes: 14 additions & 12 deletions
26
libs/dao/src/main/java/com/akto/util/JsonStringPayloadModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters