Skip to content

Commit 6eccc1c

Browse files
Merge pull request #650 from akto-api-security/feature/ab_6
Feature/ab 6
2 parents 58b6ac3 + bc4cc49 commit 6eccc1c

File tree

15 files changed

+379
-36
lines changed

15 files changed

+379
-36
lines changed

apps/dashboard/src/main/java/com/akto/action/ExportSampleDataAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public String importInBurp() {
4545

4646
int apiCollectionId = apiCollection.getId();
4747

48-
List<SampleData> sampleDataList = SampleDataDao.instance.fetchSampleDataPaginated(apiCollectionId, lastUrlFetched, lastMethodFetched, limit);
48+
List<SampleData> sampleDataList = SampleDataDao.instance.fetchSampleDataPaginated(apiCollectionId, lastUrlFetched, lastMethodFetched, limit, 1);
4949

5050
lastMethodFetched = null;
5151
lastUrlFetched = null;

apps/dashboard/src/main/java/com/akto/action/OpenApiAction.java

+37-8
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,33 @@ public class OpenApiAction extends UserAction implements ServletResponseAware {
2727
private int apiCollectionId;
2828
private String openAPIString = null;
2929
private boolean includeHeaders = true;
30+
31+
private String lastFetchedUrl;
32+
private String lastFetchedMethod;
3033
@Override
3134
public String execute() {
3235
try {
33-
34-
List<SampleData> sampleData = SampleDataDao.instance.findAll(
35-
Filters.eq("_id.apiCollectionId", apiCollectionId)
36-
);
3736
ApiCollection apiCollection = ApiCollectionsDao.instance.findOne("_id", apiCollectionId);
38-
if (apiCollection == null) {
39-
return ERROR.toUpperCase();
40-
}
37+
if (apiCollection == null) return ERROR.toUpperCase();
4138
String host = apiCollection.getHostName();
39+
40+
int limit = 200;
41+
List<SampleData> sampleDataList = SampleDataDao.instance.fetchSampleDataPaginated(
42+
apiCollectionId, lastFetchedUrl, lastFetchedMethod, limit, 1
43+
);
44+
45+
int size = sampleDataList.size();
46+
if (size < limit) {
47+
lastFetchedUrl = null;
48+
lastFetchedMethod = null;
49+
} else {
50+
SampleData last = sampleDataList.get(size-1);
51+
lastFetchedUrl = last.getId().getUrl();
52+
lastFetchedMethod = last.getId().getMethod().name();
53+
}
54+
4255
SampleDataToSTI sampleDataToSTI = new SampleDataToSTI();
43-
sampleDataToSTI.setSampleDataToSTI(sampleData);
56+
sampleDataToSTI.setSampleDataToSTI(sampleDataList);
4457
Map<String,Map<String, Map<Integer, List<SingleTypeInfo>>>> stiList = sampleDataToSTI.getSingleTypeInfoMap();
4558
OpenAPI openAPI = Main.init(apiCollection.getDisplayName(),stiList, includeHeaders, host);
4659
openAPIString = Main.convertOpenApiToJSON(openAPI);
@@ -84,4 +97,20 @@ public void setServletResponse(HttpServletResponse response) {
8497
public void setIncludeHeaders(boolean includeHeaders) {
8598
this.includeHeaders = includeHeaders;
8699
}
100+
101+
public String getLastFetchedUrl() {
102+
return lastFetchedUrl;
103+
}
104+
105+
public void setLastFetchedUrl(String lastFetchedUrl) {
106+
this.lastFetchedUrl = lastFetchedUrl;
107+
}
108+
109+
public String getLastFetchedMethod() {
110+
return lastFetchedMethod;
111+
}
112+
113+
public void setLastFetchedMethod(String lastFetchedMethod) {
114+
this.lastFetchedMethod = lastFetchedMethod;
115+
}
87116
}

apps/dashboard/src/main/java/com/akto/action/observe/InventoryAction.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.akto.dto.ApiInfo.ApiInfoKey;
88
import com.akto.dto.type.SingleTypeInfo;
99
import com.akto.dto.type.URLMethods.Method;
10+
import com.akto.log.LoggerMaker;
11+
import com.akto.log.LoggerMaker.LogDb;
1012
import com.akto.util.Constants;
1113
import com.mongodb.BasicDBList;
1214
import com.mongodb.BasicDBObject;
@@ -40,6 +42,7 @@ public class InventoryAction extends UserAction {
4042
// }
4143

4244
public final static int DELTA_PERIOD_VALUE = 60 * 24 * 60 * 60;
45+
private static final LoggerMaker loggerMaker = new LoggerMaker(InventoryAction.class);
4346

4447
private String subType;
4548
public List<SingleTypeInfo> fetchSensitiveParams() {
@@ -579,6 +582,7 @@ private Bson prepareFilters() {
579582
}
580583
}
581584

585+
loggerMaker.infoAndAddToDb(filterList.toString(), LogDb.DASHBOARD);
582586
return Filters.and(filterList);
583587

584588
}
@@ -607,6 +611,7 @@ private List<SingleTypeInfo> getMongoResults() {
607611

608612
Bson sort = sortOrder == 1 ? Sorts.ascending(sortFields) : Sorts.descending(sortFields);
609613

614+
loggerMaker.infoAndAddToDb(String.format("skip: %s, limit: %s, sort: %s", skip, limit, sort), LogDb.DASHBOARD);
610615
List<SingleTypeInfo> list = SingleTypeInfoDao.instance.findAll(Filters.and(prepareFilters()), skip, limit, sort);
611616
return list;
612617
}
@@ -617,7 +622,14 @@ private long getTotalParams() {
617622

618623
public String fetchChanges() {
619624
response = new BasicDBObject();
620-
response.put("data", new BasicDBObject("endpoints", getMongoResults()).append("total", getTotalParams()));
625+
626+
long totalParams = getTotalParams();
627+
loggerMaker.infoAndAddToDb("Total params: " + totalParams, LogDb.DASHBOARD);
628+
629+
List<SingleTypeInfo> singleTypeInfos = getMongoResults();
630+
loggerMaker.infoAndAddToDb("STI count: " + singleTypeInfos.size(), LogDb.DASHBOARD);
631+
632+
response.put("data", new BasicDBObject("endpoints", singleTypeInfos ).append("total", totalParams));
621633

622634
return Action.SUCCESS.toUpperCase();
623635
}

apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,13 @@ static void executePIISourceFetch() {
256256

257257
if (!dt.getBoolean("active", true)) {
258258
PIISourceDao.instance.updateOne(findQ, Updates.unset("mapNameToPIIType." + piiKey));
259-
CustomDataTypeDao.instance.updateOne("name", piiKey, Updates.set("active", false));
259+
CustomDataType existingCDT = CustomDataTypeDao.instance.findOne("name", piiKey);
260+
if (existingCDT == null) {
261+
CustomDataTypeDao.instance.insertOne(getCustomDataTypeFromPiiType(piiSource, piiType, false));
262+
continue;
263+
} else {
264+
CustomDataTypeDao.instance.updateOne("name", piiKey, Updates.set("active", false));
265+
}
260266
}
261267

262268
if (currTypes.containsKey(piiKey) && currTypes.get(piiKey).equals(piiType)) {
@@ -798,6 +804,13 @@ public void runInitializerFunctions() {
798804
PIISourceDao.instance.insertOne(piiSource);
799805
}
800806

807+
if (PIISourceDao.instance.findOne("_id", "Fin") == null) {
808+
String fileUrl = "https://raw.githubusercontent.com/akto-api-security/akto/master/pii-types/fintech.json";
809+
PIISource piiSource = new PIISource(fileUrl, 0, 1638571050, 0, new HashMap<>(), true);
810+
piiSource.setId("Fin");
811+
PIISourceDao.instance.insertOne(piiSource);
812+
}
813+
801814
setUpWeeklyScheduler();
802815
setUpDailyScheduler();
803816
setUpWebhookScheduler();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.akto.listener;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertTrue;
6+
7+
import java.util.HashMap;
8+
9+
import com.akto.MongoBasedTest;
10+
import com.akto.dao.CustomDataTypeDao;
11+
import com.akto.dao.context.Context;
12+
import com.akto.dao.pii.PIISourceDao;
13+
import com.akto.dto.CustomDataType;
14+
import com.akto.dto.pii.PIISource;
15+
import com.mongodb.BasicDBObject;
16+
17+
import org.junit.Test;
18+
19+
public class TestFintechTypes extends MongoBasedTest {
20+
21+
22+
@Test
23+
public void testTypes() {
24+
String fileUrl = "https://raw.githubusercontent.com/akto-api-security/akto/master/pii-types/fintech.json";
25+
PIISource piiSource = new PIISource(fileUrl, 0, 1638571050, 0, new HashMap<>(), true);
26+
piiSource.setId("Fin");
27+
PIISourceDao.instance.insertOne(piiSource);
28+
InitializerListener.executePIISourceFetch();
29+
Context.accountId.set(ACCOUNT_ID);
30+
for(CustomDataType cdt: CustomDataTypeDao.instance.findAll(new BasicDBObject())) {
31+
switch (cdt.getName().toUpperCase()) {
32+
case "PAN CARD":
33+
assertTrue(cdt.validate("ABCDE9458J", "foo"));
34+
assertFalse(cdt.validate("ACDE9458J", "foo"));
35+
break;
36+
37+
default:
38+
break;
39+
}
40+
41+
}
42+
}
43+
44+
}

apps/dashboard/web/src/apps/dashboard/views/marketplace/PageMarketplace.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export default {
230230
let aktoTestTypes = await issuesApi.fetchAllSubCategories()
231231
this.businessCategories = aktoTestTypes.categories
232232
this.businessSubCategories = aktoTestTypes.subCategories
233-
this.$router.push(this.leftNavItems[0].items[0].link)
233+
this.$router.push(this.leftNavItems[0].items[0].link)
234234
},
235235
computed: {
236236
...mapState('marketplace', ['defaultSubcategories', 'userSubcategories', 'loading']),
@@ -338,4 +338,4 @@ export default {
338338
.c-item--title:hover {
339339
background: #f6f6f6;
340340
}
341-
</style>
341+
</style>

apps/dashboard/web/src/apps/dashboard/views/observe/inventory/api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ export default {
3939
}
4040
})
4141
},
42-
downloadOpenApiFile(apiCollectionId) {
42+
downloadOpenApiFile(apiCollectionId,lastFetchedUrl, lastFetchedMethod) {
4343
return request({
4444
url: '/api/generateOpenApiFile',
4545
method: 'post',
4646
data: {
47-
apiCollectionId
47+
apiCollectionId, lastFetchedUrl, lastFetchedMethod
4848
}
4949
})
5050
},

apps/dashboard/web/src/apps/dashboard/views/observe/inventory/components/APIEndpoints.vue

+20-8
Original file line numberDiff line numberDiff line change
@@ -383,19 +383,31 @@ export default {
383383
}
384384
},
385385
async downloadOpenApiFile() {
386-
var result = await this.$store.dispatch('inventory/downloadOpenApiFile')
387-
let openApiString = result["openAPIString"]
388-
var blob = new Blob([openApiString], {
389-
type: "application/json",
390-
});
391-
const fileName = "open_api_" +this.apiCollectionName+ ".json";
392-
saveAs(blob, fileName);
386+
let lastFetchedUrl = null;
387+
let lastFetchedMethod = null;
388+
for (let index =0; index < 10; index++) {
389+
var result = await this.$store.dispatch('inventory/downloadOpenApiFile', {lastFetchedUrl, lastFetchedMethod})
390+
let openApiString = result["openAPIString"]
391+
var blob = new Blob([openApiString], {
392+
type: "application/json",
393+
});
394+
const fileName = "open_api_" +this.apiCollectionName+ ".json";
395+
saveAs(blob, fileName);
396+
397+
lastFetchedUrl = result["lastFetchedUrl"]
398+
lastFetchedMethod = result["lastFetchedMethod"]
399+
400+
if (!lastFetchedUrl || !lastFetchedMethod) break;
401+
}
402+
403+
393404
window._AKTO.$emit('SHOW_SNACKBAR', {
394405
show: true,
395-
text: fileName + " downloaded !",
406+
text: "OpenAPI spec file downloaded !",
396407
color: 'green'
397408
})
398409
},
410+
399411
async exportToPostman() {
400412
var result = await this.$store.dispatch('inventory/exportToPostman')
401413
window._AKTO.$emit('SHOW_SNACKBAR', {

apps/dashboard/web/src/apps/dashboard/views/observe/inventory/store/module.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ const inventory = {
181181
return resp
182182
})
183183
},
184-
downloadOpenApiFile({commit,state}) {
185-
return api.downloadOpenApiFile(state.apiCollectionId).then(resp => {
184+
downloadOpenApiFile({commit,state}, {lastFetchedUrl, lastFetchedMethod}) {
185+
return api.downloadOpenApiFile(state.apiCollectionId, lastFetchedUrl, lastFetchedMethod).then(resp => {
186186
return resp
187187
})
188188
},

apps/dashboard/web/src/apps/dashboard/views/observe/sensitive/SensitiveData.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ export default {
210210
},
211211
methods: {
212212
async fetchRecentParamsForRequest(sortKey, sortOrder, skip, limit, filters, filterOperators) {
213-
return await api.fetchChanges(sortKey, sortOrder, skip, limit, filters, filterOperators, this.startTimestamp, this.endTimestamp, true, true)
213+
return await api.fetchChanges(sortKey, sortOrder, skip, limit, filters, filterOperators, 0, this.endTimestamp, true, true)
214214
},
215215
async fetchRecentParamsForResponse(sortKey, sortOrder, skip, limit, filters, filterOperators) {
216-
return await api.fetchChanges(sortKey, sortOrder, skip, limit, filters, filterOperators, this.startTimestamp, this.endTimestamp, true, false)
216+
return await api.fetchChanges(sortKey, sortOrder, skip, limit, filters, filterOperators, 0, this.endTimestamp, true, false)
217217
},
218218
ignoreForThisAPI(item) {
219219
this.ignoredCollection = item.name

0 commit comments

Comments
 (0)