Skip to content

Commit

Permalink
Merge pull request #1293 from akto-api-security/feature/improvements_…
Browse files Browse the repository at this point in the history
…jul_15

Feature/improvements jul 15
  • Loading branch information
notshivansh authored Jul 19, 2024
2 parents 25352b0 + fd15263 commit fcc041e
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,9 @@ public List<ApiCollection> fillApiCollectionsUrlCount(List<ApiCollection> apiCol
if (count != null && (apiCollection.getHostName() != null)) {
apiCollection.setUrlsCount(count);
} else if(ApiCollection.Type.API_GROUP.equals(apiCollection.getType())){
loggerMaker.infoAndAddToDb("fillApiCollectionsUrlCount API_GROUP started: " + apiCollectionId + " " + tsRandom, LoggerMaker.LogDb.DASHBOARD);

count = SingleTypeInfoDao.instance.countEndpoints(Filters.in(SingleTypeInfo._COLLECTION_IDS, apiCollectionId));
loggerMaker.infoAndAddToDb("fillApiCollectionsUrlCount API_GROUP ended: " + apiCollectionId + " " + tsRandom, LoggerMaker.LogDb.DASHBOARD);

if (count == null) {
count = SingleTypeInfoDao.instance.countEndpoints(Filters.in(SingleTypeInfo._COLLECTION_IDS, apiCollectionId));
}
apiCollection.setUrlsCount(count);
} else {
apiCollection.setUrlsCount(fallbackCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ public static void createUnauthenticatedApiGroup() {
Filters.eq("_id", UnauthenticatedEndpoint.UNAUTHENTICATED_GROUP_ID)) == null) {
loggerMaker.infoAndAddToDb("AccountId: " + Context.accountId.get() + " Creating unauthenticated api group.", LogDb.DASHBOARD);
ApiCollection unauthenticatedApisGroup = new ApiCollection(UnauthenticatedEndpoint.UNAUTHENTICATED_GROUP_ID,
"Unauthenticated Apis", Context.now(), new HashSet<>(), null, 0, false, false);
"Unauthenticated APIs", Context.now(), new HashSet<>(), null, 0, false, false);

unauthenticatedApisGroup.setAutomated(true);
unauthenticatedApisGroup.setType(ApiCollection.Type.API_GROUP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function CollectionComponent(props) {
const { condition, index, dispatch, operatorComponent } = props
const [apiEndpoints, setApiEndpoints] = useState({})
const [regexText, setRegexText] = useState('')
const [hostRegexText, setHostRegexText] = useState('')

useEffect(() => {
fetchApiEndpoints(condition.data)
Expand Down Expand Up @@ -144,6 +145,8 @@ function CollectionComponent(props) {
return {method:"GET"}
case "REGEX":
return {}
case "HOST_REGEX":
return {}
default:
return {}
}
Expand All @@ -161,9 +164,13 @@ function CollectionComponent(props) {
value: 'METHOD'
},
{
label: 'Matches regex',
label: 'Path matches regex',
value: 'REGEX'
},
{
label: 'Host name matches regex',
value: 'HOST_REGEX'
}
]}
initial={condition.type}
selected={(value) => {
Expand All @@ -177,6 +184,11 @@ function CollectionComponent(props) {
dispatch({ type: "overwrite", index: index, key: "data", obj: {"regex":val } })
}

const handleHostRegexText = (val) => {
setHostRegexText(val)
dispatch({ type: "overwrite", index: index, key: "data", obj: {"host_regex":val } })
}

const component = (condition, index) => {
switch (condition.type) {
case "CUSTOM":
Expand All @@ -197,7 +209,12 @@ function CollectionComponent(props) {
return(
<TextField onChange={(val) => handleRegexText(val)} value={regexText} />
)
default: break;
case "HOST_REGEX":
return(
<TextField onChange={(val) => handleHostRegexText(val)} value={hostRegexText} />
)
default:
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import HighchartsReact from "highcharts-react-official"
import Highcharts from "highcharts"
import { useEffect, useRef, useState } from "react";
import func from "../../../../util/func";
import SpinnerCentered from "../progress/SpinnerCentered";

function LineChart(props) {

const { type, height, backgroundColor, data, graphPointClick, tooltipFormatter, yAxisTitle, title, text, defaultChartOptions, areaFillHex, color, width, noGap, showGridLines } = props;
const chartComponentRef = useRef(null)

const fillColor = {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, color],
[1, '#000000'],
],
};

const coreChartOptions = {
chart: {
type: type,
height: (height) + 'px',
spacing: [5, 0, 0, 0],
backgroundColor: backgroundColor
},
credits: {
enabled: false,
},
title: {
text: title,
align: 'left',
margin: 20
},
tooltip:{
shared: false,
},
plotOptions: {
column: {
dataLabels: {
enabled: true
}
},
series: {
minPointLength: noGap ? 0 : 5,
pointWidth: width,
cursor: 'pointer',
point: {
events: {
click: () => {
}
}
}
}
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
day: '%b %e',
month: '%b',
},
title: {
text: 'Date',
},
visible: text,
gridLineWidth: 0,
},
yAxis: [
{
title: {
text: yAxisTitle,
},
visible: text,
gridLineWidth: showGridLines ? 1 : 0,
min: 1,
}
],
time: {
useUTC: false
},
...defaultChartOptions
}

function processChartData(data) {
return data.map((x, i) => {
return {
data: x.data,
color: x.color,
name: x.name,
fillColor: areaFillHex ? fillColor : {},
marker: {
enabled: false
},
yAxis: i==1 ? 1 : 0,
lineWidth: i==1 ? 1: 3

}
})
}

const [chartOptions, setChartOptions] = useState({...coreChartOptions, series: []});

useEffect(() => {
setChartOptions((prev) => {
let tmp = processChartData(data);
if (func.deepComparison(prev.series, tmp)) {
return prev;
}
prev.series = tmp;
prev.yAxis = tmp.map((x, i) => {
return {
title: {
text: x.name,
color: x.color
},
visible: x.name,
gridLineWidth: 1,
min: 1,
opposite: i==1,
}
})
prev.plotOptions.series.point.events.click = graphPointClick
prev.tooltip.formatter = tooltipFormatter
return {...prev};
})
}, [data])

return (
data.length > 0 ? <HighchartsReact
key={"chart"}
highcharts={Highcharts}
options={chartOptions}
ref={chartComponentRef}
/> : <SpinnerCentered/>
)
}

export default LineChart;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ApiDetails from "./ApiDetails";
import PersistStore from "../../../../main/PersistStore";
import ApiChangesTable from "./component/ApiChangesTable";
import SummaryCardInfo from "../../../components/shared/SummaryCardInfo";
import StackedChart from "../../../components/charts/StackedChart";
import LineChart from "../../../components/charts/LineChart";
import TitleWithInfo from "@/apps/dashboard/components/shared/TitleWithInfo";
import { useLocation } from "react-router-dom";

Expand Down Expand Up @@ -145,19 +145,19 @@ function ApiChanges() {
return [
{
data: endpointsTrend,
color: "#AEE9D1",
color: "#61affe",
name: "New endpoints"
},
{
data: parametersTrend,
color: "#A4E8F2",
color: "#fca130",
name: "New parameters"
}
]
}
const defaultChartOptions = {
"legend": {
enabled: false
enabled: true
},
}

Expand All @@ -169,21 +169,9 @@ function ApiChanges() {
<Divider />
</VerticalStack>
<VerticalStack gap={2}>
<HorizontalStack align="end">
<HorizontalStack gap={3}>
<HorizontalStack gap={2}>
<div style={{background: "#A4E8F2", borderRadius: '50%', height:'8px', width: '8px'}} />
<Text variant="bodyMd">Sensitive params</Text>
</HorizontalStack>
<HorizontalStack gap={2}>
<div style={{background: "#AEE9D1", borderRadius: '50%', height:'8px', width: '8px'}} />
<Text variant="bodyMd">New endpoints</Text>
</HorizontalStack>
</HorizontalStack>
</HorizontalStack>
<StackedChart
<LineChart
key={`trend-chart`}
type='column'
type='line'
color='#6200EA'
areaFillHex="true"
height="280"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function ApiSingleSchema(props) {
<Box paddingBlockStart="05" paddingBlockEnd="05">
<HorizontalStack gap="2">
<Text variant="bodyMd">Header</Text>
<span style={{padding: '4px 8px', width: '30px', color: '#202223', background:(isHeader ? "#ECEBFF" : "#E4E5E7"), borderRadius: '4px'}}>
<span style={{padding: '4px 8px', width: 'fit-content', color: '#202223', background:(isHeader ? "#ECEBFF" : "#E4E5E7"), borderRadius: '4px'}}>
{headerCount}
</span>
</HorizontalStack>
Expand All @@ -116,7 +116,7 @@ function ApiSingleSchema(props) {
<Box paddingBlockStart="05" paddingBlockEnd="05">
<HorizontalStack gap="2">
<Text variant="bodyMd">Payload</Text>
<span style={{padding: '4px 8px', width: '30px', color: '#202223', background:(!isHeader ? "#ECEBFF" : "#E4E5E7"), borderRadius: '4px'}}>
<span style={{padding: '4px 8px', width: 'fit-content', color: '#202223', background:(!isHeader ? "#ECEBFF" : "#E4E5E7"), borderRadius: '4px'}}>
{payloadCount}
</span>
</HorizontalStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ const transform = {
let currDate = twoMonthsAgo
let ret = []
let dateToCount = resp.reduce((m, e) => {
let detectDate = func.toYMD(new Date(e._id * 86400 * 1000))

let detectDate = func.toYMD(new Date((e._id+1) * 86400 * 1000))
m[detectDate] = (m[detectDate] || 0) + e.count
newParametersCount += e.count
return m
Expand Down
3 changes: 2 additions & 1 deletion libs/dao/src/main/java/com/akto/DaoInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public static CodecRegistry createCodecRegistry(){
ClassModel<JiraIntegration> jiraintegrationClassModel = ClassModel.builder(JiraIntegration.class).enableDiscriminator(true).build();
ClassModel<MethodCondition> methodConditionClassModel = ClassModel.builder(MethodCondition.class).enableDiscriminator(true).build();
ClassModel<RegexTestingEndpoints> regexTestingEndpointsClassModel = ClassModel.builder(RegexTestingEndpoints.class).enableDiscriminator(true).build();
ClassModel<HostRegexTestingEndpoints> hostRegexTestingEndpointsClassModel = ClassModel.builder(HostRegexTestingEndpoints.class).enableDiscriminator(true).build();
ClassModel<DependencyNode> dependencyNodeClassModel = ClassModel.builder(DependencyNode.class).enableDiscriminator(true).build();
ClassModel<ParamInfo> paramInfoClassModel = ClassModel.builder(ParamInfo.class).enableDiscriminator(true).build();
ClassModel<Node> nodeClassModel = ClassModel.builder(Node.class).enableDiscriminator(true).build();
Expand Down Expand Up @@ -277,7 +278,7 @@ public static CodecRegistry createCodecRegistry(){
loaderClassModel, normalLoaderClassModel, postmanUploadLoaderClassModel, aktoGptConfigClassModel,
vulnerableRequestForTemplateClassModel, trafficMetricsAlertClassModel,jiraintegrationClassModel, setupClassModel,
cronTimersClassModel, connectionInfoClassModel, testLibraryClassModel,
methodConditionClassModel, regexTestingEndpointsClassModel, allTestingEndpointsClassModel,
methodConditionClassModel, regexTestingEndpointsClassModel, hostRegexTestingEndpointsClassModel, allTestingEndpointsClassModel,
UsageMetricClassModel, UsageMetricInfoClassModel, UsageSyncClassModel, OrganizationClassModel,
yamlNodeDetails, multiExecTestResultClassModel, workflowTestClassModel, dependencyNodeClassModel, paramInfoClassModel,
nodeClassModel, connectionClassModel, edgeClassModel, replaceDetailClassModel, modifyHostDetailClassModel, fileUploadClassModel
Expand Down
Loading

0 comments on commit fcc041e

Please sign in to comment.