Dependency Scanning

Dependency Scanning helps to automatically find security vulnerabilities in your dependencies while you are developing and testing your applications, for example when your application is using an external (open source) library which is known to be vulnerable.

Overview

If you are using GitLab CI/CD, you can analyze your dependencies for known vulnerabilities using Dependency Scanning. All dependencies are scanned, including the transitive dependencies (also known as nested dependencies).

You can take advantage of Dependency Scanning by either including the Dependency Scanning template in your existing .gitlab-ci.yml file or by implicitly using Auto Dependency Scanning that is provided by Auto DevOps.

GitLab checks the Dependency Scanning report, compares the found vulnerabilities between the source and target branches, and shows the information on the merge request.

Dependency Scanning Widget

The results are sorted by the severity of the vulnerability:

  1. Critical
  2. High
  3. Medium
  4. Low
  5. Unknown
  6. Everything else

Requirements

To run a Dependency Scanning job, by default, you need GitLab Runner with the docker or kubernetes executor running in privileged mode. If you’re using the shared Runners on GitLab.com, this is enabled by default.

Caution: If you use your own Runners, make sure that the Docker version you have installed is not 19.03.00. See troubleshooting information for details.

Privileged mode is not necessary if you’ve disabled Docker in Docker for Dependency Scanning

Supported languages and package managers

The following languages and dependency managers are supported.

Language (package managers)SupportedScan tool(s)
Java (Gradle)yesgemnasium
Java (Maven)yesgemnasium
JavaScript (npm, yarn)yesgemnasium, Retire.js
PHP (Composer)yesgemnasium
Python (pip)yesgemnasium
Python (Pipfile)not currently (issue)not available
Python (poetry)not currently (issue)not available
Ruby (gem)yesgemnasium, bundler-audit
Scala (sbt)yesgemnasium
Go (Go Modules)yes (alpha)gemnasium

Contribute your scanner

The Security Scanner Integration documentation explains how to integrate other security scanners into GitLab.

Configuration

For GitLab 11.9 and later, to enable Dependency Scanning, you must include the Dependency-Scanning.gitlab-ci.yml template that’s provided as a part of your GitLab installation. For GitLab versions earlier than 11.9, you can copy and use the job as defined that template.

Add the following to your .gitlab-ci.yml file:

include:
  - template: Dependency-Scanning.gitlab-ci.yml

The included template will create a dependency_scanning job in your CI/CD pipeline and scan your project’s source code for possible vulnerabilities.

The results will be saved as a Dependency Scanning report artifact that you can later download and analyze. Due to implementation limitations, we always take the latest Dependency Scanning artifact available.

Customizing the Dependency Scanning settings

The Dependency Scanning settings can be changed through environment variables by using the variables parameter in .gitlab-ci.yml.

For example:

include:
  - template: Dependency-Scanning.gitlab-ci.yml

variables:
  DS_PYTHON_VERSION: 2

Because template is evaluated before the pipeline configuration, the last mention of the variable will take precedence.

Overriding the Dependency Scanning template

If you want to override the job definition (for example, change properties like variables or dependencies), you need to declare a dependency_scanning job after the template inclusion and specify any additional keys under it. For example:

include:
  - template: Dependency-Scanning.gitlab-ci.yml

dependency_scanning:
  variables:
    CI_DEBUG_TRACE: "true"

Available variables

Dependency Scanning can be configured using environment variables.

Configuring Dependency Scanning

The following variables allow configuration of global dependency scanning settings.

Environment variableDescription
DS_ANALYZER_IMAGE_PREFIXOverride the name of the Docker registry providing the official default images (proxy). Read more about customizing analyzers.
DS_DEFAULT_ANALYZERSOverride the names of the official default images. Read more about customizing analyzers.
DS_DISABLE_DINDDisable Docker-in-Docker and run analyzers individually.
ADDITIONAL_CA_CERT_BUNDLEBundle of CA certs to trust.
DS_EXCLUDED_PATHSExclude vulnerabilities from output based on the paths. A comma-separated list of patterns. Patterns can be globs, or file or folder paths (for example, doc,spec). Parent directories also match patterns.

Configuring Docker-in-Docker orchestrator

The following variables configure the Docker-in-Docker orchestrator.

Environment variableDefaultDescription
DS_ANALYZER_IMAGES Comma separated list of custom images. The official default images are still enabled. Read more about customizing analyzers.
DS_ANALYZER_IMAGE_TAG Override the Docker tag of the official default images. Read more about customizing analyzers.
DS_PULL_ANALYZER_IMAGES Pull the images from the Docker registry (set to 0 to disable).
DS_DOCKER_CLIENT_NEGOTIATION_TIMEOUT2mTime limit for Docker client negotiation. Timeouts are parsed using Go’s ParseDuration. Valid time units are ns, us (or µs), ms, s, m, or h. For example, 300ms, 1.5h, or 2h45m.
DS_PULL_ANALYZER_IMAGE_TIMEOUT5mTime limit when pulling an analyzer’s image. Timeouts are parsed using Go’s ParseDuration. Valid time units are ns, us (or µs), ms, s, m, or h. For example, 300ms, 1.5h, or 2h45m.
DS_RUN_ANALYZER_TIMEOUT20mTime limit when running an analyzer. Timeouts are parsed using Go’s ParseDuration. Valid time units are ns, us (or µs), ms, s, m, or h. For example, 300ms, 1.5h, or 2h45m.

Configuring specific analyzers used by Dependency Scanning

The following variables are used for configuring specific analyzers (used for a specific language/framework).

Environment variableAnalyzerDefaultDescription
GEMNASIUM_DB_LOCAL_PATHgemnasium/gemnasium-dbPath to local gemnasium database.
GEMNASIUM_DB_REMOTE_URLgemnasiumhttps://gitlab.com/gitlab-org/security-products/gemnasium-db.gitRepository URL for fetching the gemnasium database.
GEMNASIUM_DB_REF_NAMEgemnasiummasterBranch name for remote repository database. GEMNASIUM_DB_REMOTE_URL is required.
DS_REMEDIATEgemnasium"true"Enable automatic remediation of vulnerable dependencies.
PIP_INDEX_URLgemnasium-pythonhttps://pypi.org/simpleBase URL of Python Package Index.
PIP_EXTRA_INDEX_URLgemnasium-python Array of extra URLs of package indexes to use in addition to PIP_INDEX_URL. Comma separated.
PIP_REQUIREMENTS_FILEgemnasium-python Pip requirements file to be scanned.
DS_PIP_VERSIONgemnasium-python Force the install of a specific pip version (example: "19.3"), otherwise the pip installed in the Docker image is used. (Introduced in GitLab 12.7)
DS_PIP_DEPENDENCY_PATHgemnasium-python Path to load Python pip dependencies from. (Introduced in GitLab 12.2)
DS_PYTHON_VERSIONretire.js Version of Python. If set to 2, dependencies are installed using Python 2.7 instead of Python 3.6. (Introduced in GitLab 12.1)
MAVEN_CLI_OPTSgemnasium-maven"-DskipTests --batch-mode"List of command line arguments that will be passed to maven by the analyzer. See an example for using private repos.
BUNDLER_AUDIT_UPDATE_DISABLEDbundler-audit"false"Disable automatic updates for the bundler-audit analyzer. Useful if you’re running Dependency Scanning in an offline, air-gapped environment.
BUNDLER_AUDIT_ADVISORY_DB_URLbundler-audithttps://github.com/rubysec/ruby-advisory-dbURL of the advisory database used by bundler-audit.
BUNDLER_AUDIT_ADVISORY_DB_REF_NAMEbundler-auditmasterGit ref for the advisory database specified by BUNDLER_AUDIT_ADVISORY_DB_URL.
RETIREJS_JS_ADVISORY_DBretire.jshttps://raw.githubusercontent.com/RetireJS/retire.js/master/repository/jsrepository.jsonPath or URL to Retire.js js vulnerability data file.
RETIREJS_NODE_ADVISORY_DBretire.jshttps://raw.githubusercontent.com/RetireJS/retire.js/master/repository/npmrepository.jsonPath or URL to Retire.js node vulnerability data file.

Using private Maven repos

If you have a private Maven repository which requires login credentials, you can use the MAVEN_CLI_OPTS environment variable.

Read more on how to use private Maven repos.

Disabling Docker in Docker for Dependency Scanning

Introduced in GitLab Ultimate 12.5.

You can avoid the need for Docker in Docker by running the individual analyzers. This does not require running the executor in privileged mode. For example:

include:
  - template: Dependency-Scanning.gitlab-ci.yml

variables:
  DS_DISABLE_DIND: "true"

This will create individual <analyzer-name>-dependency_scanning jobs for each analyzer that runs in your CI/CD pipeline.

By removing Docker-in-Docker (DIND), GitLab relies on Linguist to start relevant analyzers depending on the detected repository language(s) instead of the orchestrator. However, there are some differences in the way repository languages are detected between DIND and non-DIND. You can observe these differences by checking both Linguist and the common library. For instance, Linguist looks for *.java files to spin up the gemnasium-maven image, while orchestrator only looks for the existence of pom.xml or build.gradle. GitLab uses Linguist to detect new file types in the default branch. This means that when introducing files or dependencies for a new language or package manager, the corresponding scans won’t be triggered in the MR and will only run on the default branch once the MR is merged. This will be addressed by #211702.

Interacting with the vulnerabilities

Once a vulnerability is found, you can interact with it. Read more on how to interact with the vulnerabilities.

Solutions for vulnerabilities (auto-remediation)

Some vulnerabilities can be fixed by applying the solution that GitLab automatically generates.

Read more about the solutions for vulnerabilities.

Security Dashboard

The Security Dashboard is a good place to get an overview of all the security vulnerabilities in your groups, projects and pipelines. Read more about the Security Dashboard.

Vulnerabilities database update

For more information about the vulnerabilities database update, check the maintenance table.

Dependency List

An additional benefit of Dependency Scanning is the ability to view your project’s dependencies and their known vulnerabilities. Read more about the Dependency List.

Reports JSON format

Caution: The JSON report artifacts are not a public API of Dependency Scanning and their format may change in the future.

The Dependency Scanning tool emits a JSON report file. Here is an example of the report structure with all important parts of it highlighted:

{
  "version": "2.0",
  "vulnerabilities": [
    {
      "id": "51e83874-0ff6-4677-a4c5-249060554eae",
      "category": "dependency_scanning",
      "name": "Regular Expression Denial of Service",
      "message": "Regular Expression Denial of Service in debug",
      "description": "The debug module is vulnerable to regular expression denial of service when untrusted user input is passed into the `o` formatter. It takes around 50k characters to block for 2 seconds making this a low severity issue.",
      "severity": "Unknown",
      "solution": "Upgrade to latest versions.",
      "scanner": {
        "id": "gemnasium",
        "name": "Gemnasium"
      },
      "location": {
        "file": "yarn.lock",
        "dependency": {
          "package": {
            "name": "debug"
          },
          "version": "1.0.5"
        }
      },
      "identifiers": [
        {
          "type": "gemnasium",
          "name": "Gemnasium-37283ed4-0380-40d7-ada7-2d994afcc62a",
          "value": "37283ed4-0380-40d7-ada7-2d994afcc62a",
          "url": "https://deps.sec.gitlab.com/packages/npm/debug/versions/1.0.5/advisories"
        }
      ],
      "links": [
        {
          "url": "https://nodesecurity.io/advisories/534"
        },
        {
          "url": "https://github.com/visionmedia/debug/issues/501"
        },
        {
          "url": "https://github.com/visionmedia/debug/pull/504"
        }
      ]
    },
    {
      "id": "5d681b13-e8fa-4668-957e-8d88f932ddc7",
      "category": "dependency_scanning",
      "name": "Authentication bypass via incorrect DOM traversal and canonicalization",
      "message": "Authentication bypass via incorrect DOM traversal and canonicalization in saml2-js",
      "description": "Some XML DOM traversal and canonicalization APIs may be inconsistent in handling of comments within XML nodes. Incorrect use of these APIs by some SAML libraries results in incorrect parsing of the inner text of XML nodes such that any inner text after the comment is lost prior to cryptographically signing the SAML message. Text after the comment therefore has no impact on the signature on the SAML message.\r\n\r\nA remote attacker can modify SAML content for a SAML service provider without invalidating the cryptographic signature, which may allow attackers to bypass primary authentication for the affected SAML service provider.",
      "severity": "Unknown",
      "solution": "Upgrade to fixed version.\r\n",
      "scanner": {
        "id": "gemnasium",
        "name": "Gemnasium"
      },
      "location": {
        "file": "yarn.lock",
        "dependency": {
          "package": {
            "name": "saml2-js"
          },
          "version": "1.5.0"
        }
      },
      "identifiers": [
        {
          "type": "gemnasium",
          "name": "Gemnasium-9952e574-7b5b-46fa-a270-aeb694198a98",
          "value": "9952e574-7b5b-46fa-a270-aeb694198a98",
          "url": "https://deps.sec.gitlab.com/packages/npm/saml2-js/versions/1.5.0/advisories"
        },
        {
          "type": "cve",
          "name": "CVE-2017-11429",
          "value": "CVE-2017-11429",
          "url": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-11429"
        }
      ],
      "links": [
        {
          "url": "https://github.com/Clever/saml2/commit/3546cb61fd541f219abda364c5b919633609ef3d#diff-af730f9f738de1c9ad87596df3f6de84R279"
        },
        {
          "url": "https://github.com/Clever/saml2/issues/127"
        },
        {
          "url": "https://www.kb.cert.org/vuls/id/475445"
        }
      ]
    }
  ],
  "remediations": [
    {
      "fixes": [
        {
          "id": "5d681b13-e8fa-4668-957e-8d88f932ddc7",
        }
      ],
      "summary": "Upgrade saml2-js",
      "diff": "ZGlmZiAtLWdpdCBhL...OR0d1ZUc2THh3UT09Cg==" // some content is omitted for brevity
    }
  ]
}
Deprecation: Beginning with GitLab 12.9, dependency scanning no longer reports undefined severity and confidence levels.

Here is the description of the report file structure nodes and their meaning. All fields are mandatory to be present in the report JSON unless stated otherwise. Presence of optional fields depends on the underlying analyzers being used.

Report JSON nodeDescription
versionReport syntax version used to generate this JSON.
vulnerabilitiesArray of vulnerability objects.
vulnerabilities[].idUnique identifier of the vulnerability.
vulnerabilities[].categoryWhere this vulnerability belongs (SAST, Dependency Scanning etc.). For Dependency Scanning, it will always be dependency_scanning.
vulnerabilities[].nameName of the vulnerability, this must not include the occurrence’s specific information. Optional.
vulnerabilities[].messageA short text that describes the vulnerability, it may include occurrence’s specific information. Optional.
vulnerabilities[].descriptionA long text that describes the vulnerability. Optional.
vulnerabilities[].cve(DEPRECATED - use vulnerabilities[].id instead) A fingerprint string value that represents a concrete occurrence of the vulnerability. It’s used to determine whether two vulnerability occurrences are same or different. May not be 100% accurate. This is NOT a CVE.
vulnerabilities[].severityHow much the vulnerability impacts the software. Possible values: Undefined (an analyzer has not provided this information), Info, Unknown, Low, Medium, High, Critical.
vulnerabilities[].confidenceHow reliable the vulnerability’s assessment is. Possible values: Undefined (an analyzer has not provided this information), Ignore, Unknown, Experimental, Low, Medium, High, Confirmed.
vulnerabilities[].solutionExplanation of how to fix the vulnerability. Optional.
vulnerabilities[].scannerA node that describes the analyzer used to find this vulnerability.
vulnerabilities[].scanner.idId of the scanner as a snake_case string.
vulnerabilities[].scanner.nameName of the scanner, for display purposes.
vulnerabilities[].locationA node that tells where the vulnerability is located.
vulnerabilities[].location.filePath to the dependencies file (e.g., yarn.lock). Optional.
vulnerabilities[].location.dependencyA node that describes the dependency of a project where the vulnerability is located.
vulnerabilities[].location.dependency.packageA node that provides the information on the package where the vulnerability is located.
vulnerabilities[].location.dependency.package.nameName of the package where the vulnerability is located. Optional.
vulnerabilities[].location.dependency.versionVersion of the vulnerable package. Optional.
vulnerabilities[].identifiersAn ordered array of references that identify a vulnerability on internal or external DBs.
vulnerabilities[].identifiers[].typeType of the identifier. Possible values: common identifier types (among cve, cwe, osvdb, and usn) or analyzer-dependent ones (e.g. gemnasium for Gemnasium).
vulnerabilities[].identifiers[].nameName of the identifier for display purpose.
vulnerabilities[].identifiers[].valueValue of the identifier for matching purpose.
vulnerabilities[].identifiers[].urlURL to identifier’s documentation. Optional.
vulnerabilities[].linksAn array of references to external documentation pieces or articles that describe the vulnerability further. Optional.
vulnerabilities[].links[].nameName of the vulnerability details link. Optional.
vulnerabilities[].links[].urlURL of the vulnerability details document. Optional.
remediationsAn array of objects containing information on cured vulnerabilities along with patch diffs to apply. Empty if no remediations provided by an underlying analyzer.
remediations[].fixesAn array of strings that represent references to vulnerabilities fixed by this particular remediation.
remediations[].fixes[].idThe id of a fixed vulnerability.
remediations[].fixes[].cve(DEPRECATED - use remediations[].fixes[].id instead) A string value that describes a fixed vulnerability in the same format as vulnerabilities[].cve.
remediations[].summaryOverview of how the vulnerabilities have been fixed.
remediations[].diffbase64-encoded remediation code diff, compatible with git apply.

Versioning and release process

Please check the Release Process documentation.

Contributing to the vulnerability database

You can search the gemnasium-db project to find a vulnerability in the Gemnasium database. You can also submit new vulnerabilities.

Troubleshooting

Error response from daemon: error processing tar file: docker-tar: relocation error

This error occurs when the Docker version used to run the SAST job is 19.03.00. You are advised to update to Docker 19.03.01 or greater. Older versions are not affected. Read more in this issue.