Skip to main content

JavaScript/TypeScript

This article shows you how to analyze your applications written in JavaScript or TypeScript (including those that use the Angular, React.js, and Vue.js frameworks) using Qwiet AI by Harness. It assumes that you have already set up and authenticated with Qwiet.

note

Qwiet offers sample applications that you can use to run and test Qwiet AI by Harness. They also include functioning configuration files to demonstrate how you can leverage GitHub Actions to automate code analysis whenever you open a new Pull Request (PR).

Requirements

See Prerequisites for more information.

Analyzing your JavaScript application

caution

--js is deprecated. Use --jssrc instead — it requires no build step and is the preferred way to analyze JavaScript and TypeScript applications.

To analyze your JavaScript application, run:

# Ensure node_modules does not exist
sl analyze --app <name> --js [<path>]
ParameterDescription
--app <name>The name of the application to be analyzed (maximum length: 100 characters)
--jsThe flag identifying the application's language
<path>The path to the application directory

See the CLI reference for additional sl analyze options.

SCA

To identify open-source vulnerabilities, Qwiet AI by Harness automatically searches for build manifests in the project path you provided when running sl analyze. However, depending on how your project repo is structured, you may need to provide --oss-project-dir <project-path> so that Qwiet AI by Harness can identify where your dependencies are located.

Tagging results with your branch name

To include the branch name in your Qwiet AI by Harness results, allowing you to distinguish one set of results from another, add the following to your invocation of Qwiet:

sl analyze --tag branch=`git symbolic-ref --short HEAD`

If you're working in a GitHub environment (e.g., GitHub Actions), you can also use --tag branch=${{ github.head_ref }} to populate your branch name.

If you don't provide a branch name, but Qwiet detects one available in your environment, it will use that name.

Additional parameters

The analysis accepts additional parameters after a double hyphen --.

For example, the following ignores minified JavaScript sources in the analysis and uses a custom package.json in the config sub-directory:

sl analyze --app Xyz --js /path/to/my/typescript-project -- --ignore-minified --package-json /path/to/my/typescript-project/config/package.json

Such parameters, if valid, are passed directly to the JavaScript plugin.

ParameterDescription
--package-json <path>The custom path to package.json (by default, Qwiet AI by Harness looks for the file in the JavaScript project directory)
--output <value>The CPG output file name (defaults to cpg.bin.zip if none provided)
--no-tsExclude TypeScript sources from the analysis (by default, Qwiet AI by Harness includes Typescript sources)
--no-babelExclude Babel sources in the analysis (by default, Qwiet AI by Harness includes Babel sources)
--no-vue-jsExclude Vue.js sources in the analysis (by default, Qwiet AI by Harness includes Vue.js sources)
--no-nuxt-jsExclude Nuxt.js sources in the analysis (by default, Qwiet AI by Harness includes Nuxt.js sources)
--no-templatesExclude EJS and Pug template sources in the analysis (by default, Qwiet AI by Harness includes EJS and Pug template sources)
--include-minifiedInclude minified Javascript sources (e.g., filenames ending with -min.js or .min.js) in the analysis (by default, Qwiet AI by Harness excludes all such sources)
--include-testsInclude test files (typically required for sample vulnerable apps, such as OWASP Juice Shop)
--exclude <path>Exclude the specified file/directory during code analysis; the path provided must either be an absolute path or a relative path to the project directory; can be specified multiple times
--exclude-htmlExclude HTML files from the analysis
--exclude-regex <value>A regex specifying the files to exclude during the analysis (the match is to the absolute file path), e.g., --exclude-regex ".*([-.])min\\.js" or `--exclude-regex ".*.(spec
--exclude-private-depsExclude private modules/dependencies in node_modules (defaults to false)
--all-dependenciesInstall all project dependencies during transpilation. May result in slow execution times depending on your project setup and network speed. Defaults to false. If this option is not used, only a minimal set of dependencies relevant for transpilation is installed (and may result in faster execution times).
--private-deps-ns <dep1>,<dep2>,...Additional private dependencies you would like to be analyzed from node_modules