Skip to content

Commit

Permalink
Merge pull request #1519 from akto-api-security/hotfix/security_postu…
Browse files Browse the repository at this point in the history
…re_bugs

Hotfix/security posture bugs
  • Loading branch information
avneesh-akto authored Sep 19, 2024
2 parents 0a1e5a1 + 0015194 commit a97fcee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2341,7 +2341,7 @@ private static void backFillDiscovered() {
do {
Map<ApiInfo.ApiInfoKey, ApiInfo> apiInfoMap = new HashMap<>();
Bson idFilter = id == null ? Filters.empty() : Filters.gt("_id", id);
singleTypeInfos = SingleTypeInfoDao.instance.findAll(Filters.gt("_id", idFilter), 0, 100_000, sort, Projections.include(SingleTypeInfo._TIMESTAMP, SingleTypeInfo._URL, SingleTypeInfo._API_COLLECTION_ID, SingleTypeInfo._METHOD));
singleTypeInfos = SingleTypeInfoDao.instance.findAll(idFilter, 0, 100_000, sort, Projections.include(SingleTypeInfo._TIMESTAMP, SingleTypeInfo._URL, SingleTypeInfo._API_COLLECTION_ID, SingleTypeInfo._METHOD));
for (SingleTypeInfo singleTypeInfo: singleTypeInfos) {
id = singleTypeInfo.getId();
ApiInfo.ApiInfoKey apiInfoKey = new ApiInfo.ApiInfoKey(singleTypeInfo.getApiCollectionId(), singleTypeInfo.getUrl(), Method.fromString(singleTypeInfo.getMethod()));
Expand All @@ -2356,7 +2356,21 @@ private static void backFillDiscovered() {
for (ApiInfo apiInfo: apiInfoMap.values()) {
updates.add(
new UpdateOneModel<>(
ApiInfoDao.getFilter(apiInfo.getId()),
Filters.and(
ApiInfoDao.getFilter(apiInfo.getId()),
Filters.exists(ApiInfo.DISCOVERED_TIMESTAMP, false)
),
Updates.set(ApiInfo.DISCOVERED_TIMESTAMP, apiInfo.getDiscoveredTimestamp()),
new UpdateOptions().upsert(false)
)
);

updates.add(
new UpdateOneModel<>(
Filters.and(
ApiInfoDao.getFilter(apiInfo.getId()),
Filters.exists(ApiInfo.DISCOVERED_TIMESTAMP, true)
),
Updates.min(ApiInfo.DISCOVERED_TIMESTAMP, apiInfo.getDiscoveredTimestamp()),
new UpdateOptions().upsert(false)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import SmoothAreaChart from './new_components/SmoothChart'
import DateRangeFilter from '../../components/layouts/DateRangeFilter';
import { produce } from 'immer';
import EmptyCard from './new_components/EmptyCard';
import TooltipText from '../../components/shared/TooltipText';
import transform from '../observe/transform';

function HomeDashboard() {

Expand Down Expand Up @@ -378,15 +380,19 @@ function HomeDashboard() {
Object.keys(apiStats.riskScoreMap).forEach((key) => {
const badgeIndex = 5 - parseInt(key, 10);
const value = apiStats.riskScoreMap[key];
result[badgeIndex].text = value;
result[badgeIndex].progressValue = `${((value / totalApisCount) * 100).toFixed(2)}%`;
result[badgeIndex].text = value ? value : 0;
if (!totalApisCount || totalApisCount === 0) {
result[badgeIndex].progressValue = `0%`;
} else {
result[badgeIndex].progressValue = `${((value / totalApisCount) * 100).toFixed(2)}%`;
}
});

setRiskScoreData(result)
}

function getCollectionsWithCoverage() {
const validCollections = allCollections.filter(collection => collection.hostName !== null && collection.hostName !== undefined);
const validCollections = allCollections.filter(collection => collection.hostName !== null && collection.hostName !== undefined && !collection.deactivated);

const sortedCollections = validCollections.sort((a, b) => b.startTs - a.startTs);

Expand All @@ -405,7 +411,7 @@ function HomeDashboard() {
const summaryInfo = [
{
title: 'Total APIs',
data: totalAPIs,
data: transform.formatNumberWithCommas(totalAPIs),
variant: 'heading2xl',
byLineComponent: generateByLineComponent((totalAPIs - oldTotalApis), func.timeDifference(startTimestamp, endTimestamp)),
smoothChartComponent: (<SmoothAreaChart tickPositions={[oldTotalApis, totalAPIs]} />)
Expand Down Expand Up @@ -507,8 +513,10 @@ function HomeDashboard() {
return collections.map((collection, index) => ([
<HorizontalStack align='space-between'>
<HorizontalStack gap={2}>
<Text>{collection.name}</Text>
<Text color='subdued'>{Math.floor(100.0 * collection.apisTested / collection.totalApis)}% test coverage</Text>
<Box maxWidth='287px'>
<TooltipText tooltip={collection.name} text={collection.name}/>
</Box>
<Text variant='bodySm' color='subdued'>{(collection.totalApis === 0 ? 0 : Math.floor(100.0 * collection.apisTested / collection.totalApis))}% test coverage</Text>
</HorizontalStack>
<Text>{collection.totalApis}</Text>
</HorizontalStack>
Expand Down

0 comments on commit a97fcee

Please sign in to comment.