Skip to content

Commit 2695dee

Browse files
authored
semantics dotnet (owasp-dep-scan#412)
* Improved semantic reachability by tracking reached packages bundled in binaries. Improves detection for dotnet Signed-off-by: Prabhu Subramanian <[email protected]> * Dotnet repo tests Signed-off-by: Prabhu Subramanian <[email protected]> --------- Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent 876d903 commit 2695dee

File tree

14 files changed

+198
-39
lines changed

14 files changed

+198
-39
lines changed

.github/workflows/repotests-lifecycle-c.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ jobs:
3838
uses: actions/setup-python@v5
3939
with:
4040
python-version: ${{ matrix.python-version }}
41+
- name: Trim CI agent
42+
run: |
43+
chmod +x contrib/free_disk_space.sh
44+
./contrib/free_disk_space.sh
4145
- name: Install depscan
4246
run: |
4347
python -m pip install --upgrade pip

.github/workflows/repotests-lifecycle-dotnet.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
uses: actions/setup-python@v5
3636
with:
3737
python-version: ${{ matrix.python-version }}
38+
- name: Trim CI agent
39+
run: |
40+
chmod +x contrib/free_disk_space.sh
41+
./contrib/free_disk_space.sh
3842
- name: Install depscan
3943
run: |
4044
python -m pip install --upgrade pip
@@ -44,6 +48,7 @@ jobs:
4448
- name: lifecycle-test Damm-Vulnerable-dotNet-Application
4549
run: |
4650
mkdir -p ${GITHUB_WORKSPACE}/depscan_reports/Damm-Vulnerable-dotNet-Application-lifecycle
51+
dotnet build ${GITHUB_WORKSPACE}/repotests/Damm-Vulnerable-dotNet-Application/WebGoat.NET.sln
4752
uv run depscan --src ${GITHUB_WORKSPACE}/repotests/Damm-Vulnerable-dotNet-Application\
4853
--reports-dir ${GITHUB_WORKSPACE}/depscan_reports/Damm-Vulnerable-dotNet-Application\
4954
-t dotnet\

.github/workflows/repotests-lifecycle-go.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
uses: actions/setup-python@v5
3636
with:
3737
python-version: ${{ matrix.python-version }}
38+
- name: Trim CI agent
39+
run: |
40+
chmod +x contrib/free_disk_space.sh
41+
./contrib/free_disk_space.sh
3842
- name: Install depscan
3943
run: |
4044
python -m pip install --upgrade pip
@@ -44,6 +48,9 @@ jobs:
4448
- name: lifecycle-test damn-vulnerable-golang
4549
run: |
4650
mkdir -p ${GITHUB_WORKSPACE}/depscan_reports/damn-vulnerable-golang-lifecycle
51+
cd ${GITHUB_WORKSPACE}/depscan_reports/damn-vulnerable-golang-lifecycle
52+
go build main.go
53+
cd ${GITHUB_WORKSPACE}
4754
uv run depscan --src ${GITHUB_WORKSPACE}/repotests/damn-vulnerable-golang\
4855
--reports-dir ${GITHUB_WORKSPACE}/depscan_reports/damn-vulnerable-golang\
4956
-t go\

.github/workflows/repotests-lifecycle-java.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ jobs:
3030
uses: actions/setup-node@v4
3131
with:
3232
node-version: '23.x'
33+
- name: Trim CI agent
34+
run: |
35+
chmod +x contrib/free_disk_space.sh
36+
./contrib/free_disk_space.sh
3337
- name: Install uv
3438
uses: astral-sh/setup-uv@v5
3539
- name: Setup Python

.github/workflows/repotests.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
with:
3232
repository: 'HooliCorp/vulnerable-aws-koa-app'
3333
path: 'repotests/vulnerable-aws-koa-app'
34+
- uses: actions/checkout@v4
35+
with:
36+
repository: 'microsoft/dotnet-podcasts'
37+
path: 'repotests/dotnet-podcasts'
3438
- uses: actions/setup-go@v5
3539
with:
3640
go-version: '1.23'
@@ -57,6 +61,14 @@ jobs:
5761
uses: actions/setup-python@v5
5862
with:
5963
python-version: ${{ matrix.python-version }}
64+
- uses: actions/setup-dotnet@v4
65+
with:
66+
dotnet-version: '8.x'
67+
- name: Trim CI agent
68+
run: |
69+
chmod +x contrib/free_disk_space.sh
70+
./contrib/free_disk_space.sh
71+
if: ${{ matrix.os != 'windows-latest' }}
6072
- name: Install depscan
6173
run: |
6274
python -m pip install --upgrade pip
@@ -72,13 +84,26 @@ jobs:
7284
shell: bash
7385
env:
7486
BLINTDB_HOME: ${{ runner.temp }}/blintdb-home
87+
- name: repotests dotnet-podcasts
88+
run: |
89+
mkdir -p ${GITHUB_WORKSPACE}/depscan_reports/dotnet-podcasts ${GITHUB_WORKSPACE}/depscan_reports/dotnet-podcasts1 ${GITHUB_WORKSPACE}/depscan_reports/dotnet-podcasts2
90+
dotnet build ${GITHUB_WORKSPACE}/repotests/dotnet-podcasts/NetPodcast.Services.sln
91+
dotnet build ${GITHUB_WORKSPACE}/repotests/dotnet-podcasts/NetPodcast.sln
92+
dotnet build ${GITHUB_WORKSPACE}/repotests/dotnet-podcasts/Podcast.Web.sln
93+
uv run depscan --src ${GITHUB_WORKSPACE}/repotests/dotnet-podcasts --reports-dir ${GITHUB_WORKSPACE}/depscan_reports/dotnet-podcasts -t dotnet --bom-engine CdxgenGenerator
94+
uv run depscan --src ${GITHUB_WORKSPACE}/repotests/dotnet-podcasts --reports-dir ${GITHUB_WORKSPACE}/depscan_reports/dotnet-podcasts1 --profile research -t dotnet --bom-engine CdxgenGenerator --reachability-analyzer FrameworkReachability --explain
95+
uv run depscan --src ${GITHUB_WORKSPACE}/repotests/dotnet-podcasts --reports-dir ${GITHUB_WORKSPACE}/depscan_reports/dotnet-podcasts2 --profile research -t dotnet --bom-engine CdxgenGenerator --reachability-analyzer SemanticReachability --explain
96+
rm -rf ${GITHUB_WORKSPACE}/depscan_reports
97+
shell: bash
98+
env:
99+
BLINTDB_HOME: ${{ runner.temp }}/blintdb-home
75100
- name: repotests vulnerable-aws-koa-app
76101
run: |
77102
mkdir -p ${GITHUB_WORKSPACE}/depscan_reports/vulnerable-aws-koa-app
78103
uv run depscan --src ${GITHUB_WORKSPACE}/repotests/vulnerable-aws-koa-app --reports-dir ${GITHUB_WORKSPACE}/depscan_reports/vulnerable-aws-koa-app -t js --bom-engine CdxgenGenerator
79104
uv run depscan --src ${GITHUB_WORKSPACE}/repotests/vulnerable-aws-koa-app --reports-dir ${GITHUB_WORKSPACE}/depscan_reports/vulnerable-aws-koa-app -t js --bom-engine CdxgenGenerator --reachability-analyzer FrameworkReachability --explain
80105
uv run depscan --src ${GITHUB_WORKSPACE}/repotests/vulnerable-aws-koa-app --reports-dir ${GITHUB_WORKSPACE}/depscan_reports/vulnerable-aws-koa-app -t js --bom-engine CdxgenGenerator --reachability-analyzer SemanticReachability --explain
81-
rm -rf ${GITHUB_WORKSPACE}/depscan_reports ${BLINTDB_HOME}
106+
rm -rf ${GITHUB_WORKSPACE}/depscan_reports
82107
shell: bash
83108
env:
84109
BLINTDB_HOME: ${{ runner.temp }}/blintdb-home

contrib/depscanGPT/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Answer only questions about:
2525
If the user’s question is about creating a BOM or general CycloneDX mechanics (rather than analysing an existing report), redirect them to cdxgenGPT:
2626
“For BOM generation, please try the dedicated assistant here → https://chatgpt.com/g/g-673bfeb4037481919be8a2cd1bf868d2-cdxgen ”
2727
28-
For anything else, respond: “I’m sorry, but I can only help with BOM‑related queries.”
28+
For anything else, respond: “I’m sorry, but I can only help with BOM and VDR‑related queries.”
2929
3030
## Interaction flow
3131
1. Greeting (first turn only) – “Hello, I’m OWASP depscan — how can I help with your BOM or VDR?”
@@ -37,7 +37,7 @@ For anything else, respond: “I’m sorry, but I can only help with BOM‑relat
3737
- SBOM/CBOM/OBOM/ML‑BOM: use components, purl, licenses, properties, etc.
3838
- SaaSBOM: use services, endpoints, authenticated, data.classification.
3939
- Infer ecosystem from purl (pkg:npm → npm, pkg:pypi → Python).
40-
- If coverage is unclear, suggest regenerating with cdxgen --profile ml.
40+
- If coverage is unclear, suggest regenerating with depscan `--profile research` or `--reachability-analyzer SemanticReachability`.
4141
4242
## Understanding depscan reports
4343

contrib/free_disk_space.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ echo "Listing 100 largest packages"
3333
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | tail -n 100
3434
df -h
3535
echo "Removing large packages"
36-
sudo apt-get remove -y '^dotnet-.*'
3736
sudo apt-get remove -y '^llvm-.*'
3837
sudo apt-get remove -y 'php.*'
3938
sudo apt-get remove -y '^mongodb-.*'
@@ -44,10 +43,8 @@ sudo apt-get clean
4443
df -h
4544
echo "Removing large directories"
4645

47-
sudo rm -rf /usr/share/dotnet/
4846
sudo rm -rf /usr/local/graalvm/
4947
sudo rm -rf /usr/local/.ghcup/
5048
sudo rm -rf /usr/local/share/powershell
5149
sudo rm -rf /usr/local/share/chromium
52-
sudo rm -rf /usr/local/lib/android
5350
df -h

depscan/lib/bom.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ def create_lifecycle_boms(cdxgen_lib, src_dir, options):
424424
coptions["deep"] = False
425425
coptions["use_blintdb"] = False
426426
coptions["lifecycles"] = ["post-build"]
427-
res = create_blint_bom(postbuild_bom_file, src_dir, options=coptions)
427+
# What if the build directory is different to the source
428+
build_dir = os.getenv("DEPSCAN_BUILD_DIR") or options.get("build_dir") or src_dir
429+
res = create_blint_bom(postbuild_bom_file, build_dir, options=coptions)
428430
if not res or not os.path.exists(postbuild_bom_file):
429431
LOG.debug(
430432
"The blint invocation was unsuccessful. Try building this project prior to invoking depscan. Alternatively, check if this project generates binary artefacts."

documentation/docs/env-var.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
title: Environment Variables
33
sidebar_position: 7
44
---
5+
56
# Customization through environment variables
67

78
The following environment variables can be used to customize the behavior.
89

9-
- VDB_HOME - Directory to use for caching database. For docker-based execution, this directory should get mounted as a volume from the host
10-
- VDB_DATABASE_URL - Vulnerability DB URL. Defaults to: ghcr.io/appthreat/vdbxz:v6, which includes both app and OS vulnerabilities. For a smaller app-only database, use `ghcr.io/appthreat/vdbxz-app:v6`
11-
- USE_VDB_10Y - Set to true to use the larger 10-year vulnerability database with both app and OS vulnerabilities. Default download url: ghcr.io/appthreat/vdbxz-10y:v6. For an app-only 10 year database use `ghcr.io/appthreat/vdbxz-app-10y:v6`
12-
- VDB_AGE_HOURS - Set the age threshold for the vulnerability database before it is re-downloaded. The default is 24 hours.
13-
- DEPSCAN_TEMP_DIR - Temporary directory to use.
14-
- DEPSCAN_SOURCE_DIR_IMAGE - Alternative to `--src` argument to pass the source directory or image name.
15-
- DEPSCAN_REPORTS_DIR - Alternative to `--reports-dir` to pass the output reports directory.
16-
- DEPSCAN_SOURCE_IMAGE - Source image name to use for lifecycle analysis.
10+
- VDB_HOME - Directory to use for caching database. For docker-based execution, this directory should get mounted as a volume from the host
11+
- VDB_DATABASE_URL - Vulnerability DB URL. Defaults to: ghcr.io/appthreat/vdbxz:v6, which includes both app and OS vulnerabilities. For a smaller app-only database, use `ghcr.io/appthreat/vdbxz-app:v6`
12+
- USE_VDB_10Y - Set to true to use the larger 10-year vulnerability database with both app and OS vulnerabilities. Default download url: ghcr.io/appthreat/vdbxz-10y:v6. For an app-only 10 year database use `ghcr.io/appthreat/vdbxz-app-10y:v6`
13+
- VDB_AGE_HOURS - Set the age threshold for the vulnerability database before it is re-downloaded. The default is 24 hours.
14+
- DEPSCAN_TEMP_DIR - Temporary directory to use.
15+
- DEPSCAN_SOURCE_DIR_IMAGE - Alternative to `--src` argument to pass the source directory or image name.
16+
- DEPSCAN_REPORTS_DIR - Alternative to `--reports-dir` to pass the output reports directory.
17+
- DEPSCAN_SOURCE_IMAGE - Source image name to use for lifecycle analysis. Same as the key `source_image` in the configuration file.
18+
- DEPSCAN_BUILD_DIR - Build directory to use for lifecycle analysis. Blint sbom command will be executed with this directory. Defaults to the source directory (`--src`). Same as the key `build_dir` in the configuration file.

packages/analysis-lib/src/analysis_lib/__init__.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABC, abstractmethod
22
from dataclasses import dataclass
3-
import glob
3+
from pathlib import Path
44
from importlib.metadata import distribution
55
from logging import Logger
66
from typing import Dict, List, Optional
@@ -12,9 +12,10 @@ def get_all_bom_files(from_dir):
1212
"""
1313
Method to collect all BOM files from a given directory.
1414
"""
15-
return glob.glob(f"{from_dir}/**/*bom*.json", recursive=True) + glob.glob(
16-
f"{from_dir}/**/*.cdx.json", recursive=True
17-
)
15+
base = Path(from_dir)
16+
patterns = ["*bom*.json", "*.cdx.json"]
17+
files = {str(p.resolve()) for pattern in patterns for p in base.rglob(pattern)}
18+
return sorted(files)
1819

1920

2021
@dataclass
@@ -121,21 +122,17 @@ def __post_init__(self):
121122
# Collect bom files
122123
if not self.bom_files and self.bom_dir:
123124
self.bom_files = get_all_bom_files(self.bom_dir)
124-
# collect available slices files
125+
# Collect available slices files
125126
if not self.slices_files and self.bom_dir:
126-
self.slices_files = glob.glob(
127-
f"{self.bom_dir}/**/*slices.json", recursive=True
127+
self.slices_files = sorted(
128+
str(p.resolve()) for p in Path(self.bom_dir).rglob("*slices.json")
128129
)
129-
# collect the openapi spec files
130+
# Collect the openapi spec files
130131
if not self.openapi_spec_files:
131-
if self.bom_dir:
132-
self.openapi_spec_files = glob.glob(
133-
f"{self.bom_dir}/*openapi*.json", recursive=False
134-
)
135-
elif self.src_dir:
136-
self.openapi_spec_files = glob.glob(
137-
f"{self.src_dir}/*openapi*.json", recursive=False
138-
)
132+
search_dir = Path(self.bom_dir) if self.bom_dir else Path(self.src_dir)
133+
self.openapi_spec_files = sorted(
134+
str(p.resolve()) for p in search_dir.glob("*openapi*.json")
135+
)
139136

140137

141138
@dataclass

0 commit comments

Comments
 (0)