Skip to content

Commit 3afdd64

Browse files
committed
Tweaks
Signed-off-by: Prabhu Subramanian <[email protected]> Increase cdxgen timeout to 30 minutes Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent b8c3edd commit 3afdd64

File tree

11 files changed

+151
-133
lines changed

11 files changed

+151
-133
lines changed

.github/workflows/pythonapp.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
runs-on: ${{ matrix.os }}
6868
strategy:
6969
matrix:
70-
os: [ubuntu-latest, macos-latest]
70+
os: [macos-latest]
7171
steps:
7272
- uses: actions/checkout@v4
7373
- name: Trim CI agent
@@ -81,7 +81,10 @@ jobs:
8181
- name: Install devenv.sh
8282
run: nix profile install nixpkgs#devenv
8383
- name: Build the devenv shell
84-
run: devenv test
84+
run: |
85+
mkdir -p $HOME/.local/share/pnpm/global
86+
echo "$HOME/.local/share/pnpm/global" >> $GITHUB_PATH
87+
devenv test
8588
- name: Run pytest with uv
8689
run: |
8790
devenv shell uv run pytest --cov=depscan test

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ RUN set -e; \
7474
&& sdk offline enable \
7575
&& mv /root/.sdkman/candidates/* /opt/ \
7676
&& rm -rf /root/.sdkman \
77-
&& npm install -g @cyclonedx/cdxgen @appthreat/atom \
77+
&& npm install -g @cyclonedx/cdxgen @appthreat/atom-parsetools \
7878
&& cdxgen --version \
7979
&& curl -LO "https://dl.google.com/go/go${GO_VERSION}.linux-${GOBIN_VERSION}.tar.gz" \
8080
&& tar -C /usr/local -xzf go${GO_VERSION}.linux-${GOBIN_VERSION}.tar.gz \

depscan/lib/bom.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from datetime import datetime, timezone
77
from urllib.parse import unquote_plus
88

9-
from blint.cyclonedx.spec import CycloneDX
109
from custom_json_diff.lib.utils import json_load, json_dump
1110
from defusedxml.ElementTree import parse
1211
from xbom_lib.blint import BlintGenerator
@@ -326,13 +325,6 @@ def create_blint_bom(
326325
LOG.info(
327326
"The blint invocation was unsuccessful. Try generating the BOM separately."
328327
)
329-
# Empty SBOM is fine if there are no binaries in the project.
330-
elif bom_result.bom_obj and isinstance(bom_result.bom_obj, CycloneDX):
331-
if (
332-
not bom_result.bom_obj.components
333-
and not bom_result.bom_obj.dependencies
334-
):
335-
LOG.debug("Empty SBOM received from blint.")
336328
return bom_result.success and os.path.exists(bom_file)
337329

338330

depscan/lib/explainer.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import re
23
import glob
34
from collections import defaultdict
@@ -58,6 +59,12 @@ def explain(project_type, src_dir, bom_dir, vdr_file, vdr_result, explanation_mo
5859
else "Reachable Flows"
5960
)
6061
for sf in slices_files:
62+
if len(slices_files) > 1:
63+
fn = os.path.basename(sf)
64+
section_label = f"# Explanations for {sf}"
65+
if "-" in fn:
66+
section_label = f"# Explanations for {fn.split('-')[0].upper()}"
67+
console.print(Markdown(section_label))
6168
if (reachables_data := json_load(sf, log=LOG)) and reachables_data.get(
6269
"reachables"
6370
):
@@ -211,7 +218,7 @@ def explain_reachables(
211218
project_type,
212219
vdr_result,
213220
)
214-
if not source_sink_desc or not flow_tree:
221+
if not source_sink_desc or not flow_tree or len(flow_tree.children) < 5:
215222
continue
216223
# In non-reachables mode, we are not interested in reachable flows.
217224
if (
@@ -358,7 +365,7 @@ def flow_to_source_sink(idx, flow, purls, project_type, vdr_result):
358365
source_sink_desc = f"Invocation: {method_full_name}"
359366
elif flow.get("label") == "RETURN" and flow.get("code"):
360367
source_sink_desc = flow.get("code").split("\n")[0]
361-
elif project_type not in ("java") and flow.get("label") == "IDENTIFIER":
368+
elif project_type not in ("java",) and flow.get("label") == "IDENTIFIER":
362369
source_sink_desc = flow.get("code").split("\n")[0]
363370
if source_sink_desc.endswith("("):
364371
source_sink_desc = f":diamond_suit: {source_sink_desc})"
@@ -421,19 +428,21 @@ def filter_tags(tags):
421428

422429

423430
def is_filterable_code(project_type, code):
424-
match project_type:
425-
case "js" | "ts" | "javascript" | "typescript" | "bom":
426-
for c in (
427-
"console.log",
428-
"thoughtLog(",
429-
"_tmp_",
430-
"LOG.debug(",
431-
"options.get(",
432-
"RET",
433-
"this.",
434-
):
435-
if code and code.startswith(c):
436-
return True
431+
if len(code) < 5:
432+
return True
433+
for c in (
434+
"console.log",
435+
"thoughtLog(",
436+
"_tmp_",
437+
"LOG.debug(",
438+
"options.get(",
439+
"RET",
440+
"this.",
441+
"NULL",
442+
"!",
443+
):
444+
if code and code.startswith(c):
445+
return True
437446
return False
438447

439448

@@ -450,17 +459,21 @@ def flow_to_str(explanation_mode, flow, project_type):
450459
node_desc = flow.get("code").split("\n")[0]
451460
if node_desc.endswith("("):
452461
node_desc = f":diamond_suit: {node_desc})"
462+
elif node_desc.startswith("return "):
463+
node_desc = f":arrow_backward: [italic]{node_desc}[/italic]"
453464
tags = filter_tags(flow.get("tags"))
454-
if flow.get("label") == "METHOD_PARAMETER_IN":
465+
if flow.get("label") in ("METHOD_PARAMETER_IN",):
455466
param_name = flow.get("name")
456467
if param_name == "this":
457468
param_name = ""
458469
node_desc = f"{flow.get('parentMethodName')}([red]{param_name}[/red]) :right_arrow_curving_left:"
459470
if tags:
460471
node_desc = f"{node_desc}\n[bold]Tags:[/bold] [italic]{tags}[/italic]\n"
461-
elif flow.get("label") == "IDENTIFIER":
472+
elif flow.get("label") in ("IDENTIFIER", "CALL"):
462473
if node_desc.startswith("<"):
463474
node_desc = flow.get("name")
475+
if flow.get("isExternal"):
476+
node_desc = f"{node_desc} :right_arrow_curving_up:"
464477
if tags:
465478
node_desc = f"{node_desc}\n[bold]Tags:[/bold] [italic]{tags}[/italic]\n"
466479
if tags and not is_filterable_code(project_type, node_desc):
@@ -528,7 +541,7 @@ def explain_flows(explanation_mode, flows, purls, project_type, vdr_result):
528541
file_loc, flow_str, node_desc, has_check_tag_flow = flow_to_str(
529542
explanation_mode, aflow, project_type
530543
)
531-
if last_file_loc and last_file_loc == file_loc:
544+
if not flow_str or (last_file_loc and last_file_loc == file_loc):
532545
continue
533546
last_file_loc = file_loc
534547
if flow_str in added_flows or node_desc in added_node_desc:

devenv.lock

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"devenv": {
44
"locked": {
55
"dir": "src/modules",
6-
"lastModified": 1746190425,
6+
"lastModified": 1747185494,
77
"owner": "cachix",
88
"repo": "devenv",
9-
"rev": "b97652de96e5704fc313d865f2bd1cf8433c514c",
9+
"rev": "b292bc94c2daccda165bc9f909bf6c8056e37a80",
1010
"type": "github"
1111
},
1212
"original": {
@@ -19,10 +19,10 @@
1919
"flake-compat": {
2020
"flake": false,
2121
"locked": {
22-
"lastModified": 1733328505,
22+
"lastModified": 1747046372,
2323
"owner": "edolstra",
2424
"repo": "flake-compat",
25-
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
25+
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
2626
"type": "github"
2727
},
2828
"original": {
@@ -34,10 +34,10 @@
3434
"flake-compat_2": {
3535
"flake": false,
3636
"locked": {
37-
"lastModified": 1733328505,
37+
"lastModified": 1747046372,
3838
"owner": "edolstra",
3939
"repo": "flake-compat",
40-
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
40+
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
4141
"type": "github"
4242
},
4343
"original": {
@@ -49,10 +49,10 @@
4949
"flake-compat_3": {
5050
"flake": false,
5151
"locked": {
52-
"lastModified": 1733328505,
52+
"lastModified": 1747046372,
5353
"owner": "edolstra",
5454
"repo": "flake-compat",
55-
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
55+
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
5656
"type": "github"
5757
},
5858
"original": {
@@ -87,10 +87,10 @@
8787
]
8888
},
8989
"locked": {
90-
"lastModified": 1742649964,
90+
"lastModified": 1746537231,
9191
"owner": "cachix",
9292
"repo": "git-hooks.nix",
93-
"rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82",
93+
"rev": "fa466640195d38ec97cf0493d6d6882bc4d14969",
9494
"type": "github"
9595
},
9696
"original": {
@@ -121,10 +121,10 @@
121121
},
122122
"nixpkgs": {
123123
"locked": {
124-
"lastModified": 1733477122,
124+
"lastModified": 1746807397,
125125
"owner": "cachix",
126126
"repo": "devenv-nixpkgs",
127-
"rev": "7bd9e84d0452f6d2e63b6e6da29fe73fac951857",
127+
"rev": "c5208b594838ea8e6cca5997fbf784b7cca1ca90",
128128
"type": "github"
129129
},
130130
"original": {
@@ -163,10 +163,10 @@
163163
]
164164
},
165165
"locked": {
166-
"lastModified": 1745387063,
166+
"lastModified": 1747201535,
167167
"owner": "bobvanderlinden",
168168
"repo": "nixpkgs-ruby",
169-
"rev": "4363adc15a1137dc4b883a655e8f1db256e3c2e4",
169+
"rev": "978be3ec85a9f8661512432a29e452285c3b3b6b",
170170
"type": "github"
171171
},
172172
"original": {
@@ -177,10 +177,10 @@
177177
},
178178
"nixpkgs-unstable": {
179179
"locked": {
180-
"lastModified": 1746206129,
180+
"lastModified": 1747060738,
181181
"owner": "nixos",
182182
"repo": "nixpkgs",
183-
"rev": "9a7caecf30a0494c88b7daeeed29244cd9a52e7d",
183+
"rev": "eaeed9530c76ce5f1d2d8232e08bec5e26f18ec1",
184184
"type": "github"
185185
},
186186
"original": {

devenv.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ in
6666

6767
# Common packages
6868
packages = [
69-
pkgs.nodejs_23
69+
pkgs-unstable.nodejs_24
7070
pkgs.python312Full
7171
config.languages.python.package.pkgs.astral
7272
pkgs.uv
@@ -82,9 +82,10 @@ in
8282
pnpm setup
8383
source $HOME/.bashrc
8484
export PNPM_GLOBAL_DIR="$HOME/.local/share/pnpm/global"
85+
mkdir -p $PNPM_GLOBAL_DIR
8586
export PATH="$PNPM_GLOBAL_DIR/bin:$PATH"
8687
pnpm config set global-dir "$PNPM_GLOBAL_DIR" --location=global
87-
pnpm add -g --allow-build sqlite3 @cyclonedx/cdxgen
88+
pnpm add -g --allow-build=sqlite3 @cyclonedx/cdxgen
8889
cdxgen --version
8990
python3 --version
9091
uv sync --all-extras --all-packages --dev

packages/analysis-lib/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ds-analysis-lib"
3-
version = "6.0.0a2"
3+
version = "6.0.0a3"
44
description = "Analysis library for owasp depscan"
55
authors = [
66
{name = "Team AppThreat", email = "[email protected]"},

packages/xbom-lib/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ds-xbom-lib"
3-
version = "6.0.0a2"
3+
version = "6.0.0a3"
44
description = "xBOM library for owasp depscan"
55
authors = [
66
{name = "Team AppThreat", email = "[email protected]"},

packages/xbom-lib/src/xbom_lib/cdxgen.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"Accept-Encoding": "gzip",
1818
}
1919

20+
# cdxgen timeout. Increased to 30 minutes
21+
CDXGEN_TIMEOUT_MS = os.getenv("CDXGEN_TIMEOUT_MS", str(int(30 * 60 * 1000)))
22+
2023
# version of cdxgen to use
2124
CDXGEN_IMAGE_VERSION = os.getenv("CDXGEN_IMAGE_VERSION", "latest")
2225
CDXGEN_IMAGE_ROLLING_VERSION = os.getenv("CDXGEN_IMAGE_ROLLING_VERSION", "v11")
@@ -271,6 +274,7 @@ def generate(self) -> BOMResult:
271274
prefix="cdxgen-temp-", dir=os.getenv("DEPSCAN_TEMP_DIR")
272275
)
273276
env["CDXGEN_TEMP_DIR"] = cdxgen_temp_dir
277+
env["CDXGEN_TIMEOUT_MS"] = CDXGEN_TIMEOUT_MS
274278
if cdxgen_cmd:
275279
bom_result = exec_tool(
276280
args,
@@ -405,6 +409,7 @@ def _container_run_cmd(self) -> Tuple[str, List[str]]:
405409
or k in ("FETCH_LICENSE",)
406410
):
407411
run_command_args += ["-e", k]
412+
run_command_args += ["-e", f"CDXGEN_TIMEOUT_MS={CDXGEN_TIMEOUT_MS}"]
408413
# Enabling license fetch will improve metadata such as tags and description
409414
# These will help with semantic reachability analysis
410415
if self.options.get("profile") not in ("generic",):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "owasp-depscan"
3-
version = "6.0.0a2"
3+
version = "6.0.0a3"
44
description = "Fully open-source security audit for project dependencies based on known vulnerabilities and advisories."
55
authors = [
66
{name = "Team AppThreat", email = "[email protected]"},

0 commit comments

Comments
 (0)