snyk / snyk-to-html

export test reports from CLI to html
Other
87 stars 77 forks source link

Not running in project directory causes errors to be printed and code snippets parsed incorrectly #128

Open WillBartee opened 2 years ago

WillBartee commented 2 years ago

Current Behavior

Multiple errors are printed to the console for each vulnerability when running snyk-to-html outside of the scanned projects root directory and using the output of snyk code test....

In addition to the errors, the "Data Flow" portion of the resulting HTML does not correctly display the vulnerable code.

Tested versions

How to Reproduce

npm install -g snyk-to-html@latest
mkdir scratch
cd scratch
npm init -y
npm install axios
cat <<EOF > index.js
import axios from 'axios'

function fail(req, res) {
  return res.status(401).send(req.query)
}
EOF
snyk code test --json > ../snyk.json
cd ..
snyk-to-html -i snyk.json -o snyk.html

Example Output

$ snyk-to-html -i snyk.json -o results.html
[Error: ENOENT: no such file or directory, open '/Users/will/workspaces/index.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/will/workspaces/index.js'
}
[Error: ENOENT: no such file or directory, open '/Users/will/workspaces/index.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/will/workspaces/index.js'
}
[Error: ENOENT: no such file or directory, open '/Users/will/workspaces/index.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/will/workspaces/index.js'
}
[Error: ENOENT: no such file or directory, open '/Users/will/workspaces/index.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/will/workspaces/index.js'
}
Vulnerability snapshot saved at results.html
Screen Shot 2022-05-09 at 4 20 12 PM

Expected/Desired Behavior

cmanaila60 commented 2 years ago

+1 Versions: snyk-to-html: v2.3.2 snyk: 1.790.0

I am seeing the same behavior. Although the previous version of snyk-to-html didn't have this issue 2.3.1

snyk code test scan_folder/ --sarif | snyk-to-html > report-code.html
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, open '/Users/Desktop/work/repos/salesforce/JiraIntegration.cls'
Emitted 'error' event on ReadStream instance at:
    at internal/fs/streams.js:147:14
    at FSReqCallback.oncomplete (fs.js:171:23) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/Desktop/work/repos/salesforce/JiraIntegration.cls'
}