Skip to content

Commit

Permalink
Escape Job-Id for url
Browse files Browse the repository at this point in the history
  • Loading branch information
attiasas committed Dec 26, 2024
1 parent 74520fe commit d764c71
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<pre>44 Security issues are grouped by CVE number:&Tab;44 SCA<br><br><div style="display: flex; align-items: center; text-align: center">❗️ 33 Critical</div><br><div style="display: flex; align-items: center; text-align: center">🟡 11 Low</div><br><a href="https://test-platform-url.jfrog.io/ui/onDemandScanning/3d90ec4b-cf33-4846-6831-4bf9576f2235?gh_job_id=some-job-id&gh_section=on_demand_scan">See the results of the scan in JFrog</a></pre>
<pre>44 Security issues are grouped by CVE number:&Tab;44 SCA<br><br><div style="display: flex; align-items: center; text-align: center">❗️ 33 Critical</div><br><div style="display: flex; align-items: center; text-align: center">🟡 11 Low</div><br><a href="https://test-platform-url.jfrog.io/ui/onDemandScanning/3d90ec4b-cf33-4846-6831-4bf9576f2235?gh_job_id=some%20job%20id&gh_section=on_demand_scan">See the results of the scan in JFrog</a></pre>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<pre>24 Security Issues:&Tab;24 SCA<br><br><div style="display: flex; align-items: center; text-align: center">🔴 3 High</div><br><div style="display: flex; align-items: center; text-align: center">🟠 1 Medium</div><br><div style="display: flex; align-items: center; text-align: center">⚪️ 20 Unknown</div><br><a href="https://test-more-info-url.jfrog.io/?gh_job_id=some-job-id&gh_section=build">See the results of the scan in JFrog</a></pre>
<pre>24 Security Issues:&Tab;24 SCA<br><br><div style="display: flex; align-items: center; text-align: center">🔴 3 High</div><br><div style="display: flex; align-items: center; text-align: center">🟠 1 Medium</div><br><div style="display: flex; align-items: center; text-align: center">⚪️ 20 Unknown</div><br><a href="https://test-more-info-url.jfrog.io/?gh_job_id=some%20job%20id&gh_section=build">See the results of the scan in JFrog</a></pre>
2 changes: 1 addition & 1 deletion tests/testdata/output/jobSummary/violations_analytics.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<pre>watches: <br>watch1, watch2, watch3, watch4<br>watch5</pre><br><pre>23 Policy Violations:&Tab;17 Security&Tab;2 Operational&Tab;1 License&Tab;3 Secrets<br><br><div style="display: flex; align-items: center; text-align: center">❗️ 8 Critical (2 Not Applicable)</div><br><div style="display: flex; align-items: center; text-align: center">🔴 6 High</div><br><div style="display: flex; align-items: center; text-align: center">🟠 3 Medium</div><br><div style="display: flex; align-items: center; text-align: center">🟡 5 Low (3 Not Applicable)</div><br><div style="display: flex; align-items: center; text-align: center">⚪️ 1 Unknown</div><br><a href="https://test-more-info-url.jfrog.io/scan-descendants/master?repoId=10gh_job_id=some-job-id&gh_section=on_demand_scan">See the results of the scan in JFrog</a></pre>
<pre>watches: <br>watch1, watch2, watch3, watch4<br>watch5</pre><br><pre>23 Policy Violations:&Tab;17 Security&Tab;2 Operational&Tab;1 License&Tab;3 Secrets<br><br><div style="display: flex; align-items: center; text-align: center">❗️ 8 Critical (2 Not Applicable)</div><br><div style="display: flex; align-items: center; text-align: center">🔴 6 High</div><br><div style="display: flex; align-items: center; text-align: center">🟠 3 Medium</div><br><div style="display: flex; align-items: center; text-align: center">🟡 5 Low (3 Not Applicable)</div><br><div style="display: flex; align-items: center; text-align: center">⚪️ 1 Unknown</div><br><a href="https://test-more-info-url.jfrog.io/scan-descendants/master?repoId=10gh_job_id=some%20job%20id&gh_section=on_demand_scan">See the results of the scan in JFrog</a></pre>
3 changes: 2 additions & 1 deletion utils/results/conversion/sarifparser/sarifparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sarifparser

import (
"fmt"
"net/url"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -775,7 +776,7 @@ func getAnalyticsHiddenPixel(baseUrl string, resultOfSubScan utils.SubScanType)
return fmt.Sprintf(
"![](%sui/api/v1/u?s=1&m=2&job_id=%s&run_id=%s&git_repo=%s&type=%s)",
baseUrl,
jobId,
url.PathEscape(jobId),
runId,
gitRepo,
resultOfSubScan.String(),
Expand Down
13 changes: 7 additions & 6 deletions utils/results/output/securityJobSummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package output
import (
"errors"
"fmt"
"net/url"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -542,13 +543,13 @@ func getJfrogUrl(index commandsummary.Index, args ResultSummaryArgs, summary *fo
}

// adds analytics query params to the url if running in Github
func addAnalyticsQueryParamsIfNeeded(url string, index commandsummary.Index) string {
func addAnalyticsQueryParamsIfNeeded(platformUrl string, index commandsummary.Index) string {
githubJobId := os.Getenv(utils.JfrogExternalJobIdEnv)
if githubJobId == "" {
// Not running in Github no need to add analytics
return url
return platformUrl
}
suffixValues := []string{fmt.Sprintf("gh_job_id=%s", githubJobId)}
suffixValues := []string{fmt.Sprintf("gh_job_id=%s", url.PathEscape(githubJobId))}
// Add section analytics
indexValue := "gh_section="
switch index {
Expand All @@ -559,10 +560,10 @@ func addAnalyticsQueryParamsIfNeeded(url string, index commandsummary.Index) str
}
suffixValues = append(suffixValues, indexValue)
// Add the suffix to the url
if strings.Contains(url, "?") {
return fmt.Sprintf("%s%s", url, strings.Join(suffixValues, "&"))
if strings.Contains(platformUrl, "?") {
return fmt.Sprintf("%s%s", platformUrl, strings.Join(suffixValues, "&"))
}
return fmt.Sprintf("%s?%s", url, strings.Join(suffixValues, "&"))
return fmt.Sprintf("%s?%s", platformUrl, strings.Join(suffixValues, "&"))
}

func (mg DynamicMarkdownGenerator) generateResultsMarkdown(violations bool, moreInfoUrl string, content *formats.ScanResultSummary) (markdown string) {
Expand Down
2 changes: 1 addition & 1 deletion utils/results/output/securityJobSummary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func TestGenerateJobSummaryMarkdown(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
cleanUps := []func(){}
if testCase.GithubEnvs {
cleanUps = append(cleanUps, clientTests.SetEnvWithCallbackAndAssert(t, utils.JfrogExternalJobIdEnv, "some-job-id"))
cleanUps = append(cleanUps, clientTests.SetEnvWithCallbackAndAssert(t, utils.JfrogExternalJobIdEnv, "some job id"))
cleanUps = append(cleanUps, clientTests.SetEnvWithCallbackAndAssert(t, utils.JfrogExternalRunIdEnv, "some-run-id"))
cleanUps = append(cleanUps, clientTests.SetEnvWithCallbackAndAssert(t, utils.JfrogExternalGitRepoEnv, "some-repo"))
}
Expand Down

0 comments on commit d764c71

Please sign in to comment.