Skip to content

Commit b9897df

Browse files
authored
Merge pull request #3710 from akto-api-security/feature/show_md_reports
Fixing full report
2 parents c0e472c + cec9cab commit b9897df

File tree

6 files changed

+71
-56
lines changed

6 files changed

+71
-56
lines changed

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/Category.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Badge, Box, HorizontalStack, Text, VerticalStack } from "@shopify/polar
22
import func from "@/util/func"
33
import Issue from "./Issue"
44

5-
function Category({ index, issue, subCategoryMap }) {
5+
function Category({ index, issue, subCategoryMap, viewMode = 'syntax' }) {
66
const severity = func.getRunResultSeverity(issue.vulnerableTestingRunResults[0], subCategoryMap)
77
return (
88
<Box id={issue.testName}>
@@ -32,7 +32,7 @@ function Category({ index, issue, subCategoryMap }) {
3232

3333
{
3434
issue.vulnerableTestingRunResults.map((vulnerableTestingRunResult, index) => {
35-
return ( <Issue testResults={issue.testResults} vulnerableApi={vulnerableTestingRunResult} cwes={(issue?.cwe || [])} compliance={issue?.compliance} references={(issue?.references || [])} /> )
35+
return ( <Issue testResults={issue.testResults} vulnerableApi={vulnerableTestingRunResult} cwes={(issue?.cwe || [])} compliance={issue?.compliance} references={(issue?.references || [])} viewMode={viewMode} /> )
3636
})
3737
}
3838

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/HttpRequestResponseViewer.jsx

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React from 'react'
21
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
32
import { Box, LegacyCard, Text, VerticalStack } from '@shopify/polaris';
43
import { coy } from 'react-syntax-highlighter/dist/esm/styles/prism';
54
import func from '@/util/func';
65
import transform from '../../../components/shared/customDiffEditor';
6+
import { MarkdownRenderer, markdownStyles } from '@/apps/dashboard/components/shared/MarkdownComponents';
77

8-
const HttpRequestResponseViewer = ({ data }) => {
8+
const HttpRequestResponseViewer = ({ data, viewMode = 'syntax' }) => {
9+
910
const requestJsonObj = func.requestJson(data, [])
1011
const responseJsonObj = func.responseJson(data, [])
1112

@@ -17,34 +18,56 @@ const HttpRequestResponseViewer = ({ data }) => {
1718
const truncateContent = (content) => {
1819
return content.length > MAX_CHARACTERS ? content.slice(0, MAX_CHARACTERS) + '...\n' : content
1920
}
20-
21-
return (
22-
<VerticalStack gap={3}>
23-
<Box>
24-
<LegacyCard>
25-
<Box padding={3} borderRadius='2'>
26-
<Text>Request</Text>
27-
<Box style={{maxHeight: '4000px', overflowY: 'hidden'}} overflowY='hidden'>
28-
<SyntaxHighlighter lineProps={{style: {whiteSpace: 'pre-wrap', wordBreak: 'break-all', display: 'block'}}} wrapLongLines={true} showLineNumbers={true} language="http" style={coy}>
29-
{truncateContent(formattedRequest)}
30-
</SyntaxHighlighter>
31-
</Box>
32-
</Box>
33-
</LegacyCard>
34-
</Box>
3521

22+
const formatAsMarkdownCodeBlock = (content) => {
23+
return `\`\`\`http\n${truncateContent(content)}\n\`\`\``
24+
}
25+
26+
const renderContent = (content, title) => {
27+
if (viewMode === 'markdown') {
28+
return (
3629
<Box>
37-
<LegacyCard>
38-
<Box padding={3} borderRadius='2'>
39-
<Text>Response</Text>
40-
<Box style={{maxHeight: '4000px', overflowY: 'hidden'}} overflowY='hidden'>
41-
<SyntaxHighlighter lineProps={{style: {whiteSpace: 'pre-wrap', wordBreak: 'break-all', display: 'block'}}} wrapLongLines={true} showLineNumbers={true} language="http" style={coy}>
42-
{truncateContent(formattedResponse)}
43-
</SyntaxHighlighter>
44-
</Box>
45-
</Box>
46-
</LegacyCard>
30+
<LegacyCard>
31+
<Box padding={3} borderRadius='2'>
32+
<Text>{title}</Text>
33+
<Box style={{maxHeight: '4000px', overflowY: 'auto'}}>
34+
<div className="markdown-content">
35+
<MarkdownRenderer>
36+
{formatAsMarkdownCodeBlock(content)}
37+
</MarkdownRenderer>
38+
</div>
39+
</Box>
40+
</Box>
41+
</LegacyCard>
4742
</Box>
43+
)
44+
}
45+
46+
return (
47+
<Box>
48+
<LegacyCard>
49+
<Box padding={3} borderRadius='2'>
50+
<Text>{title}</Text>
51+
<Box style={{maxHeight: '4000px', overflowY: 'hidden'}} overflowY='hidden'>
52+
<SyntaxHighlighter lineProps={{style: {whiteSpace: 'pre-wrap', wordBreak: 'break-all', display: 'block'}}} wrapLongLines={true} showLineNumbers={true} language="http" style={coy}>
53+
{truncateContent(content)}
54+
</SyntaxHighlighter>
55+
</Box>
56+
</Box>
57+
</LegacyCard>
58+
</Box>
59+
)
60+
}
61+
62+
return (
63+
<VerticalStack gap={3}>
64+
{renderContent(formattedRequest, 'Request')}
65+
{renderContent(formattedResponse, 'Response')}
66+
{viewMode === 'markdown' && (
67+
<style jsx>{`
68+
${markdownStyles}
69+
`}</style>
70+
)}
4871
</VerticalStack>
4972
)
5073
}

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/Issue.jsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import HttpRequestResponseViewer from './HttpRequestResponseViewer'
66
import func from '@/util/func'
77
import transform from './transform';
88

9-
const Issue = ({ vulnerableApi, references, cwes, compliance }) => {
9+
const Issue = ({ vulnerableApi, references, cwes, compliance, viewMode = 'syntax' }) => {
1010
const [vulnerableApisState, setVulnerableApisState] = useState([])
1111
const [vulnerableResultSampleData, setVulnerableResultSampleData] = useState({})
1212

@@ -69,10 +69,6 @@ const Issue = ({ vulnerableApi, references, cwes, compliance }) => {
6969
setParsedSampleDataMessage(tmpParsedSampleDataMessage)
7070
}, [vulnerableResultSampleData])
7171

72-
const sampleDataEditorComp = parsedSampleDataMessage == null ? (<></>) : (
73-
<HttpRequestResponseViewer data={parsedSampleDataMessage} />
74-
)
75-
7672
return (
7773
<>
7874
<Box id='affected-api-table-container'>
@@ -95,7 +91,7 @@ const Issue = ({ vulnerableApi, references, cwes, compliance }) => {
9591
<VerticalStack gap={1}>
9692
<Text variant="headingSm">Evidence</Text>
9793
<VerticalStack gap={2}>
98-
<HttpRequestResponseViewer data={parsedSampleDataMessage} />
94+
<HttpRequestResponseViewer data={parsedSampleDataMessage} viewMode={viewMode} />
9995
</VerticalStack>
10096
</VerticalStack>
10197
}

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/ReportFindings.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const ReportFindings = ({ aktoFindingsTableData, categoryVsIssuesMap, organizati
5050
])
5151

5252
let issueNo = 0
53+
const [totalIssues, setTotalIssues] = useState(0)
5354

5455
useEffect(() => {
5556
const mediaQueryList = window.matchMedia('print')
@@ -81,6 +82,18 @@ const ReportFindings = ({ aktoFindingsTableData, categoryVsIssuesMap, organizati
8182
return () => mediaQueryList.removeEventListener('change', handlePrint)
8283
}, [])
8384

85+
const setCountApis = (aktoFindingsTableData) => {
86+
let countApis = 0
87+
aktoFindingsTableData.forEach(item => {
88+
countApis += item.apisAffected
89+
})
90+
setTotalIssues(countApis)
91+
}
92+
93+
useEffect(() => {
94+
setCountApis(aktoFindingsTableData)
95+
}, [aktoFindingsTableData])
96+
8497

8598
return (
8699
<Box id="findings-table" paddingBlockStart={6} paddingBlockEnd={6} paddingInlineStart={5} paddingInlineEnd={5}>
@@ -115,6 +128,7 @@ const ReportFindings = ({ aktoFindingsTableData, categoryVsIssuesMap, organizati
115128
index={issueNo++}
116129
issue={issue}
117130
subCategoryMap={subCategoryMap}
131+
viewMode={totalIssues > 100 ? 'markdown' : 'syntax'}
118132
/>
119133
{index !== Object.keys(categoryVsIssuesMap).length - 1 || issueIndex !== issuesArr.length - 1 ? <Box paddingBlockStart={4} paddingBlockEnd={4}><Divider /></Box> : null}
120134
</Box>

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/VulnerabilityReport.jsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const VulnerabilityReport = () => {
2626
const [categoryVsApisCountMap, setCategoryVsApisCountMap] = useState({})
2727
const [aktoFindingsTableData, setAktoFindingsTableData] = useState([])
2828
const [ aktoRecommendations, setAktoRecommendations ] = useState([])
29-
const [graphData, setGraphData] = useState([])
3029
const [totalIssues, setTotalIssues] = useState(0)
3130
const [severityMap, setSeverityMap] = useState({})
3231
const [scanTime, setScanTime] = useState('')
@@ -36,8 +35,6 @@ const VulnerabilityReport = () => {
3635
const [topCategoriesChartData, setTopCategoriesChartData] = useState({})
3736
const [hostNameVsSeverityMap, setHostNameVsSeverityMap] = useState({})
3837

39-
const issuesLimit = 200
40-
4138
const pdfRef = useRef()
4239
const params = useParams()
4340
const reportId = params.reportId
@@ -148,11 +145,6 @@ const VulnerabilityReport = () => {
148145
testingRunCountsFromDB = resp.testingRunResults.length
149146
})
150147
resultsCount += 50
151-
if(vulnerableTestingRunResults.length >= issuesLimit) {
152-
func.setToast(true, false, "Displaying the vulnerability report with only first " + issuesLimit + " issues. Apply filters to view more or export specific issues.")
153-
break
154-
}
155-
156148
if (testingRunCountsFromDB < 50) {
157149
//EOF: break as no further documents exists
158150
break
@@ -186,23 +178,12 @@ const VulnerabilityReport = () => {
186178
//sampleDataVsCurlMap = { ...sampleDataVsCurlMap, ...resp.sampleDataVsCurlMap }
187179
})
188180
resultsCount += 50
189-
if(vulnerableTestingRunResults.length >= issuesLimit) {
190-
func.setToast(true, false, "Displaying the vulnerability report with only first " + issuesLimit + " issues. Apply filters to view more or export specific issues.")
191-
break
192-
}
193181
if (testingRunCountsFromDB < 50 || resultsCount >= 1000) {
194182
//EOF: break as no further documents exists
195183
break
196184
}
197185
}
198186
}
199-
200-
if(vulnerableTestingRunResults.length > issuesLimit) {
201-
while(vulnerableTestingRunResults.length !== issuesLimit) {
202-
vulnerableTestingRunResults.pop()
203-
}
204-
}
205-
206187
const localCategoryMap = LocalStore.getState().categoryMap
207188
const localSubCategoryMap = LocalStore.getState().subCategoryMap
208189
let shouldFetchSubcategoriesAndCategories = false

apps/dashboard/web/polaris_web/web/src/util/func.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ mergeApiInfoAndApiCollection(listEndpoints, apiInfoList, idToName,apiInfoSeverit
11151115
discoveredTimestamp = x.startTs
11161116
}
11171117
let description = apiInfoMap[key] ? apiInfoMap[key]['description'] : ""
1118+
let lastSeenTs = Math.max(apiInfoMap[key] ? apiInfoMap[key]["lastSeen"] : x.startTs, x.startTs)
11181119
ret[key] = {
11191120
id: x.method + "###" + x.url + "###" + x.apiCollectionId + "###" + Math.random(),
11201121
shadow: x.shadow ? x.shadow : false,
@@ -1127,8 +1128,8 @@ mergeApiInfoAndApiCollection(listEndpoints, apiInfoList, idToName,apiInfoSeverit
11271128
method: x.method,
11281129
color: x.sensitive && x.sensitive.size > 0 ? "#f44336" : "#00bfa5",
11291130
apiCollectionId: x.apiCollectionId,
1130-
last_seen: apiInfoMap[key] ? (this.prettifyEpoch(apiInfoMap[key]["lastSeen"])) : this.prettifyEpoch(x.startTs),
1131-
lastSeenTs: apiInfoMap[key] ? apiInfoMap[key]["lastSeen"] : x.startTs,
1131+
last_seen: this.prettifyEpoch(lastSeenTs),
1132+
lastSeenTs: lastSeenTs,
11321133
detectedTs: discoveredTimestamp === 0 ? x.startTs : discoveredTimestamp,
11331134
changesCount: x.changesCount,
11341135
changes: x.changesCount && x.changesCount > 0 ? (x.changesCount +" new parameter"+(x.changesCount > 1? "s": "")) : 'No new changes',

0 commit comments

Comments
 (0)