|
| 1 | +--- |
| 2 | +stage: Application Security Testing |
| 3 | +group: Composition Analysis |
| 4 | +info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://handbook.gitlab.com/handbook/product/ux/technical-writing/#assignments |
| 5 | +title: Static reachability analysis |
| 6 | +--- |
| 7 | + |
| 8 | +{{< details >}} |
| 9 | + |
| 10 | +- Tier: Ultimate |
| 11 | +- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated |
| 12 | +- Status: Beta |
| 13 | + |
| 14 | +{{< /details >}} |
| 15 | + |
| 16 | +{{< history >}} |
| 17 | + |
| 18 | +- [Introduced](https://gitlab.com/groups/gitlab-org/-/epics/14177) as an [experiment](../../../policy/development_stages_support.md) in GitLab 17.5. |
| 19 | +- [Changed](https://gitlab.com/groups/gitlab-org/-/epics/15781) from experiment to beta in GitLab 17.11. |
| 20 | + |
| 21 | +{{< /history >}} |
| 22 | + |
| 23 | +Static reachability analysis (SRA) helps you prioritize remediation of vulnerabilities in dependencies. |
| 24 | + |
| 25 | +An application is generally deployed with many dependencies. Dependency scanning identifies which of |
| 26 | +those dependencies have vulnerabilities. However, not all dependencies are used by an application. |
| 27 | +Static reachability analysis identifies those dependencies that are used, in other words reachable, |
| 28 | +and so are a higher security risk than others. Use this information to help prioritize remediation |
| 29 | +of vulnerabilities according to risk. |
| 30 | + |
| 31 | +To identify vulnerable dependencies that are reachable, either: |
| 32 | + |
| 33 | +- Hover over the **Severity** value of a vulnerability in the vulnerability report. |
| 34 | +- Check the `Reachable` value in the vulnerability page. |
| 35 | +- Use a GraphQL query to list those vulnerabilities that are reachable. |
| 36 | + |
| 37 | +## Supported languages and package managers |
| 38 | + |
| 39 | +Static reachability analysis is available only for Python projects. SRA uses the new dependency |
| 40 | +scanning analyzer to generate SBOMs and so supports the same package managers as the analyzer. |
| 41 | + |
| 42 | +| Language | Supported Package Managers | |
| 43 | +|----------|----------------------------| |
| 44 | +| Python | `pip`, `pipenv`, `poetry`, `uv` | |
| 45 | + |
| 46 | +## Enable static reachability analysis |
| 47 | + |
| 48 | +Enable static reachability analysis to identify high-risk dependencies. |
| 49 | + |
| 50 | +Prerequisites: |
| 51 | + |
| 52 | +- Enable [Dependency Scanning by using SBOM](dependency_scanning_sbom/_index.md#configuration). |
| 53 | + |
| 54 | + Make sure you follow the [pip](dependency_scanning_sbom/_index.md#pip) or [pipenv](dependency_scanning_sbom/_index.md#pipenv) |
| 55 | + related instructions for dependency scanning using SBOM. You can also use any other Python package manager that is [supported](https://gitlab.com/gitlab-org/security-products/analyzers/dependency-scanning#supported-files) by the DS analyzer. |
| 56 | + |
| 57 | +To enable static reachability analysis: |
| 58 | + |
| 59 | +- Edit the project `.gitlab-ci.yml` file and set `DS_STATIC_REACHABILITY_ENABLED` to `true`. |
| 60 | + |
| 61 | +Enabling static reachability: |
| 62 | + |
| 63 | +```yaml |
| 64 | +stages: |
| 65 | + - build |
| 66 | + - test |
| 67 | + |
| 68 | +include: |
| 69 | + - template: Jobs/Dependency-Scanning.latest.gitlab-ci.yml |
| 70 | + |
| 71 | +variables: |
| 72 | + DS_STATIC_REACHABILITY_ENABLED: true |
| 73 | + DS_ENFORCE_NEW_ANALYZER: true |
| 74 | + |
| 75 | +# Build job required by the DS analyzer to create pipdeptree.json |
| 76 | +# https://docs.gitlab.com/user/application_security/dependency_scanning/dependency_scanning_sbom/#pip |
| 77 | +build: |
| 78 | + stage: build |
| 79 | + image: "python:latest" |
| 80 | + script: |
| 81 | + - "pip install -r requirements.txt" |
| 82 | + - "pip install pipdeptree" |
| 83 | + - "pipdeptree --json > pipdeptree.json" |
| 84 | + artifacts: |
| 85 | + when: on_success |
| 86 | + access: developer |
| 87 | + paths: ["**/pipdeptree.json"] |
| 88 | +``` |
| 89 | +
|
| 90 | +The dependency scanning analyzer requires specific lock files to function properly. These files must |
| 91 | +be generated during a build job on a stage prior to dependency scanning. By default, the dependency |
| 92 | +scanning with reachability job is configured to depend on a job named `build`. If you need to use a |
| 93 | +different name for your build job, you must override the dependency scanning `needs` section in your |
| 94 | +configuration. Below is an example using `pip-compile` to generate a requirement lock file. This |
| 95 | +file is passed to the new DS analyzer by using the `DS_PIPCOMPILE_REQUIREMENTS_FILE_NAME_PATTERN` |
| 96 | +because the name is not standard. |
| 97 | + |
| 98 | +```yaml |
| 99 | +stages: |
| 100 | + - build |
| 101 | + - test |
| 102 | +
|
| 103 | +include: |
| 104 | + - template: Jobs/Dependency-Scanning.latest.gitlab-ci.yml |
| 105 | +
|
| 106 | +variables: |
| 107 | + DS_ENFORCE_NEW_ANALYZER: true |
| 108 | + DS_STATIC_REACHABILITY_ENABLED: true |
| 109 | + DS_PIPCOMPILE_REQUIREMENTS_FILE_NAME_PATTERN: "requirements-lock.txt" |
| 110 | +
|
| 111 | +create: |
| 112 | + stage: build |
| 113 | + image: "python:3.12" |
| 114 | + script: |
| 115 | + - pip install pip-tools |
| 116 | + - pip-compile requirements.txt -o requirements-lock.txt |
| 117 | + artifacts: |
| 118 | + when: on_success |
| 119 | + access: developer |
| 120 | + paths: ["**/requirements-lock.txt"] |
| 121 | +
|
| 122 | +dependency-scanning-with-reachability: |
| 123 | + needs: |
| 124 | + - job: gitlab-static-reachability |
| 125 | + optional: true |
| 126 | + artifacts: true |
| 127 | + # For supporting Scan Execution Policies. |
| 128 | + - job: gitlab-static-reachability-0 |
| 129 | + optional: true |
| 130 | + artifacts: true |
| 131 | + - job: create # Instead of depending on build job it depends on `create` job |
| 132 | + optional: true |
| 133 | + artifacts: true |
| 134 | +``` |
| 135 | +
|
| 136 | +Static reachability introduces two key jobs: |
| 137 | +
|
| 138 | +- `gitlab-static-reachability`: Performs Static Reachability Analysis (SRA) on your Python files. |
| 139 | +- `dependency-scanning-with-reachability`: Executes dependency scanning and generates an SBOM report enriched with reachability data. This job requires the artifact output from the `gitlab-static-reachability` job. |
| 140 | + |
| 141 | +{{< alert type="note" >}} |
| 142 | + |
| 143 | +When you enable static reachability feature for non-Python projects, the |
| 144 | +`gitlab-static-reachability` job will fail but won't break your pipeline, because it's configured to |
| 145 | +allow failures. In such cases, the `dependency-scanning-with-reachability` job will perform standard |
| 146 | +dependency scanning without adding reachability data to the SBOM. |
| 147 | + |
| 148 | +{{< /alert >}} |
| 149 | + |
| 150 | +Static reachability analysis functionality is supported in [Dependency Scanning analyzer](https://gitlab.com/gitlab-org/security-products/analyzers/dependency-scanning) version `0.23.0` and all subsequent versions. |
| 151 | + |
| 152 | +{{< alert type="warning" >}} |
| 153 | + |
| 154 | +Changes to the CI/CD configuration for static reachability integration are proposed for the GA release. |
| 155 | + |
| 156 | +{{< /alert >}} |
| 157 | + |
| 158 | +## How static reachability analysis works |
| 159 | + |
| 160 | +Static reachability analysis requires two key components: |
| 161 | + |
| 162 | +- Dependency scanning (DS): Generates an SBOM report that identifies all components and their transitive dependencies. |
| 163 | +- GitLab Advanced SAST (GLAS): Performs static reachability analysis to provide a report showing direct dependencies usage in the codebase. |
| 164 | + |
| 165 | +Static reachability analysis adds reachability data to the SBOM output by dependency scanning. The enriched SBOM is then ingested by the GitLab instance. |
| 166 | + |
| 167 | +Reachability data in the UI can have one of the following values: |
| 168 | + |
| 169 | +| Reachability values | Description | |
| 170 | +|---------------------|---------------------------------------------------------------------------| |
| 171 | +| Yes | The package linked to this vulnerability is confirmed reachable in code | |
| 172 | +| Not Found | SRA ran successfully but did not detect usage of the vulnerable package | |
| 173 | +| Not Available | SRA was not executed, therefore no reachability data exists | |
| 174 | + |
| 175 | +## Where to find the reachability data |
| 176 | + |
| 177 | +The reachability data is available in the vulnerability report |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | +and the vulnerability page |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | +Finally reachability data can be reached using GraphQL. |
| 186 | + |
| 187 | +{{< alert type="warning" >}} |
| 188 | + |
| 189 | +When a vulnerability reachability value shows as "Not Found," exercise caution rather than completely dismissing it, because the beta version of SRA may produce false negatives. |
| 190 | + |
| 191 | +{{< /alert >}} |
| 192 | + |
| 193 | +## Restrictions |
| 194 | + |
| 195 | +Static reachability analysis has the following limitations: |
| 196 | + |
| 197 | +- Offline GitLab instances are not supported, though this is proposed for the GA release. |
| 198 | +- When a direct dependency is marked as `in use`, all its transitive dependencies are also marked as `in use`. |
| 199 | +- Requires the new [dependency scanning analyzer](https://gitlab.com/gitlab-org/security-products/analyzers/dependency-scanning). [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) analyzers are not supported. |
| 200 | +- SRA on beta doesn't officially support pipeline execution policies. |
| 201 | +- SRA on beta works with scan execution policies (SEP), but with the following restrictions: |
| 202 | + - only dependency scanning and/or static reachability jobs should be added through SEP. You should avoid having a policy while also including the latest dependency scanning template in your project configuration. |
| 203 | + - Users cannot override the build job name that `dependency-scanning-with-reachability` depends on. Consequently if a build job is required to create a lock file for the dependency scanning analyzer then the name must be named `build`. |
0 commit comments