capture section of the configuration file describes to Coverity on
Polaris how to locate the files that should be included in the analysis.
Coverity on Polaris captures files for analysis using the following techniques:
| Name | Description |
|---|---|
| Build | Coverity observes your project as it is built, determining which source files need analysis. |
| Filesystem | Allows users to explicitly tell Coverity on Polaris the files to include. |
| Coverity capture options | See options in table below. |
| Name | Description |
|---|---|
| idir capture | If you already have a valid idir directory, code previously analyzed by Coverity can be captured and sent to Coverity on Polaris for analysis. |
| Buildless | Captures by recursively searching for files under a specific project directory (project mode) or based on the file extension (source mode). |
| Auto-Capture | If enabled, it captures the current directory and that's treated as the project directory until explicitly specified. |
| Coverity Dynamic Analysis | Enables the Coverity dynamic analysis for webapp security
(cov-security-da). This the not a capture method. |
For each version of Coverity, Coverity on Polaris Supported Platforms, Languages, and Compilers (under Compatibility and Support Information) shows types of capture available for each supported language.
Build Capture
Build capture means that Coverity on Polaris observes your project as it is built, determining which source files need analysis. A build capture requires the build and clean commands.
Syntax
capture:
build:
cleanCommands:
- shell: [clean-command-component1, clean-command-component2, clean-command-component3...]
buildCommands:
- shell: [build-command-component1, build-command-component2, build-command-component3...]
coverity:
cov-build:
- "<--option1>"
- "<value1>"
- "<--option2>"[--option1, --option2]
skipFiles:
- "@File1"
- "File2"
cov-configure:
- "<--option1>"
- "<value1>"
- "<--option2>"
| Name | Description |
|---|---|
| cleanCommands | You must specify commands as they are entered in a command shell using commas to separate each argument. See examples for other language specific information. |
| buildCommmands | You must specify commands as they are entered in a command shell using commas to separate each argument. See examples for language specific information. |
| coverity | Allows you to use Coverity options for cov-build, skipFiles and cov-configure. These are optional and not automatically generated by the CLI. See table below for details. |
| Name | Description |
|---|---|
| cov-build |
You can specify Coverity build options in the polaris.yml configuration file by including options in a list or array. When an option requires an argument, use "option-value". Note that the CLI skips filesystem capture options that are passed in with
The provided cov-build value is passed directly to cov-build without any value validation. In case of any errors returned by Coverity, the same would be returned by Coverity on Polaris CLI. This |
| skipFiles | Excludes Subdirectories from a Build . You can skip files or directories by using an absolute path. For Windows, verify that the path separator is escaped. You can also use the Note the following limitations:
|
| cov-configure |
Allow users to pass cov-configure options, excluding compiler specific option, from polaris.yml. For example, they can skip Go files/directories. The |
Example for Build Capture
capture:
build:
cleanCommands:
- shell: [mvn, -B, -f, pom.xml, clean]
buildCommands:
- shell: [mvn, -B, -f, pom.xml, install]
coverity:
cov-build: [--disable-aspnetcompiler]
skipFiles:
- "@File1.java"
- "File2.java"
cov-configure: [--xml-option=prepend_arg@Go:--suppress_emit=value]
Examples for buildCommand and cleanCommand by language
Build Capture-C/C++
For a C or C++ application with a Makefile, make clean is a typical clean
command, and make is a typical build command.
capture:
build:
cleanCommands:
- shell: [make, -f, Makefile, clean]
buildCommands:
- shell: [make, -f, Makefile]
With this configuration, Coverity on Polaris cleans your project by running make -f
Makefile clean, then builds it using make -f Makefile.
Build Capture-C#
Note: If MSbuild.exe is not in the PATH, then its full location must be provided.
capture:
build:
cleanCommands:
- shell: [msbuild, NameOfYourProject.csproj, '/t:Clean']
buildCommands:
- shell: [msbuild, NameOfYourProject.csproj, '/t:Build']
Build Capture-Gradle
capture:
build:
cleanCommands:
- shell: [gradle, -b, build.gradle, --no-daemon, clean]
buildCommands:
- shell: [gradle, -b, build.gradle, --no-daemon, build]
Build Capture-Java/Maven Project
capture:
build:
cleanCommands:
- shell: [mvn, -B, -f, pom.xml, clean]
buildCommands:
- shell: [mvn, -B, -f, pom.xml, install]
Build Capture-Ant
capture:
build:
cleanCommands:
- shell: [ant, -f, build.xml, clean]
buildCommands:
- shell: [ant, -f, build.xml]
Build Capture-Swift
capture:
build:
cleanCommands:
- shell: [xcodebuild, -project, CryptoSwift.xcodeproj, clean]
buildCommands:
- shell: [xcodebuild, -project, CryptoSwift.xcodeproj, build]
Example for passing options to cov-build
capture:
build:
coverity:
cov-build: ["--cached-jars-file", "/tzy/swip-openapi-lib.d2gsjf8w.metadata"]
Examples for skipFiles
skipFiles with Perl regex argument
You can exclude files and directories from a build capture by using the skipFiles property and a Perl regex argument. Coverity on Polaris CLI uses this regex to generate a new compiler configuration, which will be used with cov-build for capture. Coverity does not compile the files or directories that match the regex argument.
capture:
build:
cleanCommands:
- shell: [mvn, -f, pom.xml, clean]
buildCommands:
- shell: [mvn, -f, pom.xml, install]
coverity:
skipFiles: ["regex1", "@java:regex2"]
The match is partial: use ^ and $ to match
boundaries.
The [@language] option specifies that the switch is to be added for
compiler variants within the given language. Valid values are:
- C
- C++
- Java
- CS
- ObjC
- ObjC++
The skipFiles settings in the preceding example include a search in Java
files, using "regex2" as a regular expression; the search for
"regex1" is not limited by the language contained in the files.
skipFiles with no cov-build
capture:
build:
buildCommands: []
cleanCommands: []
coverity:
cov-build: null
skipFiles:
- "<file1>"
- "<file2>"
skipFiles macOS/Linux example
capture:
build:
coverity:
skipFiles:
- "@java:AbstractLessonTest.java"
- "LabelDebuggerTest.java"
- "@java:/webgoat-container/src/test/java/org/owasp/webgoat/plugins/PluginTe[a-zA-z]*.java"
- "/webgoat-container/src/test/java/org/owasp/webgoat/util/LabelManager[a-zA-z]*Test.java"
Example for skipping Go files using cov-configure
In the example, the cov-configure command skips GO files.
capture:
build:
coverity:
cov-build: [--disable-aspnetcompiler]
skipFiles:
- "@File1.java"
- "File2.java"
cov-configure: [--xml-option=prepend_arg@Go:--suppress_emit=value]
Filesystem Capture
Filesystem captures directly from the disk. It does not require observing a build command, and it allows control over the directories or file names to be included or excluded in analysis.
This is useful for source code is not compiled or explicitly built. For example, JavaScript and Python are both interpreted at run time. Software written in these languages is never "built," so build capture does not apply. Likewise, in other cases, compiled build artifacts, such as Java WAR or EAR files, can provide valuable information during analysis.
Syntax
capture:
fileSystem:
language:
extensions: [extension]
files:
- directory: /directory
| Name | Description |
|---|---|
| extensions | For each file type, you can specify the applicable file extensions and
directories to include. You can also supply a regular expression of files to be
excluded. Directories are traversed recursively. Filesystem capture searches through
the specified directory and its subdirectories. You can specify multiple file
extensions, separated by commas. The following example configuration captures Python
files in the pysrc subdirectory with the extension
py. Note: The extensions field is optional. However, in the default polaris.yml, CLI specifies extensions for ears and wars to run cov-emit-java to emit jar files only if these files are available inside the project directory. The difference is, if the extension is not specified in these cases, then CLI will run cov-emit-java thinking that the wars and ears are available. However, for programming languages, it is not required to specify the extension until the user wants to capture only specific extensions for the respective language. |
| files |
The files setting of filesystem language can contain the following options: - file : Should be a relative path of a file to be included - directory : Should be a relative path of the directory to be included - includeRegex : regex to include files - excludeRegex : regex to exclude files |
| Type | Default Match |
|---|---|
| Java-related files (Android configuration, JSP) | N/A |
| JavaScript source | *.js |
| TypeScript source | *.ts |
| PHP source | *.php |
| Python source | *.py |
| Ruby source | *.rb |
| Java Enterprise Archive (ears) | *.ear |
| Java Web Application Archive (wars) | *.war |
Generic Examples
capture:
fileSystem:
ears:
extensions: [ear]
files:
- directory: ${project.projectDir}
java:
files:
- directory: ${project.projectDir}
javascript:
files:
- directory: "."
- includeRegex: "han.*\\.js"
- excludeRegex: ""
extensions:
- "js"
- "xsjs"
- "xsjslib"
- "map"
- "html"
- "htm"
- "vue"
- "jsx"
typescript:
files:
- directory: ${project.projectDir}
php:
files:
- directory: ${project.projectDir}
python:
files:
- directory: ${project.projectDir}
ruby:
files:
- directory: ${project.projectDir}
wars:
extensions: [war]
files:
- directory: ${project.projectDir}
Python and JavaScript Example
The following example configuration captures Python files in the pysrc subdirectory with the extension py.
In addition, JavaScript files with extension js in the subdirectory widget-main are captured with the exception of files that begin with mock.
capture:
fileSystem:
python:
extensions: [py]
files:
- directory: pysrc
javascript:
extensions: [js]
files:
- directory: widget-main
excludeRegex: '[/\\]mock.*[.]js$'
Java Source Files ExampleFilesystem capture for Java source files is a special case because you must remove the build section of the configuration file in addition to configuring the capture section.
The following is an example of setting up the capture section for Java filesystem capture.capture:
fileSystem:
java:
files:
- directory: ${project.projectDir}
Using this configuration and removing the build section tells Coverity on Polaris to use
the Coverity command cov-configure --javafs instead of
cov-configure --java when running Coverity analysis.
idir Capture
If you already have a valid idir directory (you've analyzed the project with Coverity previously) and don't want to wait to capture source files again, you can use idirCapture. Coverity on Polaris CLI checks the idir for compatibility with your current version of Coverity.
Syntax
capture:
coverity:
idirCapture:
idirPath: "/path/to/existing/idir"
| Name | Description |
|---|---|
| idirPath | Path to existing idir (absolute or relative path to the project directory). |
Buildless Capture
Buildless capture works by recursively searching for:
- Project files under a specific project directory (Project Mode).
- Source files based on the file extension (Source Mode). Searches for known source files where the language is determined by filename extension.
Only one mode can be specified for buildless capture; the options are project and source. Specifying more than one mode results in an error message.
The Supported Platforms, Languages, and Compilers (under Compatibility and Support Information) show the languages supported for buildless capture. You can specify the languages you want to capture and you can exclude specific build files as needed.
Syntax
capture:
coverity:
buildless:
project:
languages:
- "java"
- "javascript"
sourceMode:
sourceDirOptions:
- "<--option1>"
- "<value1>"
- "<--option2>"
- "<value2>"
sourceDir: "source/directory/path/"
| Name | Description |
|---|---|
| languages | See "Language Support for Coverity on Polaris" for your version of Coverity. |
| excludes | Indicates that the project file should be excluded from capture. If this path is absolute, it is used as-is; otherwise, it is understood as relative to the project directory. |
| Name | Description |
|---|---|
| sourceDirOptions | Accepts source-dir parameters as an array of strings. For more
information, refer to the Coverity Command Reference. Not required. |
| sourceDir | Accepts the source directory name as a string. Not required. |
Examples
In the following example, only Java and JavaScript files are captured. Files associated with build.gradle are excluded.
capture:
coverity:
buildless:
project:
languages:
- "java"
- "javascript"
excludes:
- build.gradle
This example shows TypeScript captured in Project Mode.
capture:
build:
cleanCommands:
- shell: [mvn, -B, -f, pom.xml, clean]
buildCommands:
- shell: [mvn, -B, -f, pom.xml, install]
coverity:
buildless:
project:
languages:
- "typescript"
analyze:
mode: central
install:
coverity:
version:
serverUrl: https://qa.dev.cop.blackduck.com/
The following example shows how to set up buildless capture with source mode .
capture:
coverity:
buildless:
sourceMode:
sourceDirOptions:
- "--language"
- "java"
sourceDir:"source/direcotry/path/
Auto-Capture
The auto-capture option should be placed in the polaris.yml file, under
the Coverity capture settings as shown below.
Syntax
capture:
coverity:
autoCapture: enable | disable
| Name | Description |
|---|---|
| autoCapture | Enable/disable auto-capture (disabled by default). Note:
- The Supported Platforms, Languages, and Compilers (under Compatibility and Support Information) shows the languages supported for auto-capture. Running Clean commands Coverity on Polaris CLI always runs the clean commands when they are specified in the polaris.yml file. Multiple Build commands Coverity on Polaris CLI provides you the capability to add multiple build commands inside the polaris.yml configuration file. If you use multiple build commands, autocapture will run once per command. |
Coverity Dynamic Analysis for web app security
The cov-security-da command runs a dynamic analysis of Java and .NET
bytecode and a separate dynamic analysis of JavaScript templates. The Java/.NET analysis
invokes certain string-manipulation functions to detect whether they correctly escape or
sanitize unsafe values. The JavaScript template analysis dynamically renders observed
template files to detect interpolation sites that could be vulnerable to XSS.
Syntax
capture:
coverity:
cov-security-da: "enable" | "disable"
| Name | Description |
|---|---|
| cov-security-da | Enable/disable this command. Disabled by default. |