Snyk Code CLI support now in public beta
Frank Fischer
2021年9月21日
0 分で読めますSnyk is on the mission to make Static Application Security Testing (SAST) tools work for developers throughout the DevOps pipeline. Snyk Code scans in real time with high accuracy — and it does it right from the tools and workflows developers are already using. For example, the IDE plugins for IntelliJ, PyCharm, WebStorm, and Visual Studio Code make it easy to code, scan and fix even before code hits the version management. And with the web-based UI, developers can scan legacy code or perform a code review.
Adding to all that, we are happy to announce that Snyk Code is now part of the Snyk command-line interface (Snyk CLI) in a public beta. Now you can easily make Snyk Code part of the CI/CD process, with the flexibility to trigger a scan and work with the results in an automatic fashion.
Snyk provides a CLI to interact with any element of the Snyk platform. Snyk Code extends the functionality of the existing CLI. This article is going to be a “Getting Started” experience, for a deeper dive, I encourage you to explore our Snyk Code CLI documentation.
As a quick reminder, the CLI support is in beta for now. Please give it a try and give us feedback so we can make it even better.
Installing and Configuring the Snyk CLI
The Snyk CLI is a Node.js application, and as such can be hosted on any system supporting Node.js. It is also easy to install and configure.
You can use npm to install it by running: npm install -g snyk
For more ways to install it, and more information about the npm installation, check out our full Snyk Code CLI documentation.
After installation, the next step is to authenticate which can be achieved by calling: snyk auth.
This will start an authentication process and result in an identification token for you being stored to be used with the CLI from now on.
Pro tip: The CLI tests for updates every time it’s run. It will notify the user to update showing the necessary command. To make sure to have the latest version, you can also update manually by calling npm update -g snyk.
Testing a project or folder
Calling a Snyk Code scan using the CLI looks like this: snyk code test [my-folder-path]
If you do not provide the path parameter, the CLI will scan the current folder. And yes, it will iterate through the directory tree and scan its contents. There are lots of more commands and parameters possible, which you can find in our documentation.
For existing CLI users, please note that this beta does not support the monitor command for Snyk Code.
Note: The CLI will bundle and upload supported source code files for scan into Snyk. So please be advised that while both data-in-motion and data-at-rest is encrypted, source code will leave your premises. Make sure you are fine with this before running the CLI on a given repository.
Result format options
There are three ways the CLI can report its result. First, and a good way to get started with the CLI, is by simply calling it. This will return a report in a human-readable format.
Severity level is color-coded and the result provides an explanation of the vulnerability as well as a recommended remediation.
Pro tip: As Snyk Code is extremely fast, take any project (or cloned open source repo in that regard) and simply run the scan to check that the system is working.
Next, the CLI provides a data format called SARIF by calling snyk code test --sarif:
This output is rich and contains everything — and even a bit more — that you can see in the Snyk Code frontend. It even contains the example fixes and priority score.
Pro Tip: Grab a cup of coffee and have a good look around in the SARIF file. As it is JSON, it is actually not that hard to understand. It contains a wealth of information and I promise you will have a lot of ideas on how to use it in your processes or to gather some stats.
Finally, the CLI provides an exit code that can be used to steer, for example, a CI/CD process. Here are the exit codes to expect:
3: failure, no supported projects found
2: failure, try to re-run command
1: action needed, vulnerabilities found
0: success, no vulnerabilities found
By using the parameter --severity-threshold=<low|medium|high> in your call, you can filter on severity level.
Try the Snyk Code CLI in beta
The CLI is a powerful tool and we want to invite everyone to join us in the public beta. Just make sure you have the latest Snyk CLI installed, Snyk Code is enabled for your org and give it a try. And since this is a beta, we’d love it if you helped us by using it and provided us feedback.
And if you’re new to Snyk, the first step is to have a Snyk Code-activated account on Snyk! Sign up for free today.
Capture the Flag を始める
バーチャル 101 ワークショップオンデマンドで、Capture the Flag の課題の解決方法をご覧ください。