Dependency scanning

  • Tier: Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

The dependency scanning feature based on the Gemnasium analyzer is deprecated in GitLab 17.9 and is planned for removal inGitLab 19.0. It is being replaced withdependency scanning using SBOMand thenew dependency scanning analyzer.For more information, seeepic 15961.

Dependency scanning identifies security vulnerabilities in your application’s dependencies beforethey reach production. This identification protects your application from potential exploits and data breaches thatcould damage user trust and your business reputation. When vulnerabilities are found during pipelineruns, they appear directly in your merge request, giving you immediate visibility of security issuesbefore code is committed.

All dependencies in your code, including transitive (nested) dependencies, are automaticallyanalyzed during pipelines. This analysis catches security issues that manual review processes might miss.Dependency scanning integrates into your existing CI/CD workflow with minimal configuration changes,making it straightforward to implement secure development practices from day one.

Vulnerabilities can also be identified outside a pipeline bycontinuous vulnerability scanning.

GitLab offers both dependency scanning andcontainer scanning toensure coverage for all of these dependency types. To cover as much of your risk area as possible,we encourage you to use all of our security scanners. For a comparison of these features, seeDependency scanning compared to container scanning.

Dependency scanning does not support runtime installation of compilers and interpreters.

Getting started

To get started with dependency scanning the following steps show how to enable it for your project.

Prerequisites:

  • Thetest stage is required in the.gitlab-ci.yml file.
  • With self-managed runners you need a GitLab Runner with thedocker orkubernetes executor.
  • If you’re using SaaS runners on GitLab.com, this is enabled by default.

To enable the analyzer, either:

Use a preconfigured merge request

This method automatically prepares a merge request that includes the dependency scanning templatein the.gitlab-ci.yml file. You then merge the merge request to enable dependency scanning.

This method works best with no existing.gitlab-ci.yml file, or with a minimal configuration file.If you have a complex GitLab configuration file it might not be parsed successfully, and an errormight occur. In that case, use themanual method instead.

To enable dependency scanning:

  1. On the left sidebar, selectSearch or go to and find your project.
  2. SelectSecure >Security configuration.
  3. In theDependency Scanning row, selectConfigure with a merge request.
  4. SelectCreate merge request.
  5. Review the merge request, then selectMerge.

Pipelines now include a dependency scanning job.

Edit the.gitlab-ci.yml file manually

This method requires you to manually edit the existing.gitlab-ci.yml file. Use this method ifyour GitLab CI/CD configuration file is complex.

To enable dependency scanning:

  1. On the left sidebar, selectSearch or go to and find your project.

  2. SelectBuild >Pipeline editor.

  3. If no.gitlab-ci.yml file exists, selectConfigure pipeline, then delete the examplecontent.

  4. Copy and paste the following to the bottom of the.gitlab-ci.yml file. If aninclude linealready exists, add only thetemplate line below it.

    include:-template:Jobs/Dependency-Scanning.gitlab-ci.yml
  5. Select theValidate tab, then selectValidate pipeline.

    The messageSimulation completed successfully confirms the file is valid.

  6. Select theEdit tab.

  7. Complete the fields. Do not use the default branch for theBranch field.

  8. Select theStart a new merge request with these changes checkbox, then selectCommitchanges.

  9. Complete the fields according to your standard workflow, then selectCreatemerge request.

  10. Review and edit the merge request according to your standard workflow, then selectMerge.

Pipelines now include a dependency scanning job.

Use CI/CD components

UseCI/CD components to perform dependency scanning of yourapplication. For instructions, see the respective component’s README file.

Available CI/CD components

Seehttps://gitlab.com/explore/catalog/components/dependency-scanning

After completing these steps, you can:

Understanding the results

You can review vulnerabilities in a pipeline:

  1. On the left sidebar, selectSearch or go to and find your project.
  2. On the left sidebar, selectBuild >Pipelines.
  3. Select the pipeline.
  4. Select theSecurity tab.
  5. Select a vulnerability to view its details, including:
    • Status: Indicates whether the vulnerability has been triaged or resolved.
    • Description: Explains the cause of the vulnerability, its potential impact, and recommended remediation steps.
    • Severity: Categorized into six levels based on impact.Learn more about severity levels.
    • CVSS score: Provides a numeric value that maps to severity.
    • EPSS: Shows the likelihood of a vulnerability being exploited in the wild.
    • Has Known Exploit (KEV): Indicates that a given vulnerability has been exploited.
    • Project: Highlights the project where the vulnerability was identified.
    • Report type / Scanner: Explains the output type and scanner used to generate the output.
    • Reachable: Provides an indication whether the vulnerable dependency is used in code.
    • Scanner: Identifies which analyzer detected the vulnerability.
    • Location: Names the file where the vulnerable dependency is located.
    • Links: Evidence of the vulnerability being cataloged in various advisory databases.
    • Identifiers: A list of references used to classify the vulnerability, such as CVE identifiers.

Dependency scanning produces the following output:

  • Dependency scanning report: Contains details of all vulnerabilities detected in dependencies.
  • CycloneDX Software Bill of Materials: Software Bill of Materials (SBOM) for each supportedlock or build file detected.

Dependency scanning report

Dependency scanning outputs a report containing details of all vulnerabilities. The report isprocessed internally and the results are shown in the UI. The report is also output as an artifactof the dependency scanning job, namedgl-dependency-scanning-report.json.

For more details of the dependency scanning report, see theDependency scanning report schema.

CycloneDX Software Bill of Materials

Dependency scanning outputs aCycloneDX Software Bill of Materials (SBOM)for each supported lock or build file it detects.

The CycloneDX SBOMs are:

  • Namedgl-sbom-<package-type>-<package-manager>.cdx.json.
  • Available as job artifacts of the dependency scanning job.
  • Saved in the same directory as the detected lock or build files.

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

Merging multiple CycloneDX SBOMs

You can use a CI/CD job to merge the multiple CycloneDX SBOMs into a single SBOM. GitLab usesCycloneDX Properties to storeimplementation-specific details in the metadata of each CycloneDX SBOM, such as the location ofbuild and lock files. If multiple CycloneDX SBOMs are merged together, this information is removedfrom the resulting merged file.

For example, the following.gitlab-ci.yml extract demonstrates how the Cyclone SBOM files can bemerged, and the resulting file validated.

stages:-test-merge-cyclonedx-sbomsinclude:-template:Jobs/Dependency-Scanning.gitlab-ci.ymlmerge cyclonedx sboms:stage:merge-cyclonedx-sbomsimage:name:cyclonedx/cyclonedx-cli:0.25.1entrypoint:[""]script:-find . -name "gl-sbom-*.cdx.json" -exec cyclonedx merge --output-file gl-sbom-all.cdx.json --input-files "{}" +# optional: validate the merged sbom-cyclonedx validate --input-version v1_4 --input-file gl-sbom-all.cdx.jsonartifacts:paths:-gl-sbom-all.cdx.json

Roll out

After you are confident in the dependency scanning results for a single project, you can extend its implementation to additional projects:

Supported languages and package managers

The following languages and dependency managers are supported by dependency scanning:

LanguageLanguage versionsPackage managerSupported filesProcesses multiple files?
.NETAll versionsNuGetpackages.lock.jsonY
C#
CAll versionsConanconan.lockY
C++
GoAll versionsGo
  • go.mod
Y
Java and Kotlin8 LTS,11 LTS,17 LTS,or 21 LTS1Gradle2
  • build.gradle
  • build.gradle.kts
N
Maven6pom.xmlN
JavaScript and TypeScriptAll versionsnpm
  • package-lock.json
  • npm-shrinkwrap.json
Y
yarnyarn.lockY
pnpm3pnpm-lock.yamlY
PHPAll versionsComposercomposer.lockY
Python3.117setuptools8setup.pyN
pip
  • requirements.txt
  • requirements.pip
  • requires.txt
N
PipenvN
Poetry4poetry.lockN
uvuv.lockY
RubyAll versionsBundler
  • Gemfile.lock
  • gems.locked
Y
ScalaAll versionssbt5build.sbtN
SwiftAll versionsSwift Package ManagerPackage.resolvedN
Cocoapods9All versionsCocoaPodsPodfile.lockN
Dart10All versionsPubpubspec.lockN

Footnotes:

  1. Java 21 LTS forsbt is limited to version 1.9.7. Support for more sbt versions can be tracked inissue 430335.It is not supported when FIPS mode is enabled.
  2. Gradle is not supported when FIPS mode is enabled.
  3. pnpm lockfiles do not store bundled dependencies, so the reported dependencies may differ from npm or yarn.
  4. Support for projects without apoetry.lock file is tracked inissue 32774.
  5. Support for sbt 1.0.x wasdeprecated in GitLab 16.8 andremoved in GitLab 17.0.
  6. Support for Maven below 3.8.8 wasdeprecated in GitLab 16.9 and removed in GitLab 17.0.
  7. Support for prior Python versions wasdeprecated in GitLab 16.9 andremoved in GitLab 17.0.
  8. Excludes bothpip andsetuptools from the report as they are required by the installer.
  9. Only SBOM, without advisories. Seeissue 468764.
  10. No license detection. Seeepic 17037.

Running jobs in merge request pipelines

SeeUse security scanning tools with merge request pipelines

Customizing analyzer behavior

To customize dependency scanning, useCI/CD variables.

Test all customization of GitLab analyzers in a merge request before merging these changes to thedefault branch. Failure to do so can give unexpected results, including a large number of falsepositives.

Overriding dependency scanning jobs

To override a job definition (for example, to change properties likevariables ordependencies),declare a new job with the same name as the one to override. Place this new job after the templateinclusion and specify any additional keys under it. For example, this disablesDS_REMEDIATE forthegemnasium analyzer:

include:-template:Jobs/Dependency-Scanning.gitlab-ci.ymlgemnasium-dependency_scanning:variables:DS_REMEDIATE:"false"

To override thedependencies: [] attribute, add an override job as described previously, targeting this attribute:

include:-template:Jobs/Dependency-Scanning.gitlab-ci.ymlgemnasium-dependency_scanning:dependencies:["build"]

Available CI/CD variables

You can use CI/CD variables tocustomize dependency scanning behavior.

Global analyzer settings

The following variables allow configuration of global dependency scanning settings.

CI/CD variablesDescription
ADDITIONAL_CA_CERT_BUNDLEBundle of CA certificates to trust. The bundle of certificates provided here is also used by other tools during the scanning process, such asgit,yarn, ornpm. For more details, seeCustom TLS certificate authority.
DS_EXCLUDED_ANALYZERSSpecify the analyzers (by name) to exclude from dependency scanning. For more information, seeAnalyzers.
DS_EXCLUDED_PATHSExclude files and directories from the scan based on the paths. A comma-separated list of patterns. Patterns can be globs (seedoublestar.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_SUFFIXSuffix 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_DEPTHDefines 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_PREFIXOverride the name of the Docker registry providing the official default images (proxy).

Analyzer-specific settings

The following variables configure the behavior of specific dependency scanning analyzers.

CI/CD variableAnalyzerDefaultDescription
GEMNASIUM_DB_LOCAL_PATHgemnasium/gemnasium-dbPath to local Gemnasium database.
GEMNASIUM_DB_UPDATE_DISABLEDgemnasium"false"Disable automatic updates for thegemnasium-db advisory database. For usage seeAccess to the GitLab advisory database.
GEMNASIUM_DB_REMOTE_URLgemnasiumhttps://gitlab.com/gitlab-org/security-products/gemnasium-db.gitRepository URL for fetching the GitLab advisory database.
GEMNASIUM_DB_REF_NAMEgemnasiummasterBranch name for remote repository database.GEMNASIUM_DB_REMOTE_URL is required.
GEMNASIUM_IGNORED_SCOPESgemnasiumComma-separated list of Maven dependency scopes to ignore. For more details, see theMaven dependency scope documentation
DS_REMEDIATEgemnasium"true","false" in FIPS modeEnable automatic remediation of vulnerable dependencies. Not supported in FIPS mode.
DS_REMEDIATE_TIMEOUTgemnasium5mTimeout for auto-remediation.
GEMNASIUM_LIBRARY_SCAN_ENABLEDgemnasium"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 theRetire.js scanner to detect a limited set of vulnerabilities. For details of which vulnerabilities are detected, see theRetire.js repository.
DS_INCLUDE_DEV_DEPENDENCIESgemnasium"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.
GOOSgemnasium"linux"The operating system for which to compile Go code.
GOARCHgemnasium"amd64"The architecture of the processor for which to compile Go code.
GOFLAGSgemnasiumThe flags passed to thego build tool.
GOPRIVATEgemnasiumA list of glob patterns and prefixes to be fetched from source. For more information, see the Go private modulesdocumentation.
DS_JAVA_VERSIONgemnasium-maven17Version of Java. Available versions:8,11,17,21.
MAVEN_CLI_OPTSgemnasium-maven"-DskipTests --batch-mode"List of command line arguments that are passed tomaven by the analyzer. See an example forusing private repositories.
GRADLE_CLI_OPTSgemnasium-mavenList of command line arguments that are passed togradle by the analyzer.
GRADLE_PLUGIN_INIT_PATHgemnasium-maven"gemnasium-init.gradle"Specifies the path to the Gradle initialization script. The init script must includeallprojects { apply plugin: 'project-report' } to ensure compatibility.
DS_GRADLE_RESOLUTION_POLICYgemnasium-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_OPTSgemnasium-mavenList of command-line arguments that the analyzer passes tosbt.
PIP_INDEX_URLgemnasium-pythonhttps://pypi.org/simpleBase URL of Python Package Index.
PIP_EXTRA_INDEX_URLgemnasium-pythonArray ofextra URLs of package indexes to use in addition toPIP_INDEX_URL. Comma-separated.Warning: Readthe following security consideration when using this environment variable.
PIP_REQUIREMENTS_FILEgemnasium-pythonPip 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_MIRRORgemnasium-pythonIf set, overrides the PyPi index used by Pipenv with amirror.
DS_PIP_VERSIONgemnasium-pythonForce the install of a specific pip version (example:"19.3"), otherwise the pip installed in the Docker image is used.
DS_PIP_DEPENDENCY_PATHgemnasium-pythonPath to load Python pip dependencies from.

Other variables

The previous tables are not an exhaustive list of all variables that can be used. They contain all specific GitLab and analyzer variables we support and test. There are many variables, such as environment variables, that you can pass in and they do work. This is a large list, many of which we may be unaware of, and as such is not documented.

For example, to pass the non-GitLab environment variableHTTPS_PROXY to all dependency scanning jobs,set it as aCI/CD variable in your.gitlab-ci.ymlfile like this:

variables:HTTPS_PROXY:"https://squid-proxy:3128"

Gradle projects requirean additional variable setup to use a proxy.

Alternatively we may use it in specific jobs, like dependency scanning:

dependency_scanning:variables:HTTPS_PROXY:$HTTPS_PROXY

As we have not tested all variables you may find some do work and others do not.If one does not work and you need it we suggestsubmitting a feature requestor contributing to the code to enable it to be used.

Custom TLS certificate authority

Dependency scanning allows for use of custom TLS certificates for SSL/TLS connections instead of thedefault shipped with the analyzer container image.

Support for custom certificate authorities was introduced in the following versions.

AnalyzerVersion
gemnasiumv2.8.0
gemnasium-mavenv2.9.0
gemnasium-pythonv2.7.0

Using a custom TLS certificate authority

To use a custom TLS certificate authority, assign thetext representation of the X.509 PEM public-key certificateto the CI/CD variableADDITIONAL_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-----

Authenticate with a private Maven repository

To use a private Maven repository that requires authentication, you should store your credentials ina CI/CD variable and reference them in your Maven settings file. Do not add the credentials to your.gitlab-ci.yml file.

To authenticate with a private Maven repository:

  1. Add theMAVEN_CLI_OPTS CI/CD variable to yourproject’s settings, setting the value to includeyour credentials.

    For example, if your username ismyuser and the password isverysecret:

    TypeKeyValue
    VariableMAVEN_CLI_OPTS--settings mysettings.xml -Drepository.password=verysecret -Drepository.user=myuser
  2. Create a Maven settings file with your server configuration.

    For example, add the following to the settings filemysettings.xml. This file is referenced intheMAVEN_CLI_OPTS CI/CD variable.

    <!-- mysettings.xml --><settings>    ...<servers><server><id>private_server</id><username>${repository.user}</username><password>${repository.password}</password></server></servers></settings>

FIPS-enabled images

GitLab also offersFIPS-enabled Red Hat UBIversions of the Gemnasium images. When FIPS mode is enabled in the GitLab instance, Gemnasiumscanning jobs automatically use the FIPS-enabled images. To manually switch to FIPS-enabled images,set the variableDS_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 asdnf ormicrodnfso it’s not possible to install system packages at runtime.

Offline environment

  • Tier: Ultimate
  • Offering: GitLab Self-Managed

For instances in an environment with limited, restricted, or intermittent accessto external resources through the internet, some adjustments are required for dependency scanningjobs to run successfully. For more information, seeOffline environments.

Requirements

To run dependency scanning in an offline environment you must have:

Local copies of analyzer images

To use dependency scanning with allsupported languages and frameworks:

  1. Import the following default dependency scanning analyzer images fromregistry.gitlab.com intoyourlocal Docker container registry:

    registry.gitlab.com/security-products/gemnasium:6registry.gitlab.com/security-products/gemnasium:6-fipsregistry.gitlab.com/security-products/gemnasium-maven:6registry.gitlab.com/security-products/gemnasium-maven:6-fipsregistry.gitlab.com/security-products/gemnasium-python:6registry.gitlab.com/security-products/gemnasium-python:6-fips

    The process for importing Docker images into a local offline Docker registry depends onyour network security policy. Consult your IT staff to find an accepted and approvedprocess by which external resources can be imported or temporarily accessed.These scanners areperiodically updatedwith new definitions, and you may want to download them regularly.

  2. Configure GitLab CI/CD to use the local analyzers.

    Set the value of the CI/CD variableSECURE_ANALYZERS_PREFIX to your local Docker registry - inthis example,docker-registry.example.com.

    include:-template:Jobs/Dependency-Scanning.gitlab-ci.ymlvariables:SECURE_ANALYZERS_PREFIX:"docker-registry.example.com/analyzers"

Access to the GitLab advisory database

TheGitLab advisory database is thesource of vulnerability data used by thegemnasium,gemnasium-maven, andgemnasium-pythonanalyzers. 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 mustalso update the database manually at your own schedule.

Available options for hosting the database are:

Use a clone of the GitLab advisory database

Using a clone of the GitLab advisory database is recommended because it is the most efficientmethod.

To host a clone of the GitLab advisory database:

  1. Clone the GitLab advisory database to a host that is accessible by HTTP from the GitLab runners.
  2. In your.gitlab-ci.yml file, set the value of the CI/CD variableGEMNASIUM_DB_REMOTE_URL tothe URL of the Git repository.

For example:

variables:GEMNASIUM_DB_REMOTE_URL:https://users-own-copy.example.com/gemnasium-db.git
Use a copy of the GitLab advisory database

Using a copy of the GitLab advisory database requires you to host an archive file which isdownloaded by the analyzers.

To use a copy of the GitLab advisory database:

  1. Download an archive of the GitLab advisory database to a host that is accessible by HTTP from theGitLab runners. The archive is located athttps://gitlab.com/gitlab-org/security-products/gemnasium-db/-/archive/master/gemnasium-db-master.tar.gz.

  2. Update your.gitlab-ci.yml file.

    • Set CI/CD variableGEMNASIUM_DB_LOCAL_PATH to use the local copy of the database.
    • Set CI/CD variableGEMNASIUM_DB_UPDATE_DISABLED to disable the database update.
    • Download and extract the advisory database before the scan begins.
    variables:GEMNASIUM_DB_LOCAL_PATH:./gemnasium-db-localGEMNASIUM_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

Using a proxy with Gradle projects

The Gradle wrapper script does not read theHTTP(S)_PROXY environment variables. Seethis upstream issue.

To make the Gradle wrapper script use a proxy, you can specify the options using theGRADLE_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"

Using a proxy with Maven projects

Maven does not read theHTTP(S)_PROXY environment variables.

To make the Maven dependency scanner use a proxy, you can configure it using asettings.xml file (seeMaven documentation) and instruct Maven to use this configuration by using theMAVEN_CLI_OPTS CI/CD variable:

variables:MAVEN_CLI_OPTS:"--settings mysettings.xml"

Specific settings for languages and package managers

See the following sections for configuring specific languages and package managers.

Python (pip)

If you need to install Python packages before the analyzer runs, you should usepip install --user in thebefore_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.

Python (setuptools)

If you need to install Python packages before the analyzer runs, you should usepython setup.py install --user in thebefore_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 (asidefrom the previous.gitlab-ci.yml template) is needed. However, you must update yoursetup.py toensure that it can reach your private repository. Here is an example configuration:

  1. Updatesetup.py to create adependency_links attribute pointing at your private repository for eachdependency in theinstall_requires list:

    install_requires=['pyparsing>=2.0.3'],dependency_links=['https://pypi.example.com/simple/pyparsing'],
  2. 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
  3. Pointsetup.py at the newly downloaded certificate:

    importsetuptools.ssl_supportsetuptools.ssl_support.cert_paths=['internal.crt']

Python (Pipenv)

If running in a limited network connectivity environment, you must configure thePIPENV_PYPI_MIRRORvariable 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 packagesinto the Pipenv virtual environment cache. For this option, the project must check in thePipfile.lock into the repository, and load both default and development packages into the cache.See the examplepython-pipenvproject for an example of how this can be done.

Dependency detection

Dependency scanning automatically detects the languages used in the repository. All analyzersmatching the detected languages are run. There is usually no need to customize the selection ofanalyzers. We recommend not specifying the analyzers so you automatically use the full selection forbest coverage, avoiding the need to make adjustments when there are deprecations or removals.However, you can override the selection using the variableDS_EXCLUDED_ANALYZERS.

The language detection relies on CI jobrules to detectsupported dependency file

For Java and Python, when a supported dependency file is detected, dependency scanning attempts tobuild the project and execute some Java or Python commands to get the list of dependencies. For allother projects, the lock file is parsed to obtain the list of dependencies without needing to buildthe project first.

All direct and transitive dependencies are analyzed, without a limit to the depth of transitive dependencies.

Analyzers

Dependency scanning supports the following officialGemnasium-based analyzers:

  • gemnasium
  • gemnasium-maven
  • gemnasium-python

The analyzers are published as Docker images, which dependency scanning uses to launch dedicatedcontainers for each analysis. You can also integrate a customsecurity scanner.

Each analyzer is updated as new versions of Gemnasium are released.

How analyzers obtain dependency information

GitLab analyzers obtain dependency information using one of the following two methods:

  1. Parsing lockfiles directly.
  2. Running a package manager or build tool to generate a dependency information file which is then parsed.

Obtaining dependency information by parsing lockfiles

The following package managers use lockfiles that GitLab analyzers are capable of parsing directly:

Package ManagerSupported File Format VersionsTested Package Manager Versions
BundlerNot applicable1.17.3,2.1.4
ComposerNot applicable1.x
Conan0.41.x
GoNot applicable1.x
NuGetv1, v214.9
npmv1, v2, v36.x,7.x,9.x
pnpmv5, v6, v97.x,8.x9.x
yarnversions 1, 2, 3, 421.x,2.x,3.x
Poetryv11.x
uvv0.x0.x

Footnotes:

  1. Support for NuGet version 2 lock files wasintroduced in GitLab 16.2.

  2. Support for Yarn version 4 wasintroduced in GitLab 16.11.

    The following features are not supported for Yarn Berry:

    • Workspaces
    • yarn patch

    Yarn files that contain a patch, a workspace, or both, are still processed, but these features are ignored.

Obtaining dependency information by running a package manager to generate a parsable file

To support the following package managers, the GitLab analyzers proceed in two steps:

  1. Execute the package manager or a specific task, to export the dependency information.
  2. Parse the exported dependency information.
Package ManagerPre-installed VersionsTested Versions
sbt1.6.21.1.6,1.2.8,1.3.12,1.4.6,1.5.8,1.6.2,1.7.3,1.8.3,1.9.6,1.9.7
maven3.9.83.9.81
Gradle6.7.1,7.6.4,8.825.6,6.7,6.9,7.6,8.8
setuptools70.3.0>= 70.3.0
pip2424
Pipenv2023.11.152023.11.153,2023.11.15
Go1.211.214

Footnotes:

  1. This test uses the default version of maven specified by the.tool-versions file.
  2. Different versions of Java require different versions of Gradle. The versions of Gradle listed in the previous table are pre-installed in the analyzer image. The version of Gradle used by the analyzer depends on whether your project uses agradlew (Gradle wrapper) file or not:
    • If your project does not use agradlew file, then the analyzer automatically switches to one of the pre-installed Gradle versions, based on the version of Java specified by theDS_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 agradlew 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.

  3. This test confirms that if aPipfile.lock file is found, it is used by Gemnasium to scan the exact package versions listed in this file.
  4. Because of the implementation ofgo build, the Go build process requires network access, a pre-loaded mod cache usinggo mod download, or vendored dependencies. For more information, refer to theGo documentation on compiling packages and dependencies.

How analyzers are triggered

GitLab relies onrules:exists to start the relevant analyzers for the languages detected by the presence of thesupported files in the repository.A maximum of two directory levels from the repository’s root is searched. For example, thegemnasium-dependency_scanning job is enabled if a repository contains eitherGemfile,api/Gemfile, orapi/client/Gemfile, but not if the only supported dependency file isapi/v1/client/Gemfile.

How multiple files are processed

If you’ve run into problems while scanning multiple files, contribute a comment tothis issue.

Python

We only execute one installation in the directory where either a requirements file or a lock file has been detected. Dependencies are only analyzed bygemnasium-python for the first file that is detected. Files are searched for in the following order:

  1. requirements.txt,requirements.pip, orrequires.txt for projects using Pip.
  2. Pipfile orPipfile.lock for projects using Pipenv.
  3. poetry.lock for projects using Poetry.
  4. 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 lock file in the root directory would be detected before a Pipenv file in a subdirectory.

Java and Scala

We only execute one build in the directory where a build file has been detected. For large projects that includemultiple Gradle, Maven, or sbt builds, or any combination of these,gemnasium-maven only analyzes dependencies for the first build filethat is detected. Build files are searched for in the following order:

  1. pom.xml for single ormulti-module Maven projects.
  2. build.gradle orbuild.gradle.kts for single ormulti-project Gradle builds.
  3. build.sbt for single ormulti-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.Formulti-module Maven projects, and multi-projectGradle andsbt builds, sub-module and sub-project files are analyzed if they are declared in the parent build file.

JavaScript

The following analyzers are executed, each of which have different behavior when processing multiple files:

  • Gemnasium

    Supports multiple lockfiles

  • Retire.js

    Does not support multiple lockfiles. When multiple lockfiles exist,Retire.jsanalyzes the first lockfile discovered while traversing the directory tree in alphabetical order.

Thegemnasium analyzer scans supports JavaScript projects for vendored libraries(that is, those checked into the project but not managed by the package manager).

Go

Multiple files are supported. When ago.mod file is detected, the analyzer attempts to generate abuild list usingMinimal Version Selection. If this fails, the analyzer instead attempts to parse the dependencies within thego.mod file.

As a requirement, thego.mod file should be cleaned up using the commandgo mod tidy to ensure proper management of dependencies. The process is repeated for every detectedgo.mod file.

PHP, C, C++, .NET, C#, Ruby, JavaScript

The analyzer for these languages supports multiple lockfiles.

Support for additional languages

Support for additional languages, dependency managers, and dependency files are tracked in the following issues:

Package ManagersLanguagesSupported filesScan toolsIssue
PoetryPythonpyproject.tomlGemnasiumGitLab#32774

Warnings

We recommend that you 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.

Gradle projects

Do not override thereports.html.destination orreports.html.outputLocation properties when generating an HTML dependency report for Gradle projects. Doing so prevents dependency scanning from functioning correctly.

Maven Projects

In isolated networks, if the central repository is a private registry (explicitly set with the<mirror> directive), Maven builds may fail to find thegemnasium-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.

Workaround

To resolve this issue, add a<pluginRepositories> section to yoursettings.xml file. This allows Maven to find plugins in the local repository.

Before you begin, consider the following:

  • This workaround is only for environments where the default Maven central repository is mirrored to a private registry.
  • After applying this workaround, Maven searches the local repository for plugins, which may have security implications in some environments. Make sure this aligns with your organization’s security policies.

Follow these steps to modify thesettings.xml file:

  1. Locate your Mavensettings.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.
  2. Check if there’s an existing<pluginRepositories> section in the file.

  3. 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>
  4. Run your Maven build or dependency scanning process again.

Python projects

Extra care needs to be taken when using thePIP_EXTRA_INDEX_URLenvironment variable due to a possible exploit documented byCVE-2018-20225:

An issue was discovered in pip (all versions) because it installs the version with the highest version number, even if the user hadintended to obtain a private package from a private index. This only affects use of thePIP_EXTRA_INDEX_URL option, and exploitationrequires that the package does not already exist in the public index (and thus the attacker can put the package there with an arbitraryversion number).

Version number parsing

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:

  • The version is unknown.
  • The version is invalid.
  • Parsing the version or comparing it to the range fails.
  • The version is a branch, likedev-master or1.5.x.
  • The compared versions are ambiguous. For example,1.0.0-20241502 can’t be compared to1.0.0-2because 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 falsenegative. For a discussion, seeissue 442027.

Build Swift projects

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.

  1. Include aPackage.resolved file.

    ThePackage.resolved file locks your dependencies to specific versions.Always commit this file to your repository to ensure consistency acrossdifferent environments.

    git add Package.resolvedgit commit -m"Add Package.resolved to lock dependencies"
  2. To build your Swift project, use the following commands:

    # Update dependenciesswift package update# Build the projectswift build
  3. To configure CI/CD, add these steps to your.gitlab-ci.yml file:

    swift-build:stage:buildscript:-swift package update-swift build
  4. 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:

    1. Fetch the certificate:

      echo| openssl s_client -servername your.repo.url -connect your.repo.url:443| sed -ne'/-BEGIN CERTIFICATE-/,/-ENDCERTIFICATE-/p' > repo-cert.crt
    2. Add these lines to your Swift package manifest (Package.swift):

      importFoundation#ifcanImport(Security)importSecurity#endifextensionPackage{publicstaticfuncaddCustomCertificate(){guardletcertPath=Bundle.module.path(forResource:"repo-cert",ofType:"crt")else{fatalError("Certificate not found")}SecCertificateAddToSystemStore(SecCertificateCreateWithData(nil,try!Data(contentsOf:URL(fileURLWithPath:certPath))asCFData)!)}}// Call this before defining your packagePackage.addCustomCertificate()

Always test your build process in a clean environment to ensure yourdependencies are correctly specified and resolve automatically.

Build CocoaPods projects

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.

  1. Include aPodfile.lock file.

    ThePodfile.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.lockgit commit -m"Add Podfile.lock to lock CocoaPods dependencies"
  2. You can build your project with one of the following:

    • Thexcodebuild command-line tool:

      # Install CocoaPods dependenciespod install# Build the projectxcodebuild -workspace YourWorkspace.xcworkspace -scheme YourScheme build
    • The Xcode IDE:

      1. Open your.xcworkspace file in Xcode.
      2. Select your target scheme.
      3. SelectProduct > Build. You can also press+B.
    • fastlane, a tool for automating builds and releases for iOS and Android apps:

      1. Installfastlane:

        sudo gem install fastlane
      2. In your project, configurefastlane:

        fastlane init
      3. Add a lane to yourfastfile:

        lane:builddococoapodsgym(scheme:"YourScheme")end
      4. Run the build:

        fastlane build
    • If your project uses both CocoaPods and Carthage, you can use Carthage to build your dependencies:

      1. Create aCartfile that includes your CocoaPods dependencies.

      2. Run the following:

        carthage update --platform iOS
  3. Configure CI/CD to build the project according to your preferred method.

    For example, usingxcodebuild:

    cocoapods-build:stage:buildscript:-pod install-xcodebuild -workspace YourWorkspace.xcworkspace -scheme YourScheme build
  4. Optional. If you use private CocoaPods repositories,you might need to configure your project to access them:

    1. Add the private spec repo:

      pod repo add REPO_NAME SOURCE_URL
    2. In your Podfile, specify the source:

      source'https://github.com/CocoaPods/Specs.git'source'SOURCE_URL'
  5. 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
  6. After you update your Podfile, runpod install to install dependencies and update your workspace.

Remember to always runpod install after updating your Podfile to ensure all dependencies are properly installed and the workspace is updated.

Contributing to the vulnerability database

To find a vulnerability, you can search theGitLab advisory database.You can alsosubmit new vulnerabilities.