Skip to content

Commit 80862ce

Browse files
authored
Merge pull request #1355 from akto-api-security/hotfix/first_url_param_merging
fix first url param merging
2 parents 1328e95 + 8e2f819 commit 80862ce

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

apps/api-runtime/src/main/java/com/akto/runtime/APICatalogSync.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,7 @@ public static boolean isNumber(String val) {
709709

710710
public static URLTemplate tryParamteresingUrl(URLStatic newUrl){
711711
String[] tokens = tokenize(newUrl.getUrl());
712-
if(tokens.length < 2){
713-
return null;
714-
}
712+
boolean tokensBelowThreshold = tokens.length < 2;
715713
Pattern pattern = patternToSubType.get(SingleTypeInfo.UUID);
716714
boolean allNull = true;
717715
SuperType[] newTypes = new SuperType[tokens.length];
@@ -733,7 +731,7 @@ public static URLTemplate tryParamteresingUrl(URLStatic newUrl){
733731

734732
if(tokens[i] != null){
735733
SubType tempSubType = KeyTypes.findSubType(tokens[i], ""+i, null,true);
736-
if(isValidSubtype(tempSubType)){
734+
if(!tokensBelowThreshold && isValidSubtype(tempSubType)){
737735
newTypes[i] = SuperType.STRING;
738736
tokens[i] = null;
739737
}else if(isAlphanumericString(tempToken)){

apps/api-runtime/src/test/java/com/akto/parsers/TestMergingNew.java

+28
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,34 @@ public void testmultipleUUIDForceMerge(){
164164
assertNotNull(singleTypeInfo2);
165165
}
166166

167+
@Test
168+
public void testFirstUrlParameterMerging(){
169+
SingleTypeInfoDao.instance.getMCollection().drop();
170+
ApiCollectionsDao.instance.getMCollection().drop();
171+
HttpCallParser parser = new HttpCallParser("userIdentifier", 1, 1, 1, true);
172+
List<HttpResponseParams> responseParams = new ArrayList<>();
173+
List<String> urls = new ArrayList<>();
174+
urls.add("/D654447FF7"); // merges to /STRING
175+
urls.add("/c7e5e544-4040-4405-b2a7-22bf9c5286fb"); // merges to /STRING
176+
urls.add("/3"); // merges to /INTEGER
177+
urls.add(new ObjectId().toHexString()); // merges to /OBJECT_ID
178+
urls.add("[email protected]"); //this shouldn't get merge because tokensBelowThreshold and subtype match
179+
180+
int i = 0;
181+
for (String c: urls) {
182+
HttpResponseParams resp = createDifferentHttpResponseParams(i*100, c);
183+
responseParams.add(resp);
184+
i +=1;
185+
}
186+
187+
parser.syncFunction(responseParams, false, true, null);
188+
parser.apiCatalogSync.syncWithDB(false, true, SyncLimit.noLimit);
189+
parser.apiCatalogSync.buildFromDB(false, true);
190+
assertEquals(1, parser.apiCatalogSync.getDbState(123).getStrictURLToMethods().size());
191+
assertEquals(3, parser.apiCatalogSync.getDbState(123).getTemplateURLToMethods().size());
192+
193+
}
194+
167195
@Test
168196
public void testUUIDForceMerge() {
169197
SingleTypeInfoDao.instance.getMCollection().drop();

apps/mini-runtime/src/main/java/com/akto/hybrid_runtime/APICatalogSync.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,7 @@ public static boolean isNumber(String val) {
526526

527527
public static URLTemplate tryParamteresingUrl(URLStatic newUrl){
528528
String[] tokens = tokenize(newUrl.getUrl());
529-
if(tokens.length < 2){
530-
return null;
531-
}
529+
boolean tokensBelowThreshold = tokens.length < 2;
532530
Pattern pattern = patternToSubType.get(SingleTypeInfo.UUID);
533531
boolean allNull = true;
534532
SuperType[] newTypes = new SuperType[tokens.length];
@@ -550,7 +548,7 @@ public static URLTemplate tryParamteresingUrl(URLStatic newUrl){
550548

551549
if(tokens[i] != null){
552550
SubType tempSubType = KeyTypes.findSubType(tokens[i], ""+i, null,true);
553-
if(isValidSubtype(tempSubType)){
551+
if(!tokensBelowThreshold && isValidSubtype(tempSubType)){
554552
newTypes[i] = SuperType.STRING;
555553
tokens[i] = null;
556554
}else if(isAlphanumericString(tempToken)){

0 commit comments

Comments
 (0)