doc/user/application_security/dependency_scanning/_index.md
{{< details >}}
{{< /details >}}
[!warning] The dependency scanning feature based on the Gemnasium analyzer is deprecated in GitLab 17.9 and is proposed for removal in GitLab 20.0. However, the removal timeline is not finalized, and you can continue using Gemnasium as needed. For more information, see epic 15961.
Dependency scanning integrates into your CI/CD pipelines, and runs automatically to identify security vulnerabilities in your application's dependencies. By scanning branches before they merge, you have immediate visibility of security issues in merge requests. This can help you make informed decisions about potential vulnerabilities before merging your code.
By default, dependency scanning analyzes all dependencies in your code, including runtime, development, and transitive (nested) dependencies. You can optionally exclude development dependencies from scanning.
For vulnerability scanning of dependencies outside a pipeline, see continuous vulnerability scanning.
Follow these steps to turn on dependency scanning in your project.
To enable the analyzer, either:
.gitlab-ci.yml file manually.This method automatically prepares a merge request that includes the dependency scanning template
in the .gitlab-ci.yml file. You then merge the merge request to enable dependency scanning.
[!note] This method works best with no existing
.gitlab-ci.ymlfile, or with a minimal configuration file. If you have a complex GitLab configuration file it might not be parsed successfully, and an error might occur. In that case, use the manual method instead.
Prerequisites:
test stage is required in the .gitlab-ci.yml file.docker or
kubernetes executor.To turn on dependency scanning:
Pipelines now include a dependency scanning job.
.gitlab-ci.yml file manuallyThis method requires you to manually edit the existing .gitlab-ci.yml file. Use this method if
your GitLab CI/CD configuration file is complex.
Prerequisites:
test stage is required in the .gitlab-ci.yml file.docker or
kubernetes executor.To turn on dependency scanning:
In the top bar, select Search or go to and find your project.
Select Build > Pipeline editor.
If no .gitlab-ci.yml file exists, select Configure pipeline, then delete the example
content.
Copy and paste the following to the bottom of the .gitlab-ci.yml file. If an include line
already exists, add only the template line below it.
include:
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
Select the Validate tab, then select Validate pipeline.
The message Simulation completed successfully confirms the file is valid.
Select the Edit tab.
Complete the fields. Do not use the default branch for the Branch field.
Select the Start a new merge request with these changes checkbox, then select Commit changes.
Complete the fields according to your standard workflow, then select Create merge request.
Review and edit the merge request according to your standard workflow, then select Merge.
Pipelines now include a dependency scanning job.
{{< history >}}
{{< /history >}}
Use CI/CD components to perform dependency scanning of your application. For instructions, see the respective component's README file.
See https://gitlab.com/explore/catalog/components/dependency-scanning
After completing these steps, you can:
Dependency scanning results are available in multiple formats. View them directly in the pipeline UI, in the detailed scanning report, or in the Software Bill of Materials (SBOM) generated during the scan.
Review vulnerabilities detected in your pipeline and take action before your merge request is merged.
Prerequisites:
To review dependency scanning results in a pipeline:
Dependency scanning outputs a report containing details of all vulnerabilities. The report is
processed internally and the results are shown in the UI. The report is also output as an artifact
of the dependency scanning job, named gl-dependency-scanning-report.json, and is always generated
at the root of the project.
For more details of the dependency scanning report, see the Dependency scanning report schema.
Dependency scanning outputs a CycloneDX Software Bill of Materials (SBOM) for each supported lockfile or build file it detects.
The CycloneDX SBOMs are:
gl-sbom-<package-type>-<package-manager>.cdx.json.For example, if your project has the following structure:
.
├── ruby-project/
│ └── Gemfile.lock
├── ruby-project-2/
│ └── Gemfile.lock
├── php-project/
│ └── composer.lock
└── go-project/
└── go.sum
Then the Gemnasium scanner generates the following CycloneDX SBOMs:
.
├── ruby-project/
│ ├── Gemfile.lock
│ └── gl-sbom-gem-bundler.cdx.json
├── ruby-project-2/
│ ├── Gemfile.lock
│ └── gl-sbom-gem-bundler.cdx.json
├── php-project/
│ ├── composer.lock
│ └── gl-sbom-packagist-composer.cdx.json
└── go-project/
├── go.sum
└── gl-sbom-go-go.cdx.json
After you are confident in the dependency scanning results for a single project, you can extend its implementation to additional projects:
[!note] Dependency scanning does not support runtime installation of compilers and interpreters.
The following languages and dependency managers are supported by dependency scanning:
<!-- markdownlint-disable MD044 --> <table class="ds-table"> <thead> <tr> <th>Language</th> <th>Language versions</th> <th>Package manager</th> <th>Supported files</th> <th><a href="#how-multiple-files-are-processed">Processes multiple files?</a></th> </tr> </thead> <tbody> <tr> <td>.NET</td> <td rowspan="2">All versions</td> <td rowspan="2"><a href="https://www.nuget.org/">NuGet</a></td> <td rowspan="2"><a href="https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#enabling-lock-file"><code>packages.lock.json</code></a></td> <td rowspan="2">Y</td> </tr> <tr> <td>C#</td> </tr> <tr> <td>C</td> <td rowspan="2">All versions</td> <td rowspan="2"><a href="https://conan.io/">Conan</a></td> <td rowspan="2"><a href="https://docs.conan.io/en/latest/versioning/lockfiles.html"><code>conan.lock</code></a></td> <td rowspan="2">Y</td> </tr> <tr> <td>C++</td> </tr> <tr> <td>Go</td> <td>All versions</td> <td><a href="https://go.dev/">Go</a></td> <td> <ul> <li><code>go.mod</code></li> </ul> </td> <td>Y</td> </tr> <tr> <td rowspan="2">Java and Kotlin</td> <td rowspan="2"> 8 LTS, 11 LTS, 17 LTS, or 21 LTS<sup>1</sup> </td> <td><a href="https://gradle.org/">Gradle</a><sup>2</sup></td> <td> <ul> <li><code>build.gradle</code></li> <li><code>build.gradle.kts</code></li> </ul> </td> <td>N</td> </tr> <tr> <td><a href="https://maven.apache.org/">Maven</a><sup>6</sup></td> <td><code>pom.xml</code></td> <td>N</td> </tr> <tr> <td rowspan="3">JavaScript and TypeScript</td> <td rowspan="3">All versions</td> <td><a href="https://www.npmjs.com/">npm</a></td> <td> <ul> <li><code>package-lock.json</code></li> <li><code>npm-shrinkwrap.json</code></li> </ul> </td> <td>Y</td> </tr> <tr> <td><a href="https://classic.yarnpkg.com/en/">yarn</a></td> <td><code>yarn.lock</code></td> <td>Y</td> </tr> <tr> <td><a href="https://pnpm.io/">pnpm</a><sup>3</sup></td> <td><code>pnpm-lock.yaml</code></td> <td>Y</td> </tr> <tr> <td>PHP</td> <td>All versions</td> <td><a href="https://getcomposer.org/">Composer</a></td> <td><code>composer.lock</code></td> <td>Y</td> </tr> <tr> <td rowspan="5">Python</td> <td rowspan="5">3.11<sup>7</sup></td> <td><a href="https://setuptools.readthedocs.io/en/latest/">setuptools</a><sup>8</sup></td> <td><code>setup.py</code></td> <td>N</td> </tr> <tr> <td><a href="https://pip.pypa.io/en/stable/">pip</a></td> <td> <ul> <li><code>requirements.txt</code></li> <li><code>requirements.pip</code></li> <li><code>requires.txt</code></li> </ul> </td> <td>N</td> </tr> <tr> <td><a href="https://pipenv.pypa.io/en/latest/">Pipenv</a></td> <td> <ul> <li><a href="https://pipenv.pypa.io/en/latest/pipfile.html#example-pipfile"><code>Pipfile</code></a></li> <li><a href="https://pipenv.pypa.io/en/latest/pipfile.html#example-pipfile-lock"><code>Pipfile.lock</code></a></li> </ul> </td> <td>N</td> </tr> <tr> <td><a href="https://python-poetry.org/">Poetry</a><sup>4</sup></td> <td><code>poetry.lock</code></td> <td>N</td> </tr> <tr> <td><a href="https://docs.astral.sh/uv/">uv</a><sup>11</sup></td> <td><code>uv.lock</code></td> <td>Y</td> </tr> <tr> <td>Ruby</td> <td>All versions</td> <td><a href="https://bundler.io/">Bundler</a></td> <td> <ul> <li><code>Gemfile.lock</code></li> <li><code>gems.locked</code></li> </ul> </td> <td>Y</td> </tr> <tr> <td>Scala</td> <td>All versions</td> <td><a href="https://www.scala-sbt.org/">sbt</a><sup>5</sup></td> <td><code>build.sbt</code></td> <td>N</td> </tr> <tr> <td>Swift</td> <td>All versions</td> <td><a href="https://swift.org/package-manager/">Swift Package Manager</a></td> <td><code>Package.resolved</code></td> <td>N</td> </tr> <tr> <td>CocoaPods<sup>9</sup></td> <td>All versions</td> <td><a href="https://cocoapods.org/">CocoaPods</a></td> <td><code>Podfile.lock</code></td> <td>N</td> </tr> <tr> <td>Dart<sup>10</sup></td> <td>All versions</td> <td><a href="https://pub.dev/">Pub</a></td> <td><code>pubspec.lock</code></td> <td>N</td> </tr> </tbody> </table> <!-- markdownlint-disable MD029 -->Footnotes:
poetry.lock file is tracked in issue 32774.pip and setuptools from the report as they are required by the installer.Detection of development dependencies is supported for the following languages and package managers:
<!-- vale gitlab_base.Substitutions = NO --> <!-- markdownlint-disable MD044 -->| Language | Package manager | Files |
|---|---|---|
| C/C++/Fortran/Go/Python/R | conda | conda-lock.yml |
| Java | Maven | maven.graph.json |
| Java/Kotlin | Gradle | dependencies.lock, dependencies.direct.lock, gradle-html-dependency-report.js, gradle.lockfile |
| JavaScript/TypeScript | npm | package-lock.json, npm-shrinkwrap.json |
| JavaScript/TypeScript | pnpm | pnpm-lock.yaml |
| PHP | Composer | composer.lock |
| Python | Pipenv | Pipfile.lock |
| Python | Poetry | poetry.lock |
| Python | uv | uv.lock |
See Use security scanning tools with merge request pipelines
To customize dependency scanning, use CI/CD variables.
[!warning] Test all customization of GitLab analyzers in a merge request before merging these changes to the default branch. Failure to do so can give unexpected results, including a large number of false positives.
To override a job definition (for example, to change properties like variables or dependencies),
declare a new job with the same name as the one to override. Place this new job after the template
inclusion and specify any additional keys under it.
For example, this disables automatic remediation of vulnerable dependencies for the gemnasium
analyzer:
include:
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
gemnasium-dependency_scanning:
variables:
DS_REMEDIATE: "false"
To override the dependencies: [] attribute, add an override job as described previously, targeting this attribute:
include:
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
gemnasium-dependency_scanning:
dependencies: ["build"]
You can use CI/CD variables to customize dependency scanning behavior.
The following variables allow configuration of global dependency scanning settings.
| CI/CD variables | Description |
|---|---|
ADDITIONAL_CA_CERT_BUNDLE | Bundle of CA certificates to trust. The bundle of certificates provided here is also used by other tools during the scanning process, such as git, yarn, or npm. For more details, see Custom TLS certificate authority. |
DS_EXCLUDED_ANALYZERS | Specify the analyzers (by name) to exclude from dependency scanning. For more information, see Analyzers. |
DS_EXCLUDED_PATHS | Exclude files and directories from the scan based on the paths. A comma-separated list of patterns. Patterns can be globs (see doublestar.Match for supported patterns), or file or folder paths (for example, doc,spec). Parent directories also match patterns. This is a pre-filter which is applied before the scan is executed. Default: "spec, test, tests, tmp". |
DS_IMAGE_SUFFIX | Suffix added to the image name. (GitLab team members can view more information in this confidential issue: https://gitlab.com/gitlab-org/gitlab/-/issues/354796). Automatically set to "-fips" when FIPS mode is enabled. |
DS_MAX_DEPTH | Defines how many directory levels deep that the analyzer should search for supported files to scan. A value of -1 scans all directories regardless of depth. Default: 2. |
SECURE_ANALYZERS_PREFIX | Override the name of the Docker registry providing the official default images (proxy). |
The following variables configure the behavior of specific dependency scanning analyzers.
| CI/CD variable | Analyzer | Default | Description |
|---|---|---|---|
GEMNASIUM_DB_LOCAL_PATH | gemnasium | /gemnasium-db | Path to local Gemnasium database. |
GEMNASIUM_DB_UPDATE_DISABLED | gemnasium | "false" | Disable automatic updates for the gemnasium-db advisory database. For usage see Access to the GitLab advisory database. |
GEMNASIUM_DB_REMOTE_URL | gemnasium | https://gitlab.com/gitlab-org/security-products/gemnasium-db.git | Repository URL for fetching the GitLab advisory database. |
GEMNASIUM_DB_REF_NAME | gemnasium | master | Branch name for remote repository database. GEMNASIUM_DB_REMOTE_URL is required. |
GEMNASIUM_IGNORED_SCOPES | gemnasium | Comma-separated list of Maven dependency scopes to ignore. For more details, see the Maven dependency scope documentation | |
DS_REMEDIATE | gemnasium | "true", "false" in FIPS mode | Enable automatic remediation of vulnerable dependencies. Not supported in FIPS mode. |
DS_REMEDIATE_TIMEOUT | gemnasium | 5m | Timeout for auto-remediation. |
GEMNASIUM_LIBRARY_SCAN_ENABLED | gemnasium | "true" | Enable detecting vulnerabilities in vendored JavaScript libraries (libraries which are not managed by a package manager). This functionality requires a JavaScript lockfile to be present in a commit, otherwise dependency scanning is not executed and vendored files are not scanned. |
| Dependency scanning uses the Retire.js scanner to detect a limited set of vulnerabilities. For details of which vulnerabilities are detected, see the Retire.js repository. | |||
DS_INCLUDE_DEV_DEPENDENCIES | gemnasium | "true" | When set to "false", development dependencies and their vulnerabilities are not reported. Only projects using Composer, Maven, npm, pnpm, Pipenv or Poetry are supported. Introduced in GitLab 15.1. |
GOOS | gemnasium | "linux" | The operating system for which to compile Go code. |
GOARCH | gemnasium | "amd64" | The architecture of the processor for which to compile Go code. |
GOFLAGS | gemnasium | The flags passed to the go build tool. | |
GOPRIVATE | gemnasium | A list of glob patterns and prefixes to be fetched from source. For more information, see the Go private modules documentation. | |
DS_JAVA_VERSION | gemnasium-maven | 17 | Version of Java. Available versions: 8, 11, 17, 21. |
MAVEN_CLI_OPTS | gemnasium-maven | "-DskipTests --batch-mode" | List of command line arguments that are passed to maven by the analyzer. See an example for using private repositories. |
GRADLE_CLI_OPTS | gemnasium-maven | List of command line arguments that are passed to gradle by the analyzer. | |
GRADLE_PLUGIN_INIT_PATH | gemnasium-maven | "gemnasium-init.gradle" | Specifies the path to the Gradle initialization script. The init script must include allprojects { apply plugin: 'project-report' } to ensure compatibility. |
DS_GRADLE_RESOLUTION_POLICY | gemnasium-maven | "failed" | Controls Gradle dependency resolution strictness. Accepts "none" to allow partial results, or "failed" to fail the scan when any dependencies fail to resolve. |
SBT_CLI_OPTS | gemnasium-maven | List of command-line arguments that the analyzer passes to sbt. | |
PIP_INDEX_URL | gemnasium-python | https://pypi.org/simple | Base URL of Python Package Index. |
PIP_EXTRA_INDEX_URL | gemnasium-python | Array of extra URLs of package indexes to use in addition to PIP_INDEX_URL. Comma-separated. Warning: Read the following security consideration when using this environment variable. | |
PIP_REQUIREMENTS_FILE | gemnasium-python | Pip requirements file to be scanned. This is a filename and not a path. When this environment variable is set only the specified file is scanned. | |
PIPENV_PYPI_MIRROR | gemnasium-python | If set, overrides the PyPi index used by Pipenv with a mirror. | |
DS_PIP_VERSION | gemnasium-python | Force the install of a specific pip version (example: "19.3"), otherwise the pip installed in the Docker image is used. | |
DS_PIP_DEPENDENCY_PATH | gemnasium-python | Path to load Python pip dependencies from. |
The previous tables are not an exhaustive list of all variables that can be used. They contain all specific GitLab and analyzer variables that are supported and tested. Many other variables, such as environment variables, can be passed in and work correctly. This list is large and not fully documented.
For example, to pass the non-GitLab environment variable HTTPS_PROXY to all dependency scanning jobs,
set it as a CI/CD variable in your .gitlab-ci.yml
file like this:
variables:
HTTPS_PROXY: "https://squid-proxy:3128"
[!note] Gradle projects require an additional variable set up to use a proxy.
Alternatively it may be used in specific jobs, like dependency scanning:
dependency_scanning:
variables:
HTTPS_PROXY: $HTTPS_PROXY
Because all variables have not been tested, you may find that some work and others do not. If you need one that does not work, submitting a feature request or contribute to the code to enable it to be used.
Dependency scanning allows for use of custom TLS certificates for SSL/TLS connections instead of the default shipped with the analyzer container image.
Support for custom certificate authorities was introduced in the following versions.
| Analyzer | Version |
|---|---|
gemnasium | v2.8.0 |
gemnasium-maven | v2.9.0 |
gemnasium-python | v2.7.0 |
Prerequisites:
To use a custom TLS certificate authority:
ADDITIONAL_CA_CERT_BUNDLE.For example, to configure the certificate in the .gitlab-ci.yml file:
variables:
ADDITIONAL_CA_CERT_BUNDLE: |
-----BEGIN CERTIFICATE-----
MIIGqTCCBJGgAwIBAgIQI7AVxxVwg2kch4d56XNdDjANBgkqhkiG9w0BAQsFADCB
...
jWgmPqF3vUbZE0EyScetPJquRFRKIesyJuBFMAs=
-----END CERTIFICATE-----
To allow the dependency analyzer to authenticate with a private Maven repository, you must configure credentials in the CI/CD pipeline. Without authentication, the dependency analyzer cannot access private dependencies, and the scan will fail.
[!warning] Do not add the credentials to your
.gitlab-ci.ymlfile.
Prerequisites:
To allow the dependency analyzer to authenticate with a private Maven repository:
Create a project CI/CD variable named
MAVEN_CLI_OPTS, and set its value to include your credentials.
For example, assuming a settings file named mysettings.xml, username of myuser, and password
of verysecret, you would set the MAVEN_CLI_OPTS CI/CD variable to the following:
--settings mysettings.xml -Drepository.password=verysecret -Drepository.user=myuser
Create the mysettings.xml Maven settings file with your server configuration. The filename must
match the value you specified in the --settings option in step 1.
<!-- mysettings.xml -->
<settings>
...
<servers>
<server>
<id>private_server</id>
<username>${repository.user}</username>
<password>${repository.password}</password>
</server>
</servers>
</settings>
GitLab also offers FIPS-enabled Red Hat UBI
versions of the Gemnasium images. When FIPS mode is enabled in the GitLab instance, Gemnasium
scanning jobs automatically use the FIPS-enabled images. To manually switch to FIPS-enabled images,
set the variable DS_IMAGE_SUFFIX to "-fips".
Dependency scanning for Gradle projects and auto-remediation for Yarn projects are not supported in FIPS mode.
FIPS-enabled images are based on RedHat's UBI micro.
They don't have package managers such as dnf or microdnf
so it's not possible to install system packages at runtime.
{{< details >}}
{{< /details >}}
For instances in an environment with limited, restricted, or intermittent access to external resources through the internet, some adjustments are required for dependency scanning jobs to run successfully. For more information, see Offline environments.
Prerequisites:
docker or kubernetes executorTo use dependency scanning with all supported languages and frameworks:
Import the following default dependency scanning analyzer images from registry.gitlab.com into
your local Docker container registry:
registry.gitlab.com/security-products/gemnasium:6
registry.gitlab.com/security-products/gemnasium:6-fips
registry.gitlab.com/security-products/gemnasium-maven:6
registry.gitlab.com/security-products/gemnasium-maven:6-fips
registry.gitlab.com/security-products/gemnasium-python:6
registry.gitlab.com/security-products/gemnasium-python:6-fips
The process for importing Docker images into a local offline Docker registry depends on your network security policy. Consult your IT staff to find an accepted and approved process by which external resources can be imported or temporarily accessed. These scanners are periodically updated with new definitions, and you may want to download them regularly.
Configure GitLab CI/CD to use the local analyzers.
Set the value of the CI/CD variable SECURE_ANALYZERS_PREFIX to your local Docker registry - in
this example, docker-registry.example.com.
include:
- template: Jobs/Dependency-Scanning.gitlab-ci.yml
variables:
SECURE_ANALYZERS_PREFIX: "docker-registry.example.com/analyzers"
The GitLab advisory database is the
source of vulnerability data used by the gemnasium, gemnasium-maven, and gemnasium-python
analyzers. The Docker images of these analyzers include a clone of the database.
The clone is synchronized with the database before starting a scan,
to ensure the analyzers have the latest vulnerability data.
In an offline environment, the default host of the GitLab advisory database can't be accessed. Instead, you must host the database somewhere that it is accessible to the GitLab runners. You must also update the database manually at your own schedule.
Available options for hosting the database are:
Using a clone of the GitLab advisory database is recommended because it is the most efficient method.
To host a clone of the GitLab advisory database:
.gitlab-ci.yml file, set the value of the CI/CD variable GEMNASIUM_DB_REMOTE_URL to
the URL of the Git repository.For example:
variables:
GEMNASIUM_DB_REMOTE_URL: https://users-own-copy.example.com/gemnasium-db.git
Using a copy of the GitLab advisory database requires you to host an archive file which is downloaded by the analyzers.
To use a copy of the GitLab advisory database:
Download an archive of the GitLab advisory database to a host that is accessible by HTTP from the
GitLab runners. The archive is located at
https://gitlab.com/gitlab-org/security-products/gemnasium-db/-/archive/master/gemnasium-db-master.tar.gz.
Update your .gitlab-ci.yml file.
GEMNASIUM_DB_LOCAL_PATH to use the local copy of the database.GEMNASIUM_DB_UPDATE_DISABLED to disable the database update.variables:
GEMNASIUM_DB_LOCAL_PATH: ./gemnasium-db-local
GEMNASIUM_DB_UPDATE_DISABLED: "true"
dependency_scanning:
before_script:
- wget https://local.example.com/gemnasium_db.tar.gz
- mkdir -p $GEMNASIUM_DB_LOCAL_PATH
- tar -xzvf gemnasium_db.tar.gz --strip-components=1 -C $GEMNASIUM_DB_LOCAL_PATH
The Gradle wrapper script does not read the HTTP(S)_PROXY environment variables. For more details,
see Gradle issue 11065.
Prerequisites:
To make the Gradle wrapper script use a proxy:
Specify the proxy options by using the GRADLE_CLI_OPTS CI/CD variable:
variables:
GRADLE_CLI_OPTS: "-Dhttps.proxyHost=squid-proxy -Dhttps.proxyPort=3128 -Dhttp.proxyHost=squid-proxy -Dhttp.proxyPort=3128 -Dhttp.nonProxyHosts=localhost"
Maven does not read the HTTP(S)_PROXY environment variable. You must instead use a Maven
settings file.
Prerequisites:
To configure the Maven dependency scanner to use a proxy:
Create a mysettings.xml file in the project's repository. Configure the Maven proxy settings in
that file.
For details on how to specify the proxy configuration, see the Maven documentation.
Define the MAVEN_CLI_OPTS CI/CD variable in your project's .gitlab-ci.yml file to reference
the settings file mysettings.xml.
variables:
MAVEN_CLI_OPTS: "--settings mysettings.xml"
See the following sections for configuring specific languages and package managers.
If you need to install Python packages before the analyzer runs, you should use pip install --user in the before_script of the scanning job. The --user flag causes project dependencies to be installed in the user directory. If you do not pass the --user option, packages are installed globally, and they are not scanned and don't show up when listing project dependencies.
If you need to install Python packages before the analyzer runs, you should use python setup.py install --user in the before_script of the scanning job. The --user flag causes project dependencies to be installed in the user directory. If you do not pass the --user option, packages are installed globally, and they are not scanned and don't show up when listing project dependencies.
When using self-signed certificates for your private PyPi repository, no extra job configuration (aside
from the previous .gitlab-ci.yml template) is needed. However, you must update your setup.py to
ensure that it can reach your private repository. Here is an example configuration:
Update setup.py to create a dependency_links attribute pointing at your private repository for each
dependency in the install_requires list:
install_requires=['pyparsing>=2.0.3'],
dependency_links=['https://pypi.example.com/simple/pyparsing'],
Fetch the certificate from your repository URL and add it to the project:
printf "\n" | openssl s_client -connect pypi.example.com:443 -servername pypi.example.com | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > internal.crt
Point setup.py at the newly downloaded certificate:
import setuptools.ssl_support
setuptools.ssl_support.cert_paths = ['internal.crt']
If running in a limited network connectivity environment, you must configure the PIPENV_PYPI_MIRROR
variable to use a private PyPi mirror. This mirror must contain both default and development dependencies.
variables:
PIPENV_PYPI_MIRROR: https://pypi.example.com/simple
Alternatively, if it's not possible to use a private registry, you can load the required packages
into the Pipenv virtual environment cache. For this option, the project must check in the
Pipfile.lock into the repository, and load both default and development packages into the cache.
See the example python-pipenv
project for an example of how this can be done.
Dependency scanning automatically detects the languages used in the repository. All analyzers
matching the detected languages are run. There is usually no need to customize the selection of
analyzers. Do not specify the analyzers so you automatically use the full selection for
best coverage, and avoid the need to make adjustments when there are deprecations or removals.
However, you can override the selection using the variable DS_EXCLUDED_ANALYZERS.
The language detection relies on CI job rules to detect
supported dependency file
For Java and Python, when a supported dependency file is detected, dependency scanning attempts to build the project and execute some Java or Python commands to get the list of dependencies. For all other projects, the lockfile is parsed to obtain the list of dependencies without needing to build the project first.
All direct and transitive dependencies are analyzed, without a limit to the depth of transitive dependencies.
Dependency scanning supports the following official Gemnasium-based analyzers:
gemnasiumgemnasium-mavengemnasium-pythonThe analyzers are published as Docker images, which dependency scanning uses to launch dedicated containers for each analysis. You can also integrate a custom security scanner.
Each analyzer is updated as new versions of Gemnasium are released.
GitLab analyzers obtain dependency information using one of the following two methods:
The following package managers use lockfiles that GitLab analyzers are capable of parsing directly:
<table class="ds-table no-vertical-table-lines"> <thead> <tr> <th>Package Manager</th> <th>Supported File Format Versions</th> <th>Tested Package Manager Versions</th> </tr> </thead> <tbody> <tr> <td>Bundler</td> <td>Not applicable</td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/ruby-bundler/default/Gemfile.lock#L118">1.17.3</a>, <a href="https://gitlab.com/gitlab-org/security-products/tests/ruby-bundler/-/blob/bundler2-FREEZE/Gemfile.lock#L118">2.1.4</a> </td> </tr> <tr> <td>Composer</td> <td>Not applicable</td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/php-composer/default/composer.lock">1.x</a> </td> </tr> <tr> <td>Conan</td> <td>0.4</td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/c-conan/default/conan.lock#L38">1.x</a> </td> </tr> <tr> <td>Go</td> <td>Not applicable</td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/go-modules/gosum/default/go.sum">1.x</a> </td> </tr> <tr> <td>NuGet</td> <td>v1, v2<sup>1</sup></td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/csharp-nuget-dotnetcore/default/src/web.api/packages.lock.json#L2">4.9</a> </td> </tr> <tr> <td>npm</td> <td>v1, v2, v3</td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/js-npm/default/package-lock.json#L4">6.x</a>, <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/js-npm/lockfileVersion2/package-lock.json#L4">7.x</a>, <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/scanner/parser/npm/fixtures/lockfile-v3/simple/package-lock.json#L4">9.x</a> </td> </tr> <tr> <td>pnpm</td> <td>v5, v6, v9</td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/js-pnpm/default/pnpm-lock.yaml#L1">7.x</a>, <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/scanner/parser/pnpm/fixtures/v6/simple/pnpm-lock.yaml#L1">8.x</a> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/scanner/parser/pnpm/fixtures/v9/simple/pnpm-lock.yaml#L1">9.x</a> </td> </tr> <tr> <td>yarn</td> <td>versions 1, 2, 3, 4<sup>2</sup></td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/js-yarn/classic/default/yarn.lock#L2">1.x</a>, <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/js-yarn/berry/v2/default/yarn.lock">2.x</a>, <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/js-yarn/berry/v3/default/yarn.lock">3.x</a> </td> </tr> <tr> <td>Poetry</td> <td>v1</td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/qa/fixtures/python-poetry/default/poetry.lock">1.x</a> </td> </tr> <tr> <td>uv</td> <td>v0.x</td> <td> <a href="https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/blob/master/scanner/parser/uv/fixtures/simple/uv.lock">0.x</a> </td> </tr> </tbody> </table>Footnotes:
Support for NuGet version 2 lockfiles was introduced in GitLab 16.2.
Support for Yarn version 4 was introduced in GitLab 16.11.
The following features are not supported for Yarn Berry:
yarn patchYarn files that contain a patch, a workspace, or both, are still processed, but these features are ignored.
To support the following package managers, the GitLab analyzers proceed in two steps:
Footnotes:
.tool-versions file.gradlew (Gradle wrapper) file or not:
If your project does not use a gradlew file, then the analyzer automatically switches to one of the pre-installed Gradle versions, based on the version of Java specified by the DS_JAVA_VERSION variable (default version is 17).
For Java versions 8 and 11, Gradle 6.7.1 is automatically selected, Java 17 uses Gradle 7.6.4, and Java 21 uses Gradle 8.8.
If your project does use a gradlew file, then the version of Gradle pre-installed in the analyzer image is ignored, and the version specified in your gradlew file is used instead.
Pipfile.lock file is found, it is used by Gemnasium to scan the exact package versions listed in this file.go build, the Go build process requires network access, a pre-loaded mod cache using go mod download, or vendored dependencies. For more information, refer to the Go documentation on compiling packages and dependencies.GitLab relies on rules:exists to start the relevant analyzers for the languages detected by the presence of the
supported files in the repository.
A maximum of two directory levels from the repository's root is searched. For example, the
gemnasium-dependency_scanning job is enabled if a repository contains either Gemfile,
api/Gemfile, or api/client/Gemfile, but not if the only supported dependency file is
api/v1/client/Gemfile.
[!note] If you've run into problems while scanning multiple files, contribute a comment to this issue.
GitLab only executes one installation in the directory where either a requirements file or a lockfile has been detected. Dependencies are only analyzed by gemnasium-python for the first file that is detected. Files are searched for in the following order:
requirements.txt, requirements.pip, or requires.txt for projects using Pip.Pipfile or Pipfile.lock for projects using Pipenv.poetry.lock for projects using Poetry.setup.py for project using Setuptools.The search begins with the root directory and then continues with subdirectories if no builds are found in the root directory. Consequently a Poetry lockfile in the root directory would be detected before a Pipenv file in a subdirectory.
GitLab only executes one build in the directory where a build file has been detected. For large projects that include
multiple Gradle, Maven, or sbt builds, or any combination of these, gemnasium-maven only analyzes dependencies for the first build file
that is detected. Build files are searched for in the following order:
pom.xml for single or multi-module Maven projects.build.gradle or build.gradle.kts for single or multi-project Gradle builds.build.sbt for single or multi-project sbt builds.The search begins with the root directory and then continues with subdirectories if no builds are found in the root directory. Consequently an sbt build file in the root directory would be detected before a Gradle build file in a subdirectory. For multi-module Maven projects, and multi-project Gradle and sbt builds, sub-module and sub-project files are analyzed if they are declared in the parent build file.
The following analyzers are executed, each of which have different behavior when processing multiple files:
Supports multiple lockfiles
Does not support multiple lockfiles. When multiple lockfiles exist, Retire.js
analyzes the first lockfile discovered while traversing the directory tree in alphabetical order.
The gemnasium analyzer scans supports JavaScript projects for vendored libraries
(that is, those checked into the project but not managed by the package manager).
Multiple files are supported. When a go.mod file is detected, the analyzer attempts to generate a build list using
Minimal Version Selection. If this fails, the analyzer instead attempts to parse the dependencies within the go.mod file.
As a requirement, the go.mod file should be cleaned up using the command go mod tidy to ensure proper management of dependencies. The process is repeated for every detected go.mod file.
The analyzer for these languages supports multiple lockfiles.
Support for additional languages, dependency managers, and dependency files are tracked in the following issues:
| Package Managers | Languages | Supported files | Scan tools | Issue |
|---|---|---|---|---|
| Poetry | Python | pyproject.toml | Gemnasium | GitLab#32774 |
Use the most recent version of all containers, and the most recent supported version of all package managers and languages. Using previous versions carries an increased security risk because unsupported versions may no longer benefit from active security reporting and backporting of security fixes.
Do not override the reports.html.destination or reports.html.outputLocation properties when generating an HTML dependency report for Gradle projects. Doing so prevents dependency scanning from functioning correctly.
In isolated networks, if the central repository is a private registry (explicitly set with the <mirror> directive), Maven builds may fail to find the gemnasium-maven-plugin dependency. This issue occurs because Maven doesn't search the local repository (/root/.m2) by default and attempts to fetch from the central repository. The result is an error about the missing dependency.
To resolve this issue, add a <pluginRepositories> section to your settings.xml file. This allows Maven to find plugins in the local repository.
Before you begin, consider the following:
Prerequisites:
Follow these steps to modify the settings.xml file:
Locate your Maven settings.xml file. This file is typically found in one of these locations:
/root/.m2/settings.xml for the root user.~/.m2/settings.xml for a regular user.${maven.home}/conf/settings.xml global settings.Check if there's an existing <pluginRepositories> section in the file.
If a <pluginRepositories> section already exists, add only the following <pluginRepository> element inside it.
Otherwise, add the entire <pluginRepositories> section:
<pluginRepositories>
<pluginRepository>
<id>local2</id>
<name>local repository</name>
<url>file:///root/.m2/repository/</url>
</pluginRepository>
</pluginRepositories>
Run your Maven build or dependency scanning process again.
Extra care needs to be taken when using the PIP_EXTRA_INDEX_URL
environment variable due to a possible exploit documented by CVE-2018-20225:
[!warning] An issue was discovered in pip (all versions) because it installs the version with the highest version number, even if the user had intended to obtain a private package from a private index. This only affects use of the
PIP_EXTRA_INDEX_URLoption, and exploitation requires that the package does not already exist in the public index (and thus the attacker can put the package there with an arbitrary version number).
In some cases it's not possible to determine if the version of a project dependency is in the affected range of a security advisory.
For example:
dev-master or 1.5.x.1.0.0-20241502 can't be compared to 1.0.0-2
because one version contains a timestamp while the other does not.In these cases, the analyzer skips the dependency and outputs a message to the log.
The GitLab analyzers do not make assumptions as they could result in a false positive or false negative. For a discussion, see issue 442027.
Swift Package Manager (SPM) is the official tool for managing the distribution of Swift code. It's integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Follow these best practices when you build a Swift project with SPM.
Include a Package.resolved file.
The Package.resolved file locks your dependencies to specific versions.
Always commit this file to your repository to ensure consistency across
different environments.
git add Package.resolved
git commit -m "Add Package.resolved to lock dependencies"
To build your Swift project, use the following commands:
# Update dependencies
swift package update
# Build the project
swift build
To configure CI/CD, add these steps to your .gitlab-ci.yml file:
swift-build:
stage: build
script:
- swift package update
- swift build
Optional. If you use private Swift package repositories with self-signed certificates, you might need to add the certificate to your project and configure Swift to trust it:
Fetch the certificate:
echo | openssl s_client -servername your.repo.url -connect your.repo.url:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END
CERTIFICATE-/p' > repo-cert.crt
Add these lines to your Swift package manifest (Package.swift):
import Foundation
#if canImport(Security)
import Security
#endif
extension Package {
public static func addCustomCertificate() {
guard let certPath = Bundle.module.path(forResource: "repo-cert", ofType: "crt") else {
fatalError("Certificate not found")
}
SecCertificateAddToSystemStore(SecCertificateCreateWithData(nil, try! Data(contentsOf: URL(fileURLWithPath: certPath)) as CFData)!)
}
}
// Call this before defining your package
Package.addCustomCertificate()
Always test your build process in a clean environment to ensure your dependencies are correctly specified and resolve automatically.
CocoaPods is a popular dependency manager for Swift and Objective-C Cocoa projects. It provides a standard format for managing external libraries in iOS, macOS, watchOS, and tvOS projects.
Follow these best practices when you build projects that use CocoaPods for dependency management.
Include a Podfile.lock file.
The Podfile.lock file is crucial for locking your dependencies to specific versions. Always commit this file to your repository to ensure consistency across different environments.
git add Podfile.lock
git commit -m "Add Podfile.lock to lock CocoaPods dependencies"
You can build your project with one of the following:
The xcodebuild command-line tool:
# Install CocoaPods dependencies
pod install
# Build the project
xcodebuild -workspace YourWorkspace.xcworkspace -scheme YourScheme build
The Xcode IDE:
.xcworkspace file in Xcode.fastlane, a tool for automating builds and releases for iOS and Android apps:
Install fastlane:
sudo gem install fastlane
In your project, configure fastlane:
fastlane init
Add a lane to your fastfile:
lane :build do
cocoapods
gym(scheme: "YourScheme")
end
Run the build:
fastlane build
If your project uses both CocoaPods and Carthage, you can use Carthage to build your dependencies:
Create a Cartfile that includes your CocoaPods dependencies.
Run the following:
carthage update --platform iOS
Configure CI/CD to build the project according to your preferred method.
For example, using xcodebuild:
cocoapods-build:
stage: build
script:
- pod install
- xcodebuild -workspace YourWorkspace.xcworkspace -scheme YourScheme build
Optional. If you use private CocoaPods repositories, you might need to configure your project to access them:
Add the private spec repo:
pod repo add REPO_NAME SOURCE_URL
In your Podfile, specify the source:
source 'https://github.com/CocoaPods/Specs.git'
source 'SOURCE_URL'
Optional. If your private CocoaPods repository uses SSL, ensure the SSL certificate is properly configured:
If you use a self-signed certificate, add it to your system's trusted certificates.
You can also specify the SSL configuration in your .netrc file:
machine your.private.repo.url
login your_username
password your_password
After you update your Podfile, run pod install to install dependencies and update your workspace.
Remember to always run pod install after updating your Podfile to ensure all dependencies are properly installed and the workspace is updated.
To find a vulnerability, you can search the GitLab advisory database.
You can also submit new vulnerabilities.