|
| 1 | +--- |
| 2 | +title: Query VEX for a Docker Hardened Image |
| 3 | +linktitle: Query VEX suppressions via API |
| 4 | +description: Use the DHI GraphQL API to fetch VEX statements and suppressed CVEs for a Docker Hardened Image by digest. |
| 5 | +keywords: dhi vex api, graphql api, suppressed cves, base vex, image digest, docker hardened images |
| 6 | +weight: 47 |
| 7 | +--- |
| 8 | + |
| 9 | +This is a guided example of using the [DHI API](/manuals/dhi/tools/api.md) |
| 10 | +to fetch VEX statements and suppressed CVEs for a Docker Hardened Image (DHI) |
| 11 | +by digest, using the `imagePackagesForImageCoords` query. The query takes an |
| 12 | +image digest and returns every package, every CVE reported against it, |
| 13 | +whether Docker suppresses that CVE, and why. |
| 14 | + |
| 15 | +> [!NOTE] |
| 16 | +> For one-off lookups or local scanning workflows, [`docker scout vex |
| 17 | +> get`](/manuals/dhi/how-to/scan.md#export-vex-attestations) may be simpler. |
| 18 | +> Use the API described here when you need to query many images |
| 19 | +> programmatically. |
| 20 | +
|
| 21 | +For the API endpoint and authentication, see [Use the DHI |
| 22 | +API](/manuals/dhi/tools/api.md). This page assumes you already have a valid |
| 23 | +token. |
| 24 | + |
| 25 | +## Query suppressed CVEs |
| 26 | + |
| 27 | +This is the `imagePackagesForImageCoords` query used in this example. It |
| 28 | +fetches every package in an image, every CVE reported against it, and |
| 29 | +whether Docker suppresses that CVE: |
| 30 | + |
| 31 | +```graphql |
| 32 | +query BaseVex($ctx: Context!, $q: IpImagePackagesForImageCoordsQuery!) { |
| 33 | + imagePackagesForImageCoords(context: $ctx, query: $q) { |
| 34 | + imagePackages { |
| 35 | + packages { |
| 36 | + package { |
| 37 | + purl |
| 38 | + name |
| 39 | + version |
| 40 | + vulnerabilities { |
| 41 | + sourceId |
| 42 | + isExcepted |
| 43 | + fixedBy |
| 44 | + cvss { |
| 45 | + severity |
| 46 | + } |
| 47 | + vulnerabilityExceptions { |
| 48 | + id |
| 49 | + sourceType |
| 50 | + type |
| 51 | + justification |
| 52 | + additionalDetails |
| 53 | + isDhiStatement |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +With variables: |
| 64 | + |
| 65 | +```json |
| 66 | +{ |
| 67 | + "ctx": { "organization": "your-org" }, |
| 68 | + "q": { |
| 69 | + "digest": "sha256:<platform-manifest-digest>", |
| 70 | + "hostName": "hub.docker.com", |
| 71 | + "repoName": "your-org/your-repo", |
| 72 | + "includeExcepted": true, |
| 73 | + "includeNodsa": true |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +For the full argument reference, see |
| 79 | +[`imagePackagesForImageCoords`](/manuals/dhi/tools/api.md#imagepackagesforimagecoords). |
| 80 | + |
| 81 | +### Get an access token |
| 82 | + |
| 83 | +Exchange your organization access token (OAT) or personal access token (PAT) |
| 84 | +for an access token, as described in [Use the DHI |
| 85 | +API](/manuals/dhi/tools/api.md#authentication): |
| 86 | + |
| 87 | +```console |
| 88 | +$ DHI_API_TOKEN=$(curl -s -X POST https://hub.docker.com/v2/auth/token \ |
| 89 | + -H "Content-Type: application/json" \ |
| 90 | + -d "{\"identifier\": \"<identifier>\", \"secret\": \"<token>\"}" \ |
| 91 | + | jq -r .access_token) |
| 92 | +``` |
| 93 | + |
| 94 | +Use your Docker Hub username as `identifier` for a PAT, or your organization |
| 95 | +name for an OAT. |
| 96 | + |
| 97 | +### Send the request |
| 98 | + |
| 99 | +Combine the query and variables into the request body described in [Use the |
| 100 | +DHI API](/manuals/dhi/tools/api.md#request-format). The following example |
| 101 | +uses `jq` to build the body safely, since the query spans multiple lines: |
| 102 | + |
| 103 | +```console |
| 104 | +$ QUERY='query BaseVex($ctx: Context!, $q: IpImagePackagesForImageCoordsQuery!) { |
| 105 | + imagePackagesForImageCoords(context: $ctx, query: $q) { |
| 106 | + imagePackages { |
| 107 | + packages { |
| 108 | + package { |
| 109 | + purl |
| 110 | + name |
| 111 | + version |
| 112 | + vulnerabilities { |
| 113 | + sourceId |
| 114 | + isExcepted |
| 115 | + fixedBy |
| 116 | + cvss { |
| 117 | + severity |
| 118 | + } |
| 119 | + vulnerabilityExceptions { |
| 120 | + id |
| 121 | + sourceType |
| 122 | + type |
| 123 | + justification |
| 124 | + additionalDetails |
| 125 | + isDhiStatement |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | +}' |
| 133 | + |
| 134 | +$ curl https://api.dso.docker.com/v1/graphql \ |
| 135 | + -H "Authorization: Bearer $DHI_API_TOKEN" \ |
| 136 | + -H "Content-Type: application/json" \ |
| 137 | + -d "$(jq -n --arg query "$QUERY" '{ |
| 138 | + query: $query, |
| 139 | + variables: { |
| 140 | + ctx: { organization: "your-org" }, |
| 141 | + q: { |
| 142 | + digest: "sha256:<platform-manifest-digest>", |
| 143 | + hostName: "hub.docker.com", |
| 144 | + repoName: "your-org/your-repo", |
| 145 | + includeExcepted: true, |
| 146 | + includeNodsa: true |
| 147 | + } |
| 148 | + } |
| 149 | + }')" |
| 150 | +``` |
| 151 | + |
| 152 | +Substitute your organization, digest, host, and repository. |
| 153 | + |
| 154 | +## Sample response |
| 155 | + |
| 156 | +The following example is trimmed to a single package: |
| 157 | + |
| 158 | +```json |
| 159 | +{ |
| 160 | + "package": { |
| 161 | + "purl": "pkg:deb/debian/tar@1.35%2Bdfsg-3.1%2Bdhi1?os_distro=trixie&os_name=debian&os_version=13", |
| 162 | + "name": "tar", |
| 163 | + "version": "1.35+dfsg-3.1+dhi1", |
| 164 | + "vulnerabilities": [ |
| 165 | + { |
| 166 | + "sourceId": "CVE-2025-45582", |
| 167 | + "cvss": { "severity": "MEDIUM" }, |
| 168 | + "fixedBy": null, |
| 169 | + "isExcepted": false, |
| 170 | + "vulnerabilityExceptions": [] |
| 171 | + }, |
| 172 | + { |
| 173 | + "sourceId": "CVE-2026-18477", |
| 174 | + "cvss": { "severity": "MEDIUM" }, |
| 175 | + "fixedBy": null, |
| 176 | + "isExcepted": true, |
| 177 | + "vulnerabilityExceptions": [ |
| 178 | + { |
| 179 | + "id": "debian-nodsa-CVE-2026-18477", |
| 180 | + "sourceType": "EXTERNAL", |
| 181 | + "type": "FALSE_POSITIVE", |
| 182 | + "justification": null, |
| 183 | + "additionalDetails": "Debian NODSA", |
| 184 | + "isDhiStatement": false |
| 185 | + } |
| 186 | + ] |
| 187 | + } |
| 188 | + ] |
| 189 | + } |
| 190 | +} |
| 191 | +``` |
| 192 | + |
| 193 | +Use `isExcepted` to tell whether a CVE is suppressed. For the full response |
| 194 | +field reference and the OpenVEX mapping, see |
| 195 | +[`imagePackagesForImageCoords`](/manuals/dhi/tools/api.md#imagepackagesforimagecoords). |
| 196 | + |
| 197 | +## Query customization images |
| 198 | + |
| 199 | +DHI VEX statements apply directly to images built with the [customization |
| 200 | +feature](/manuals/dhi/how-to/customize.md). Query the customized image's own |
| 201 | +digest to get its packages, CVEs, and suppressions in a single call. You |
| 202 | +don't need to query the base image separately. |
| 203 | + |
| 204 | +## Caveats |
| 205 | + |
| 206 | +The suppression set for a given digest can change as new advisories and |
| 207 | +assessments are published. Cache results per digest with a short TTL rather |
| 208 | +than treating a response as permanent. |
0 commit comments