-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: HTML report #130
feat: HTML report #130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||||||||||||||||||||||
package reporting | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||
"bytes" | ||||||||||||||||||||||||||
_ "embed" | ||||||||||||||||||||||||||
"html/template" | ||||||||||||||||||||||||||
"log" | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
var ( | ||||||||||||||||||||||||||
//go:embed html/report.tmpl | ||||||||||||||||||||||||||
htmlTemplate string | ||||||||||||||||||||||||||
//go:embed html/report.css | ||||||||||||||||||||||||||
cssTemplate string | ||||||||||||||||||||||||||
//go:embed html/github.svg | ||||||||||||||||||||||||||
githubSVG string | ||||||||||||||||||||||||||
//go:embed html/checkmarx_logo.html | ||||||||||||||||||||||||||
checkmarxLogo string | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func writeHtml(report Report) string { | ||||||||||||||||||||||||||
tmpl := template.Must(template.New("report").Funcs(getFuncMap()).Parse(htmlTemplate)) | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is new for me. When the |
||||||||||||||||||||||||||
var buffer bytes.Buffer | ||||||||||||||||||||||||||
err := tmpl.Execute(&buffer, report) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
log.Fatalf("failed to create HTML report with error: %v", err) | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think maybe use |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
return buffer.String() | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func getFuncMap() template.FuncMap { | ||||||||||||||||||||||||||
return template.FuncMap{ | ||||||||||||||||||||||||||
"includeCSS": func() template.CSS { return template.CSS(cssTemplate) }, | ||||||||||||||||||||||||||
"includeSVG": func() template.HTML { return template.HTML(githubSVG) }, | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Check failure Code scanning / gosec The used method does not auto-escape HTML. This can potentially lead to 'Cross-site Scripting' vulnerabilities, in case the attacker controls the input.
The used method does not auto-escape HTML. This can potentially lead to 'Cross-site Scripting' vulnerabilities, in case the attacker controls the input.
|
||||||||||||||||||||||||||
"includeLogo": func() template.HTML { return template.HTML(checkmarxLogo) }, | ||||||||||||||||||||||||||
Check failure Code scanning / gosec The used method does not auto-escape HTML. This can potentially lead to 'Cross-site Scripting' vulnerabilities, in case the attacker controls the input.
The used method does not auto-escape HTML. This can potentially lead to 'Cross-site Scripting' vulnerabilities, in case the attacker controls the input.
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+31
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be declared as
Suggested change
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
outline: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
font-family: sans-serif; | ||
} | ||
|
||
.container { | ||
display: flex; | ||
align-items: center; | ||
flex-direction: column; | ||
margin: 5px; | ||
border: 1px solid #bebebe; | ||
} | ||
|
||
.run-info { | ||
display: flex; | ||
flex-wrap: wrap; | ||
border: 1px solid #bebebe; | ||
margin-top: 10px; | ||
width: 50vw; | ||
} | ||
|
||
.run-info > span { | ||
flex-basis: 50%; | ||
text-align: center; | ||
} | ||
|
||
.counters { | ||
display: flex; | ||
flex-direction: row; | ||
margin: 22px 0; | ||
} | ||
|
||
.report-header-footer { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
border-bottom: 1px solid #bebebe; | ||
width: 100%; | ||
padding: 15px 21px; | ||
background-color: #503e9e; | ||
height: 50px; | ||
font-weight: bold; | ||
font-size: 14px; | ||
color: #fff; | ||
cursor: default; | ||
user-select: none; | ||
} | ||
|
||
.report-header-footer > a { | ||
color: inherit; | ||
text-decoration: inherit; | ||
} | ||
|
||
.report-header-footer > .title { | ||
font-size: 18px; | ||
} | ||
|
||
.report-header-footer > .title > span { | ||
color: #000; | ||
} | ||
|
||
.report-header-footer > .timestamp { | ||
font-weight: normal; | ||
font-style: italic; | ||
opacity: 0.5; | ||
} | ||
|
||
.badge { | ||
color: #fff; | ||
border: 2px solid #e8e8e8; | ||
border-radius: 50%; | ||
cursor: default; | ||
user-select: none; | ||
padding: 3px; | ||
font-size: 10px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 30px; | ||
height: 30px; | ||
position: absolute; | ||
left: 60%; | ||
top: 50%; | ||
} | ||
|
||
.separator { | ||
border-top: 1px solid #979797; | ||
opacity: 0.5; | ||
width: 95%; | ||
margin: 22px 0; | ||
} | ||
|
||
.secret-info { | ||
border: 1px #969696 solid; | ||
border-radius: 2px; | ||
display: flex; | ||
flex-direction: column; | ||
margin: 6px 9px; | ||
} | ||
|
||
.secret-info-header { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
margin: 6px 9px; | ||
} | ||
|
||
.secret-info-details { | ||
display: flex; | ||
flex-direction: column; | ||
margin: 6px 9px; | ||
} | ||
|
||
.secret-info-details > span > strong { | ||
width: 5vw; | ||
} | ||
|
||
.social-networks { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
margin-bottom: 24px; | ||
} | ||
|
||
.social-networks > a { | ||
margin: 0 15px; | ||
} | ||
|
||
.social-networks > a > div > svg { | ||
width: 20px; | ||
height: 20px; | ||
} | ||
|
||
.footer-text { | ||
font-style: italic; | ||
opacity: 0.5; | ||
font-weight: normal; | ||
width: 100%; | ||
display: flex; | ||
align-self: center; | ||
justify-content: center; | ||
} | ||
|
||
a.checkmarx, | ||
a.checkmarx:visited, | ||
a.checkmarx:hover, | ||
a.checkmarx:active { | ||
cursor: pointer; | ||
font-weight: bold; | ||
text-decoration: underline; | ||
color: #fff; | ||
opacity: 0.8; | ||
} | ||
|
||
.hide { | ||
display: none; | ||
} | ||
|
||
summary { | ||
cursor: pointer; | ||
user-select: none; | ||
font-size: 18px; | ||
font-weight: bold; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>2MS Scan Result</title> | ||
</head> | ||
<style> | ||
{{ includeCSS }} | ||
</style> | ||
<body> | ||
{{ includeLogo }} | ||
<div class="container"> | ||
<div class="report-header-footer"> | ||
<span class="title"> | ||
2MS | ||
<span>REPORT</span> | ||
</span> | ||
</div> | ||
|
||
<div class="run-info"> | ||
<span style="flex-basis:100%" id="scan-paths"><strong>Total items scanned:</strong> {{ .TotalItemsScanned }}</span> | ||
<span style="flex-basis:100%" id="scan-paths"><strong>Total serets found:</strong> {{ .TotalSecretsFound }}</span> | ||
</div> | ||
<hr class="separator"> | ||
|
||
{{ range $file, $secrets := .Results }} | ||
|
||
<div class="secret-info"> | ||
<h3>{{ $file }}</h3> | ||
|
||
<ul> | ||
{{ range $index, $secret := $secrets }} | ||
|
||
<div class="secret-info-details"> | ||
<span><strong>ID:</strong> {{ .ID }}</span> | ||
<span><strong>Source:</strong> {{ .Source }}</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of the times, the Do you think we can make it a link when it is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looking into it |
||
<span><strong>Description:</strong> {{ .Description }}</span> | ||
<span><strong>Start Line:</strong> {{ .StartLine }}</span> | ||
<span><strong>End Line:</strong> {{ .EndLine }}</span> | ||
<span><strong>Start Column:</strong> {{ .StartColumn }}</span> | ||
<span><strong>End Column:</strong> {{ .EndColumn }}</span> | ||
<span><strong>Value:</strong> {{ .Value }}</span> | ||
</div> | ||
|
||
{{ end }} | ||
</ul> | ||
</div> | ||
|
||
{{ end }} | ||
<hr class="separator"> | ||
<div class="social-networks"> | ||
<a href="https://github.com/Checkmarx/2ms/" rel="noopener" target="_blank"> | ||
<div>{{ includeSVG }}</div> | ||
</a> | ||
</div> | ||
<div class="report-header-footer"> | ||
<span class="footer-text">The 2MS project is powered by <a href="https://www.checkmarx.com/" class="checkmarx" rel="noopener" target="_blank">Checkmarx</a>, global leader of Application Security Testing</span> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to break the line (
overflow-wrap: anywhere
)Also, I think putting it inside a
code
block will help.