Find JavaScript cyber-vulnerabilities for free
Tags: javascript, react, angular, webdev
Published: 2022-10-11 03:36:54

According to a [2022 Stack Overflow survey](https://survey.stackoverflow.co/2022/#most-popular-technologies-language-prof) of more than 50K professional developers, JavaScript is the top programming language of choice. Finding cybersecurity risks in JavaScript code is critical for developers working with modern web technologies. CodeSec by Contrast can help developers find and fix risks in their code, like cross-site scripting (XSS) or broken access control vulnerabilities.

CodeSec is Contrast Security's free developer security motion that is very easy to install with either Homebrew, npm or straight from binary. You can find [CodeSec at Contrast’s Developer Central online portal](https://www.contrastsecurity.com/developer/codesec/?hsLang=en-us).

Once CodeSec is installed on your machine and you have authenticated with either your GitHub or Google account, you can start scanning your JavaScript project for vulnerabilities with the command **_contrast scan_**. Scan will look up to three folders deep in your project for either a single *.js file to scan or a *.zip file of JavaScript files to scan. At first glance, this might seem strange, but ZIP format is just a more compact way to upload the code files that need to be examined.

In this article, we will assume that you have a modern JavaScript project with multiple code files, such as the “browser-test-bench” project in the below screenshots.

First, let’s zip the project’s JavaScript files. The zip command-line utility tool provides arguments for recursively searching through your project’s folders to find JavaScript files while also excluding certain folders, such as _**node_modules**_.

**Run Command** (from within your project folder):
_**zip -R to-be-scanned “*.js” -x “node_modules”**_

There are, of course, plenty of variations of this command that you could do to make the ZIP file: 

- You could name it something other than “to-be-scanned.zip,” such as the day’s date or a company-specific format. 
- Your project may not have a **node_modules** folder full of third-party libraries but may have a **lib** folder instead. 
- Additionally, you may not want to do a recursive search through the project’s folders for JavaScript files. Instead, you might want to specify zipping only certain files instead. 

Whatever your needs, the ZIP command’s man page (accessible in your terminal with the command **_man zip_**), and searching Stack Overflow are both great resources for learning about the ZIP tool’s options.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ucu3nlqasy92o82dlwnx.png)

_Creating to-be-scanned.zip of project JavaScript files
_
Once the ZIP file of the project’s JavaScript files is created, you are ready to run the command to scan for vulnerabilities.

**Run Command** (from within your project folder): _**contrast scan**_

Contrast Security’s Scan product is a Static Analysis Security Testing (SAST) cybersecurity tool. This means that Scan examines static code files, as opposed to Contrast’s more dynamic analysis tools like [Assess](https://www.contrastsecurity.com/contrast-assess?hsLang=en-us) (an Interactive Application Security Testing [IAST] tool) and [Protect](https://www.contrastsecurity.com/contrast-protect?hsLang=en-us) (a Runtime Application Protection tool).

When the scan command starts, it looks for the ZIP file that we made earlier. Next, CodeSec uploads the ZIP file in order to analyze its JavaScript code files for vulnerabilities.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ehwr5x6hzitshkwr21w.png)

_In-progress cybersecurity analysis for JavaScript files 
_
Once the Scan analysis is complete, CodeSec lists the vulnerabilities found. The vulnerabilities are sorted with the most critical-to-fix ones at the top and then descending in severity. Each vulnerability is described, has the file and line number of its occurrence listed, and provides resources for learning more about that cybersecurity risk. All of the information in the Scan analysis results can help you find and fix cybersecurity vulnerabilities before they become production-level incidents that your project’s support team needs to triage.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erkctufqgl1umzutv9d4.png)

CodeSec’s Scan analysis results

**Pro tip #1:** Many modern front-end JavaScript projects minify their code for deployment in production. Minified JavaScript is not human-readable and, often, all on a single line, which means that the file and line number listing for a vulnerability in the analysis results won’t be very useful for you. Instead, try running **_contrast scan_** against your preminified code.

**Pro tip #2:** Because CodeSec is a command-line tool, you can incorporate Scan into your automated software processes, like we showed in our earlier article on using [CodeSec with Git hooks](https://www.contrastsecurity.com/security-influencers/how-to-scan-for-cybersecurity-risks-on-every-commit-with-codesec-git-hooks?hsLang=en-us).

## Conclusion
CodeSec’s free vulnerability scanning support can help you find cybersecurity risks in your JavaScript project. CodeSec is a free way for developers to provide high-value software for this popular web technology choice.

[Get started today for free.](https://www.contrastsecurity.com/developer?hsLang=en-us)