@eurekadevsecops/radar 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eurekadevsecops/radar",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "Radar is an open-source orchestrator of security scanners.",
5
5
  "homepage": "https://www.eurekadevsecops.com/radar",
6
6
  "keywords": [
@@ -150,8 +150,8 @@ module.exports = {
150
150
  }
151
151
 
152
152
  // Send telemetry: git metadata.
153
+ const metadata = git.metadata(target)
153
154
  if (telemetry.enabled && scanID) {
154
- const metadata = git.metadata(target)
155
155
  await telemetry.send(`scans/:scanID/metadata`, { scanID }, { metadata })
156
156
  await telemetry.sendSensitive(`scans/:scanID/metadata`, { scanID }, { metadata })
157
157
  }
@@ -173,7 +173,7 @@ module.exports = {
173
173
 
174
174
  // Transform scan findings: treat warnings and notes as errors, and normalize location paths.
175
175
  if (escalations) results.sarif = SARIF.transforms.escalate(results.sarif, escalations)
176
- SARIF.transforms.normalize(results.sarif, target)
176
+ SARIF.transforms.normalize(results.sarif, target, metadata, git.root(target))
177
177
 
178
178
  // Write findings to the destination SARIF file.
179
179
  if (outfile) fs.writeFileSync(outfile, JSON.stringify(results.sarif))
@@ -84,6 +84,23 @@ git rev-list --abbrev=4 --abbrev-commit --all | \
84
84
  }
85
85
  }
86
86
 
87
+ function root(folder) {
88
+ try {
89
+ // Get the full OS path to the root of the repo.
90
+ const root = execSync('git rev-parse --show-toplevel', { cwd: folder }).toString().trim()
91
+ return root
92
+ } catch (error) {
93
+ return {
94
+ type: 'error',
95
+ error: {
96
+ code: 'E_GIT_METADATA',
97
+ details: error
98
+ }
99
+ }
100
+ }
101
+ }
102
+
87
103
  module.exports = {
88
- metadata
104
+ metadata,
105
+ root
89
106
  }
@@ -1,21 +1,33 @@
1
1
  const path = require('node:path')
2
- module.exports = (sarif, dir) => {
2
+ module.exports = (sarif, dir, git, root) => {
3
3
  // Normalize findings.
4
4
  for (const run of sarif.runs) {
5
- if (!run.results) continue
6
- for (const result of run.results) {
7
5
 
8
- // Find paths in the finding description and make them relative to the scan directory.
9
- if (result?.message?.text) result.message.text = result.message.text.replace('/app/', '')
6
+ // Record the source repo location and the relative target subfolder within the repo.
7
+ run.originalUriBaseIds = {
8
+ "SOURCE": {
9
+ "uri": git.repo.url.https,
10
+ "description": "Source origin for the target being scanned (ie. git repo URL)."
11
+ },
12
+ "TARGET": {
13
+ "uri": `${path.relative(root, dir)}`,
14
+ "uriBaseId": "SOURCE",
15
+ "description": "Scan target (subfolder) within the source repo or folder."
16
+ }
17
+ }
10
18
 
11
- // Make all physical locations for the result relative to the scan directory.
19
+ // Make all physical locations for the result relative to the scan directory.
20
+ if (!run.results) continue
21
+ for (const result of run.results) {
12
22
  for (const location of result.locations) {
13
23
  if (location.physicalLocation?.artifactLocation?.uri?.startsWith('/app')) {
14
24
  let file = path.relative('/app', location.physicalLocation.artifactLocation.uri)
25
+ if (result?.message?.text) result.message.text = result.message.text.replace(location.physicalLocation.artifactLocation.uri, file)
15
26
  location.physicalLocation.artifactLocation.uri = file
16
27
  }
17
28
  else if (location.physicalLocation?.artifactLocation?.uri?.startsWith('/')) {
18
29
  let file = path.relative('/', location.physicalLocation.artifactLocation.uri)
30
+ if (result?.message?.text) result.message.text = result.message.text.replace(location.physicalLocation.artifactLocation.uri, file)
19
31
  location.physicalLocation.artifactLocation.uri = file
20
32
  }
21
33
  }