py39h1234567_0 on linux-64. If Anaconda patches the vulnerability in a later build of 1.2.3, the patched build isn’t identified as affected.
Anaconda produces advisories through the same curation process that powers the CVE information shown in Anaconda Platform. For more information about CVEs and the curation process, see Common Vulnerabilities and Exposures (CVEs).
Authentication
Obtaining a token
Exchange your service account credentials for an access token:access_token:
Access tokens expire after 15 minutes (900 seconds). If your sync job runs longer, request a new token when the current one expires.
Making authenticated requests
Include the token in theAuthorization header:
Base URL
Endpoints
Syncing the advisory feed
Sync the feed to keep your own up-to-date copy of Anaconda’s advisory data. The first sync downloads every advisory Anaconda has published; later syncs download only what changed. With a local copy of the advisory data, your tooling can check every package you run against the latest CVEs, as often as you want, without an API call for each check. On your first sync, request the feed with no parameters to get every advisory Anaconda has published. Run a full sync only once. The response returns awatermark; save it. On later syncs, pass that watermark as the modified_since parameter to get only the advisories that changed since your last sync.
The response contains advisories and pagination metadata:
Response pagination metadata example
watermark: The most recent change included in the results. The watermark is the same on every page of a sync. Save it when you reach the last page; it’s your starting point for the next sync.continuationandnext_url: Present while more pages remain. To get the next page, follow thenext_url, or pass thecontinuationvalue back as thecontinuationquery parameter. When you passcontinuation, the API ignores all other query parameters. Continuation tokens stay valid for at least 24 hours, but don’t persist them long term like thewatermark.has_more: Displaystruewhile more pages remain.
artifact_sha256s) so your tooling can match them against installed packages. Each PURL corresponds to one of the SHA256 hashes in artifact_sha256s; either one works as a lookup key.
For a working implementation of this pattern, continue to Monitoring for new advisories with Python.
Monitoring for new advisories with Python
The following script shows the full sync pattern. It gets an access token, downloads the advisories that changed since the last run, saves the new watermark, and prints a summary. On the first run, when no watermark exists, it downloads the full feed. The script requires therequests package, and it reads your service account credentials from environment variables.
To use the script:
1
Set the environment variables
2
Save the script
Save the following script as
sync.py:3
Run the script
The first full sync can take long enough that the access token expires. If a request returns a
401 error, get a new token and continue paging from the last next_url.4
Schedule the script
Optional. To keep monitoring over time, schedule the script to run regularly, for example, with cron or a scheduled CI job.
Matching advisories against your environments
What you do with changed advisories depends on your systems. One common approach is to compare the packages each advisory affects against the packages you have installed. The following example extends the script above. Add it to the same file. The example parses the PURLs of the affected artifacts and compares them with the packages installed in the active conda environment. The match is exact: the name, version, build, and platform must all match. It checks only the advisories from the current sync (changed), so it doesn’t call the API again.
The example requires the
packageurl-python package (conda install packageurl-python).The example checks the environment that’s active when the script runs. To check a different environment, pass its name to
Matching on the exact artifact matters: Anaconda sometimes fixes a vulnerability in a new build of the same package version, and some CVEs affect only certain platforms. Advisories identify only artifacts that Anaconda builds and maintains, so packages installed from other channels, such as conda-forge, don’t match. For the strictest comparison, match on the advisory’s
conda list, for example conda list --name <ENV_NAME> --json.Keep this in mind when you schedule the script: cron jobs and CI runners don’t activate environments, so the active environment is base unless the job activates another one or targets it by name.Matching on the exact artifact matters: Anaconda sometimes fixes a vulnerability in a new build of the same package version, and some CVEs affect only certain platforms. Advisories identify only artifacts that Anaconda builds and maintains, so packages installed from other channels, such as conda-forge, don’t match. For the strictest comparison, match on the advisory’s
artifact_sha256s instead of the PURL qualifiers.