Malware incident response with Semgrep Supply Chain
This document describes how to respond to a malicious dependency incident using Semgrep Supply Chain.
1. Check the results from your most recent full scan
Semgrep maintains a record of the dependencies in your project that is updated whenever a full scan runs. As soon as you have reason to be concerned, check this record to see if those packages and versions were present in your environment at the time of the scan.
You can do this in Semgrep AppSec Platform using the Dependencies tab and its dependency search functionality or through the Semgrep API.
Find malicious versions of packages with dependency search
The dependency search allows you to search:
- For a package using its name, such as
gitdb2 - For a specific version of a package
- For a range of versions, such as
tarversions between 4.0 and 5.0
To search for dependencies:
- Enter the dependency name and press Enter or Return. This returns a list of matches, but you can then filter your results further by version number:
- Click the name of your dependency to open the Dependency dialog:
- To search for a specific version of a package, click Exact match, then enter the version number.
- To search for a range of versions, click Range, then enter the minimum and maximum versions.
- Click Apply to save your changes and see your results.
You can also use the Advanced search to search for specific versions of dependencies:
- Click Advanced search.
- Enter the Dependency name.
- To specify a version number, click Exact match. For a range, click Range and provide the minimum and maximum versions.
- Optional: to search for a specific version of a package, click Exact match, then enter the version number.
- Optional: to search for a range of versions, click Range, then enter the minimum and maximum versions.
You can search for multiple packages simultaneously.
Figure. Sample dependency search for lodash.
You can also use a URL like this: https://semgrep.dev/orgs/-/supply-chain/t/dependencies?q=lodash%40%>4.17
Find malicious versions of packages using the Semgrep API
You can use the Semgrep API to find matching malicious package versions in your projects using the following endpoints:
List dependencies
Use this endpoint to search for specific packages and versions across your deployment. You can filter by ecosystem and specify version ranges or exact versions.
curl -L -g 'https://semgrep.dev/api/v1/deployments/{your_deployment_id}/dependencies' \
-H 'accept: application/json' \
-H 'authorization: Bearer <YOUR_SEMGREP_APP_TOKEN>' \
-H 'Content-Type: application/json' \
-d '{
"dependencyFilter": {
"ecosysystem": [
"npm"
],
"packageFilters": [
{
"name": "lodash",
"versionLowerBound": ">4.17"
},
{
"name": "jridgewell-resolve-uri-latest",
"exactVersion": "9999.999.999"
}
]
},
"deploymentId": <your_deployment_id__int>
}'
Create a new SBOM export job
Use this endpoint to generate a Software Bill of Materials (SBOM) for a specific repository. This is a multi-step process: first create an export job, then poll for its completion to retrieve the download URL.
Step 1: Create the export job
curl -L 'https://semgrep.dev/api/v1/deployments/{your_deployment_id}/sbom/export' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <YOUR_SEMGREP_APP_TOKEN>' \
-d '{
"deploymentId": <your_deployment_id__int>,
"repositoryId": <repository_id_to_export_for__int>,
"sbomOutputFormat": "SBOM_OUTPUT_FORMAT_JSON"
}'
This returns a task token that you'll use to check the job status:
{
"taskToken": "<TASK_TOKEN_FOR_EXPORT_JOB>"
}
Step 2: Poll for job completion
Use the task token from Step 1 to check the export job status:
curl -L 'https://semgrep.dev/api/v1/deployments/{your_deployment_id}/sbom/export/{TASK_TOKEN_FOR_EXPORT_JOB}' \
-H 'Authorization: Bearer <YOUR_SEMGREP_APP_TOKEN>'
When the job completes, the response includes a signed download URL:
{
"status": "SBOM_EXPORT_STATUS_COMPLETED",
"downloadUrl": "https://s3.amazon.com/signed/url/to/download/sbom"
}
You can then download the SBOM from the provided URL.