2019-10-12 21:52:04 +05:30
---
2020-06-23 00:09:42 +05:30
stage: Secure
group: Static Analysis
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
2019-10-12 21:52:04 +05:30
type: reference, howto
---
2019-09-30 21:07:59 +05:30
# Static Application Security Testing (SAST) **(ULTIMATE)**
2019-07-31 22:56:46 +05:30
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/3775) in [GitLab Ultimate](https://about.gitlab.com/pricing/) 10.3.
2019-07-31 22:56:46 +05:30
NOTE: **4 of the top 6 attacks were application based.**
Download our whitepaper,
["A Seismic Shift in Application Security" ](https://about.gitlab.com/resources/whitepaper-seismic-shift-application-security/ )
to learn how to protect your organization.
## Overview
2020-05-24 23:13:21 +05:30
If you're using [GitLab CI/CD ](../../../ci/README.md ), you can analyze your source code for known
2019-07-31 22:56:46 +05:30
vulnerabilities using Static Application Security Testing (SAST).
2020-04-22 19:07:51 +05:30
You can take advantage of SAST by doing one of the following:
- [Including the SAST template ](#configuration ) in your existing `.gitlab-ci.yml` file.
- Implicitly using [Auto SAST ](../../../topics/autodevops/stages.md#auto-sast-ultimate ) provided by
[Auto DevOps ](../../../topics/autodevops/index.md ).
2019-07-31 22:56:46 +05:30
GitLab checks the SAST report, compares the found vulnerabilities between the
source and target branches, and shows the information right on the merge request.
2020-05-24 23:13:21 +05:30
![SAST Widget ](img/sast_v13_0.png )
2019-07-31 22:56:46 +05:30
The results are sorted by the priority of the vulnerability:
1. Critical
1. High
1. Medium
1. Low
1. Unknown
1. Everything else
2020-05-24 23:13:21 +05:30
NOTE: **Note:**
A pipeline consists of multiple jobs, including SAST and DAST scanning. If any job fails to finish for any reason, the security dashboard won't show SAST scanner output. For example, if the SAST job finishes but the DAST job fails, the security dashboard won't show SAST results. The analyzer will output an [exit code ](../../../development/integrations/secure.md#exit-code ) on failure.
2019-07-31 22:56:46 +05:30
## Use cases
- Your code has a potentially dangerous attribute in a class, or unsafe code
that can lead to unintended code execution.
- Your application is vulnerable to cross-site scripting (XSS) attacks that can
be leveraged to unauthorized access to session data.
## Requirements
2020-05-24 23:13:21 +05:30
To run SAST jobs, by default, you need GitLab Runner with the
[`docker` ](https://docs.gitlab.com/runner/executors/docker.html ) or
[`kubernetes` ](https://docs.gitlab.com/runner/install/kubernetes.html ) executor.
If you're using the shared Runners on GitLab.com, this is enabled by default.
2019-07-31 22:56:46 +05:30
2020-05-24 23:13:21 +05:30
Beginning with GitLab 13.0, Docker privileged mode is necessary only if you've [enabled Docker-in-Docker for SAST ](#enabling-docker-in-docker ).
2019-12-21 20:55:43 +05:30
2020-03-13 15:44:24 +05:30
CAUTION: **Caution:** Our SAST jobs currently expect a Linux container type. Windows containers are not yet supported.
2019-12-04 20:38:33 +05:30
CAUTION: **Caution:**
2020-05-24 23:13:21 +05:30
If you use your own Runners, make sure the Docker version installed
2020-04-22 19:07:51 +05:30
is **not** `19.03.0` . See [troubleshooting information ](#error-response-from-daemon-error-processing-tar-file-docker-tar-relocation-error ) for details.
2019-12-04 20:38:33 +05:30
2019-07-31 22:56:46 +05:30
## Supported languages and frameworks
The following table shows which languages, package managers and frameworks are supported and which tools are used.
| Language (package managers) / framework | Scan tool | Introduced in GitLab Version |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------|------------------------------|
2020-05-24 23:13:21 +05:30
| .NET Core | [Security Code Scan ](https://security-code-scan.github.io ) | 11.0 |
| .NET Framework | [Security Code Scan ](https://security-code-scan.github.io ) | 13.0 |
2019-12-21 20:55:43 +05:30
| Any | [Gitleaks ](https://github.com/zricethezav/gitleaks ) and [TruffleHog ](https://github.com/dxa4481/truffleHog ) | 11.9 |
2020-05-24 23:13:21 +05:30
| Apex (Salesforce) | [PMD ](https://pmd.github.io/pmd/index.html ) | 12.1 |
2020-06-23 00:09:42 +05:30
| C/C++ | [Flawfinder ](https://github.com/david-a-wheeler/flawfinder ) | 10.7 |
2019-07-31 22:56:46 +05:30
| Elixir (Phoenix) | [Sobelow ](https://github.com/nccgroup/sobelow ) | 11.10 |
| Go | [Gosec ](https://github.com/securego/gosec ) | 10.7 |
| Groovy ([Ant](https://ant.apache.org/), [Gradle ](https://gradle.org/ ), [Maven ](https://maven.apache.org/ ) and [SBT ](https://www.scala-sbt.org/ )) | [SpotBugs ](https://spotbugs.github.io/ ) with the [find-sec-bugs ](https://find-sec-bugs.github.io/ ) plugin | 11.3 (Gradle) & 11.9 (Ant, Maven, SBT) |
2020-06-23 00:09:42 +05:30
| Helm Charts | [Kubesec ](https://github.com/controlplaneio/kubesec ) | 13.1 |
2019-07-31 22:56:46 +05:30
| Java ([Ant](https://ant.apache.org/), [Gradle ](https://gradle.org/ ), [Maven ](https://maven.apache.org/ ) and [SBT ](https://www.scala-sbt.org/ )) | [SpotBugs ](https://spotbugs.github.io/ ) with the [find-sec-bugs ](https://find-sec-bugs.github.io/ ) plugin | 10.6 (Maven), 10.8 (Gradle) & 11.9 (Ant, SBT) |
2019-12-21 20:55:43 +05:30
| JavaScript | [ESLint security plugin ](https://github.com/nodesecurity/eslint-plugin-security ) | 11.8 |
2020-01-01 13:55:28 +05:30
| Kubernetes manifests | [Kubesec ](https://github.com/controlplaneio/kubesec ) | 12.6 |
2019-07-31 22:56:46 +05:30
| Node.js | [NodeJsScan ](https://github.com/ajinabraham/NodeJsScan ) | 11.1 |
| PHP | [phpcs-security-audit ](https://github.com/FloeDesignTechnologies/phpcs-security-audit ) | 10.8 |
2019-09-04 21:01:54 +05:30
| Python ([pip](https://pip.pypa.io/en/stable/)) | [bandit ](https://github.com/PyCQA/bandit ) | 10.3 |
2019-12-26 22:10:19 +05:30
| React | [ESLint react plugin ](https://github.com/yannickcr/eslint-plugin-react ) | 12.5 |
2019-07-31 22:56:46 +05:30
| Ruby on Rails | [brakeman ](https://brakemanscanner.org ) | 10.3 |
| Scala ([Ant](https://ant.apache.org/), [Gradle ](https://gradle.org/ ), [Maven ](https://maven.apache.org/ ) and [SBT ](https://www.scala-sbt.org/ )) | [SpotBugs ](https://spotbugs.github.io/ ) with the [find-sec-bugs ](https://find-sec-bugs.github.io/ ) plugin | 11.0 (SBT) & 11.9 (Ant, Gradle, Maven) |
2020-05-24 23:13:21 +05:30
| TypeScript | [`tslint-config-security` ](https://github.com/webschik/tslint-config-security/ ) | 11.9 |
2019-07-31 22:56:46 +05:30
NOTE: **Note:**
The Java analyzers can also be used for variants like the
[Gradle wrapper ](https://docs.gradle.org/current/userguide/gradle_wrapper.html ),
[Grails ](https://grails.org/ ) and the [Maven wrapper ](https://github.com/takari/maven-wrapper ).
2020-04-22 19:07:51 +05:30
## Contribute your scanner
The [Security Scanner Integration ](../../../development/integrations/secure.md ) documentation explains how to integrate other security scanners into GitLab.
2019-09-30 21:07:59 +05:30
## Configuration
2019-07-31 22:56:46 +05:30
2020-04-22 19:07:51 +05:30
NOTE: **Note:**
You don't have to configure SAST manually as shown in this section if you're using [Auto SAST ](../../../topics/autodevops/stages.md#auto-sast-ultimate )
provided by [Auto DevOps ](../../../topics/autodevops/index.md ).
For GitLab 11.9 and later, to enable SAST you must [include ](../../../ci/yaml/README.md#includetemplate )
the [`SAST.gitlab-ci.yml` template ](https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml )
2020-05-24 23:13:21 +05:30
provided as a part of your GitLab installation. For GitLab versions earlier than 11.9, you
2020-04-22 19:07:51 +05:30
can copy and use the job as defined that template.
2019-07-31 22:56:46 +05:30
2019-09-30 21:07:59 +05:30
Add the following to your `.gitlab-ci.yml` file:
2019-07-31 22:56:46 +05:30
```yaml
include:
2020-03-13 15:44:24 +05:30
- template: SAST.gitlab-ci.yml
2019-07-31 22:56:46 +05:30
```
2020-05-24 23:13:21 +05:30
The included template will create SAST jobs in your CI/CD pipeline and scan
2019-07-31 22:56:46 +05:30
your project's source code for possible vulnerabilities.
2019-09-30 21:07:59 +05:30
The results will be saved as a
2020-05-24 23:13:21 +05:30
[SAST report artifact ](../../../ci/pipelines/job_artifacts.md#artifactsreportssast-ultimate )
2019-07-31 22:56:46 +05:30
that you can later download and analyze. Due to implementation limitations, we
2020-05-24 23:13:21 +05:30
always take the latest SAST artifact available.
2019-07-31 22:56:46 +05:30
2019-09-30 21:07:59 +05:30
### Customizing the SAST settings
2019-07-31 22:56:46 +05:30
2019-12-21 20:55:43 +05:30
The SAST settings can be changed through [environment variables ](#available-variables )
by using the
2019-07-31 22:56:46 +05:30
[`variables` ](../../../ci/yaml/README.md#variables ) parameter in `.gitlab-ci.yml` .
In the following example, we include the SAST template and at the same time we
set the `SAST_GOSEC_LEVEL` variable to `2` :
```yaml
include:
2020-03-13 15:44:24 +05:30
- template: SAST.gitlab-ci.yml
2019-07-31 22:56:46 +05:30
variables:
SAST_GOSEC_LEVEL: 2
```
Because the template is [evaluated before ](../../../ci/yaml/README.md#include )
2020-05-24 23:13:21 +05:30
the pipeline configuration, the last mention of the variable takes precedence.
2019-07-31 22:56:46 +05:30
2020-05-24 23:13:21 +05:30
### Overriding SAST jobs
2019-12-21 20:55:43 +05:30
2020-04-22 19:07:51 +05:30
CAUTION: **Deprecation:**
Beginning in GitLab 13.0, the use of [`only` and `except` ](../../../ci/yaml/README.md#onlyexcept-basic )
is no longer supported. When overriding the template, you must use [`rules` ](../../../ci/yaml/README.md#rules ) instead.
2020-05-24 23:13:21 +05:30
To override a job definition, (for example, change properties like `variables` or `dependencies` ),
declare a job with the same name as the SAST job to override. Place this new job after the template
inclusion and specify any additional keys under it. For example, this enables `FAIL_NEVER` for the
`spotbugs` analyzer:
2019-12-21 20:55:43 +05:30
```yaml
include:
2020-03-13 15:44:24 +05:30
- template: SAST.gitlab-ci.yml
2019-12-21 20:55:43 +05:30
2020-05-24 23:13:21 +05:30
spotbugs-sast:
2019-12-21 20:55:43 +05:30
variables:
2020-05-24 23:13:21 +05:30
FAIL_NEVER: 1
2019-12-21 20:55:43 +05:30
```
2019-12-26 22:10:19 +05:30
### Using environment variables to pass credentials for private repositories
Some analyzers require downloading the project's dependencies in order to
perform the analysis. In turn, such dependencies may live in private Git
repositories and thus require credentials like username and password to download them.
Depending on the analyzer, such credentials can be provided to
it via [custom environment variables ](#custom-environment-variables ).
#### Using a variable to pass username and password to a private Maven repository
2019-12-04 20:38:33 +05:30
2020-05-24 23:13:21 +05:30
If your private Maven repository requires login credentials,
2020-04-22 19:07:51 +05:30
you can use the `MAVEN_CLI_OPTS` environment variable.
2019-12-04 20:38:33 +05:30
2020-05-24 23:13:21 +05:30
Read more on [how to use private Maven repositories ](../index.md#using-private-maven-repos ).
2019-12-04 20:38:33 +05:30
2020-05-24 23:13:21 +05:30
### Enabling Docker-in-Docker
2019-07-31 22:56:46 +05:30
2020-05-24 23:13:21 +05:30
If needed, you can enable Docker-in-Docker to restore the SAST behavior that existed prior to GitLab
13.0. Follow these steps to do so:
2019-07-31 22:56:46 +05:30
2020-05-24 23:13:21 +05:30
1. Configure GitLab Runner with Docker-inDocker in [privileged mode ](https://docs.gitlab.com/runner/executors/docker.html#use-docker-in-docker-with-privileged-mode ).
1. Set the variable `SAST_DISABLE_DIND` set to `false` :
2019-07-31 22:56:46 +05:30
2020-05-24 23:13:21 +05:30
```yaml
include:
- template: SAST.gitlab-ci.yml
2019-07-31 22:56:46 +05:30
2020-05-24 23:13:21 +05:30
variables:
SAST_DISABLE_DIND: "false"
```
2019-12-21 20:55:43 +05:30
2020-05-24 23:13:21 +05:30
This creates a single `sast` job in your CI/CD pipeline instead of multiple `<analyzer-name>-sast`
jobs.
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
#### Enabling Kubesec analyzer
2020-01-01 13:55:28 +05:30
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/12752) in GitLab Ultimate 12.6.
2020-01-01 13:55:28 +05:30
2020-05-24 23:13:21 +05:30
You need to set `SCAN_KUBERNETES_MANIFESTS` to `"true"` to enable the
Kubesec analyzer. In `.gitlab-ci.yml` , define:
2020-01-01 13:55:28 +05:30
```yaml
include:
2020-03-13 15:44:24 +05:30
- template: SAST.gitlab-ci.yml
2020-01-01 13:55:28 +05:30
variables:
SCAN_KUBERNETES_MANIFESTS: "true"
```
2020-03-13 15:44:24 +05:30
#### Pre-compilation
If your project requires custom build configurations, it can be preferable to avoid
compilation during your SAST execution and instead pass all job artifacts from an
earlier stage within the pipeline. This is the current strategy when requiring
a `before_script` execution to prepare your scan job.
To pass your project's dependencies as artifacts, the dependencies must be included
in the project's working directory and specified using the `artifacts:path` configuration.
If all dependencies are present, the `-compile=false` flag can be provided to the
analyzer and compilation will be skipped:
```yaml
image: maven:3.6-jdk-8-alpine
stages:
- build
- test
include:
- template: SAST.gitlab-ci.yml
build:
stage: build
script:
- mvn package -Dmaven.repo.local=./.m2/repository
artifacts:
paths:
- .m2/
- target/
spotbugs-sast:
dependencies:
- build
script:
- /analyzer run -compile=false
variables:
MAVEN_REPO_PATH: ./.m2/repository
artifacts:
reports:
sast: gl-sast-report.json
```
NOTE: **Note:**
The path to the vendored directory must be specified explicitly to allow
the analyzer to recognize the compiled artifacts. This configuration can vary per
analyzer but in the case of Java above, `MAVEN_REPO_PATH` can be used.
See [Analyzer settings ](#analyzer-settings ) for the complete list of available options.
2019-10-12 21:52:04 +05:30
### Available variables
SAST can be [configured ](#customizing-the-sast-settings ) using environment variables.
2020-04-08 14:13:33 +05:30
#### Custom Certificate Authority
To trust a custom Certificate Authority, set the `ADDITIONAL_CA_CERT_BUNDLE` variable to the bundle
of CA certs that you want to trust within the SAST environment.
2019-10-12 21:52:04 +05:30
#### Docker images
The following are Docker image-related variables.
2019-12-26 22:10:19 +05:30
| Environment variable | Description |
|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2020-05-24 23:13:21 +05:30
| `SECURE_ANALYZERS_PREFIX` | Override the name of the Docker registry providing the default images (proxy). Read more about [customizing analyzers ](analyzers.md ). |
| `SAST_ANALYZER_IMAGE_PREFIX` | **DEPRECATED** : Use `SECURE_ANALYZERS_PREFIX` instead. |
| `SAST_ANALYZER_IMAGE_TAG` | **DEPRECATED:** Override the Docker tag of the default images. Read more about [customizing analyzers ](analyzers.md ). |
2019-12-26 22:10:19 +05:30
| `SAST_DEFAULT_ANALYZERS` | Override the names of default images. Read more about [customizing analyzers ](analyzers.md ). |
2020-05-24 23:13:21 +05:30
| `SAST_DISABLE_DIND` | Disable Docker-in-Docker and run analyzers [individually ](#enabling-docker-in-docker ). This variable is `true` by default. |
2019-10-12 21:52:04 +05:30
2019-12-21 20:55:43 +05:30
#### Vulnerability filters
2019-10-12 21:52:04 +05:30
Some analyzers make it possible to filter out vulnerabilities under a given threshold.
2020-04-08 14:13:33 +05:30
| Environment variable | Default value | Description |
|-------------------------|---------------|-------------|
2020-06-23 00:09:42 +05:30
| `SAST_EXCLUDED_PATHS` | `spec, test, tests, tmp` | Exclude vulnerabilities from output based on the paths. This is a comma-separated list of patterns. Patterns can be globs, or file or folder paths (for example, `doc,spec` ). Parent directories will also match patterns. |
| `SAST_BANDIT_EXCLUDED_PATHS` | - | comma-separated list of paths to exclude from scan. Uses Python's [`fnmatch` syntax ](https://docs.python.org/2/library/fnmatch.html ); For example: `'*/tests/*'` |
2020-01-01 13:55:28 +05:30
| `SAST_BRAKEMAN_LEVEL` | 1 | Ignore Brakeman vulnerabilities under given confidence level. Integer, 1=Low 3=High. |
| `SAST_FLAWFINDER_LEVEL` | 1 | Ignore Flawfinder vulnerabilities under given risk level. Integer, 0=No risk, 5=High risk. |
| `SAST_GITLEAKS_ENTROPY_LEVEL` | 8.0 | Minimum entropy for secret detection. Float, 0.0 = low, 8.0 = high. |
2020-05-24 23:13:21 +05:30
| `SAST_GOSEC_LEVEL` | 0 | Ignore Gosec vulnerabilities under given confidence level. Integer, 0=Undefined, 1=Low, 2=Medium, 3=High. |
| `SAST_GITLEAKS_COMMIT_FROM` | - | The commit a Gitleaks scan starts at. |
| `SAST_GITLEAKS_COMMIT_TO` | - | The commit a Gitleaks scan ends at. |
| `SAST_GITLEAKS_HISTORIC_SCAN` | false | Flag to enable a historic Gitleaks scan. |
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
#### Docker-in-Docker orchestrator
2019-10-12 21:52:04 +05:30
2020-05-24 23:13:21 +05:30
The following variables configure the Docker-in-Docker orchestrator, and therefore are only used when the Docker-in-Docker mode is [enabled ](#enabling-docker-in-docker ).
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
| Environment variable | Default value | Description |
|------------------------------------------|---------------|-------------|
2020-05-24 23:13:21 +05:30
| `SAST_ANALYZER_IMAGES` | | Comma-separated list of custom images. Default images are still enabled. Read more about [customizing analyzers ](analyzers.md ). |
| `SAST_PULL_ANALYZER_IMAGES` | 1 | Pull the images from the Docker registry (set to 0 to disable). Read more about [customizing analyzers ](analyzers.md ). |
| `SAST_DOCKER_CLIENT_NEGOTIATION_TIMEOUT` | 2m | Time limit for Docker client negotiation. Timeouts are parsed using Go's [`ParseDuration` ](https://golang.org/pkg/time/#ParseDuration ). Valid time units are `ns` , `us` (or `µs` ), `ms` , `s` , `m` , `h` . For example, `300ms` , `1.5h` or `2h45m` . |
| `SAST_PULL_ANALYZER_IMAGE_TIMEOUT` | 5m | Time limit when pulling the image of an analyzer. Timeouts are parsed using Go's [`ParseDuration` ](https://golang.org/pkg/time/#ParseDuration ). Valid time units are `ns` , `us` (or `µs` ), `ms` , `s` , `m` , `h` . For example, `300ms` , `1.5h` or `2h45m` . |
| `SAST_RUN_ANALYZER_TIMEOUT` | 20m | Time limit when running an analyzer. Timeouts are parsed using Go's [`ParseDuration` ](https://golang.org/pkg/time/#ParseDuration ). Valid time units are `ns` , `us` (or `µs` ), `ms` , `s` , `m` , `h` . For example, `300ms` , `1.5h` or `2h45m` .|
2019-12-26 22:10:19 +05:30
2019-12-21 20:55:43 +05:30
#### Analyzer settings
2019-10-12 21:52:04 +05:30
Some analyzers can be customized with environment variables.
2020-01-01 13:55:28 +05:30
| Environment variable | Analyzer | Description |
|-----------------------------|----------|-------------|
2020-06-23 00:09:42 +05:30
| `SCAN_KUBERNETES_MANIFESTS` | Kubesec | Set to `"true"` to scan Kubernetes manifests. |
| `KUBESEC_HELM_CHARTS_PATH` | Kubesec | Optional path to Helm charts that `helm` will use to generate a Kubernetes manifest that `kubesec` will scan. If dependencies are defined, `helm dependency build` should be ran in a `before_script` to fetch the necessary dependencies. |
| `KUBESEC_HELM_OPTIONS` | Kubesec | Additional arguments for the `helm` executable. |
| `ANT_HOME` | SpotBugs | The `ANT_HOME` environment variable. |
| `ANT_PATH` | SpotBugs | Path to the `ant` executable. |
| `GRADLE_PATH` | SpotBugs | Path to the `gradle` executable. |
| `JAVA_OPTS` | SpotBugs | Additional arguments for the `java` executable. |
| `JAVA_PATH` | SpotBugs | Path to the `java` executable. |
| `SAST_JAVA_VERSION` | SpotBugs | Which Java version to use. Supported versions are `8` and `11` . Defaults to `8` . |
| `MAVEN_CLI_OPTS` | SpotBugs | Additional arguments for the `mvn` or `mvnw` executable. |
| `MAVEN_PATH` | SpotBugs | Path to the `mvn` executable. |
| `MAVEN_REPO_PATH` | SpotBugs | Path to the Maven local repository (shortcut for the `maven.repo.local` property). |
| `SBT_PATH` | SpotBugs | Path to the `sbt` executable. |
| `FAIL_NEVER` | SpotBugs | Set to `1` to ignore compilation failure. |
| `SAST_GOSEC_CONFIG` | Gosec | Path to configuration for Gosec (optional). |
| `PHPCS_SECURITY_AUDIT_PHP_EXTENSIONS` | phpcs-security-audit | Comma separated list of additional PHP Extensions. |
2019-10-12 21:52:04 +05:30
2019-12-26 22:10:19 +05:30
#### Custom environment variables
2020-03-13 15:44:24 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/18193) in GitLab Ultimate 12.5.
2019-12-26 22:10:19 +05:30
In addition to the aforementioned SAST configuration variables,
2020-05-24 23:13:21 +05:30
all [custom environment variables ](../../../ci/variables/README.md#custom-environment-variables ) are propagated
2019-12-26 22:10:19 +05:30
to the underlying SAST analyzer images if
[the SAST vendored template ](#configuration ) is used.
CAUTION: **Caution:**
Variables having names starting with these prefixes will **not** be propagated to the SAST Docker container and/or
analyzer containers: `DOCKER_` , `CI` , `GITLAB_` , `FF_` , `HOME` , `PWD` , `OLDPWD` , `PATH` , `SHLVL` , `HOSTNAME` .
2019-09-04 21:01:54 +05:30
## Reports JSON format
2020-06-23 00:09:42 +05:30
The SAST tool emits a JSON report file. For more information, see the
[schema for this report ](https://gitlab.com/gitlab-org/security-products/security-report-schemas/-/blob/master/dist/sast-report-format.json ).
2019-09-04 21:01:54 +05:30
2020-06-23 00:09:42 +05:30
Here's an example SAST report:
2019-09-04 21:01:54 +05:30
```json-doc
{
"version": "2.0",
"vulnerabilities": [
{
2020-04-22 19:07:51 +05:30
"id": "9e96e0ab-23da-4d7d-a09e-0acbaa5e83ca",
2019-09-04 21:01:54 +05:30
"category": "sast",
"name": "Predictable pseudorandom number generator",
"message": "Predictable pseudorandom number generator",
"description": "The use of java.util.Random is predictable",
"severity": "Medium",
"confidence": "Medium",
"scanner": {
"id": "find_sec_bugs",
"name": "Find Security Bugs"
},
"location": {
"file": "groovy/src/main/groovy/com/gitlab/security_products/tests/App.groovy",
"start_line": 47,
"end_line": 47,
"class": "com.gitlab.security_products.tests.App",
"method": "generateSecretToken2",
"dependency": {
"package": {}
}
},
"identifiers": [
{
"type": "find_sec_bugs_type",
"name": "Find Security Bugs-PREDICTABLE_RANDOM",
"value": "PREDICTABLE_RANDOM",
"url": "https://find-sec-bugs.github.io/bugs.htm#PREDICTABLE_RANDOM"
},
{
"type": "cwe",
"name": "CWE-330",
"value": "330",
"url": "https://cwe.mitre.org/data/definitions/330.html"
}
]
2019-09-30 21:07:59 +05:30
},
2019-09-04 21:01:54 +05:30
{
2020-04-22 19:07:51 +05:30
"id": "e6dbf91f-4c07-46f7-a365-0169489c27d1",
2019-09-04 21:01:54 +05:30
"category": "sast",
"message": "Probable insecure usage of temp file/directory.",
"severity": "Medium",
"confidence": "Medium",
"scanner": {
"id": "bandit",
"name": "Bandit"
},
"location": {
"file": "python/hardcoded/hardcoded-tmp.py",
"start_line": 10,
"end_line": 10,
"dependency": {
"package": {}
}
},
"identifiers": [
{
"type": "bandit_test_id",
"name": "Bandit Test ID B108",
"value": "B108",
"url": "https://docs.openstack.org/bandit/latest/plugins/b108_hardcoded_tmp_directory.html"
}
]
2019-09-30 21:07:59 +05:30
},
2019-09-04 21:01:54 +05:30
],
"remediations": []
}
```
2019-07-31 22:56:46 +05:30
## Secret detection
2020-05-24 23:13:21 +05:30
Learn more about [Secret Detection ](../secret_detection ).
2020-03-13 15:44:24 +05:30
2019-07-31 22:56:46 +05:30
## Security Dashboard
The Security Dashboard is a good place to get an overview of all the security
2019-12-04 20:38:33 +05:30
vulnerabilities in your groups, projects and pipelines. Read more about the
2019-07-31 22:56:46 +05:30
[Security Dashboard ](../security_dashboard/index.md ).
## Interacting with the vulnerabilities
Once a vulnerability is found, you can interact with it. Read more on how to
[interact with the vulnerabilities ](../index.md#interacting-with-the-vulnerabilities ).
2019-09-30 21:07:59 +05:30
2020-05-24 23:13:21 +05:30
## Vulnerabilities database
Vulnerabilities contained within the vulnerability database can be searched
and viewed at the [GitLab vulnerability advisory database ](https://advisories.gitlab.com ).
### Vulnerabilities database update
2019-09-30 21:07:59 +05:30
For more information about the vulnerabilities database update, check the
[maintenance table ](../index.md#maintenance-and-update-of-the-vulnerabilities-database ).
2019-10-12 21:52:04 +05:30
2020-04-22 19:07:51 +05:30
## Running SAST in an offline environment
2020-04-08 14:13:33 +05:30
For self-managed GitLab instances in an environment with limited, restricted, or intermittent access
2020-04-22 19:07:51 +05:30
to external resources through the internet, some adjustments are required for the SAST job to
2020-05-24 23:13:21 +05:30
run successfully. For more information, see [Offline environments ](../offline_deployments/index.md ).
2020-04-08 14:13:33 +05:30
### Requirements for offline SAST
To use SAST in an offline environment, you need:
2020-05-24 23:13:21 +05:30
- To keep Docker-In-Docker disabled (default).
2020-04-08 14:13:33 +05:30
- GitLab Runner with the [`docker` or `kubernetes` executor ](#requirements ).
- Docker Container Registry with locally available copies of SAST [analyzer ](https://gitlab.com/gitlab-org/security-products/analyzers ) images.
NOTE: **Note:**
GitLab Runner has a [default `pull policy` of `always` ](https://docs.gitlab.com/runner/executors/docker.html#using-the-always-pull-policy ),
2020-05-24 23:13:21 +05:30
meaning the Runner tries to pull Docker images from the GitLab container registry even if a local
2020-04-22 19:07:51 +05:30
copy is available. GitLab Runner's [`pull_policy` can be set to `if-not-present` ](https://docs.gitlab.com/runner/executors/docker.html#using-the-if-not-present-pull-policy )
in an offline environment if you prefer using only locally available Docker images. However, we
2020-05-24 23:13:21 +05:30
recommend keeping the pull policy setting to `always` if not in an offline environment, as this
enables the use of updated scanners in your CI/CD pipelines.
2020-04-08 14:13:33 +05:30
### Make GitLab SAST analyzer images available inside your Docker registry
For SAST with all [supported languages and frameworks ](#supported-languages-and-frameworks ),
2020-05-24 23:13:21 +05:30
import the following default SAST analyzer images from `registry.gitlab.com` into your
[local Docker container registry ](../../packages/container_registry/index.md ):
2020-04-08 14:13:33 +05:30
2020-04-22 19:07:51 +05:30
```plaintext
2020-04-08 14:13:33 +05:30
registry.gitlab.com/gitlab-org/security-products/analyzers/bandit:2
registry.gitlab.com/gitlab-org/security-products/analyzers/brakeman:2
registry.gitlab.com/gitlab-org/security-products/analyzers/eslint:2
registry.gitlab.com/gitlab-org/security-products/analyzers/flawfinder:2
registry.gitlab.com/gitlab-org/security-products/analyzers/gosec:2
registry.gitlab.com/gitlab-org/security-products/analyzers/kubesec:2
registry.gitlab.com/gitlab-org/security-products/analyzers/nodejs-scan:2
registry.gitlab.com/gitlab-org/security-products/analyzers/phpcs-security-audit:2
registry.gitlab.com/gitlab-org/security-products/analyzers/pmd-apex:2
registry.gitlab.com/gitlab-org/security-products/analyzers/secrets:2
registry.gitlab.com/gitlab-org/security-products/analyzers/security-code-scan:2
registry.gitlab.com/gitlab-org/security-products/analyzers/sobelow:2
registry.gitlab.com/gitlab-org/security-products/analyzers/spotbugs:2
registry.gitlab.com/gitlab-org/security-products/analyzers/tslint:2
```
The process for importing Docker images into a local offline Docker registry depends on
**your network security policy**. Please consult your IT staff to find an accepted and approved
process by which external resources can be imported or temporarily accessed. Note that these scanners are [updated periodically ](../index.md#maintenance-and-update-of-the-vulnerabilities-database )
2020-05-24 23:13:21 +05:30
with new definitions, so consider if you're able to make periodic updates yourself.
2020-04-08 14:13:33 +05:30
For details on saving and transporting Docker images as a file, see Docker's documentation on
[`docker save` ](https://docs.docker.com/engine/reference/commandline/save/ ), [`docker load` ](https://docs.docker.com/engine/reference/commandline/load/ ),
[`docker export` ](https://docs.docker.com/engine/reference/commandline/export/ ), and [`docker import` ](https://docs.docker.com/engine/reference/commandline/import/ ).
### Set SAST CI job variables to use local SAST analyzers
2020-05-24 23:13:21 +05:30
Add the following configuration to your `.gitlab-ci.yml` file. You must replace
`SAST_ANALYZER_IMAGE_PREFIX` to refer to your local Docker container registry:
2020-04-08 14:13:33 +05:30
```yaml
include:
- template: SAST.gitlab-ci.yml
variables:
2020-05-24 23:13:21 +05:30
SECURE_ANALYZERS_PREFIX: "localhost:5000/analyzers"
2020-04-08 14:13:33 +05:30
```
The SAST job should now use local copies of the SAST analyzers to scan your code and generate
security reports without requiring internet access.
2019-12-04 20:38:33 +05:30
## Troubleshooting
2019-10-12 21:52:04 +05:30
2020-06-23 00:09:42 +05:30
### `Error response from daemon: error processing tar file: docker-tar: relocation error`
2019-10-12 21:52:04 +05:30
2020-05-24 23:13:21 +05:30
This error occurs when the Docker version that runs the SAST job is `19.03.0` .
Consider updating to Docker `19.03.1` or greater. Older versions are not
2019-12-04 20:38:33 +05:30
affected. Read more in
2020-06-23 00:09:42 +05:30
[this issue ](https://gitlab.com/gitlab-org/gitlab/-/issues/13830#note_211354992 "Current SAST container fails" ).