owasp-depscan 4.2.5__py3-none-any.whl → 4.2.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of owasp-depscan might be problematic. Click here for more details.

depscan/cli.py CHANGED
@@ -12,11 +12,14 @@ from rich.terminal_theme import MONOKAI
12
12
  from vdb.lib import config
13
13
  from vdb.lib import db as db_lib
14
14
  from vdb.lib.aqua import AquaSource
15
+ from vdb.lib.config import data_dir
15
16
  from vdb.lib.gha import GitHubSource
16
17
  from vdb.lib.nvd import NvdSource
17
18
  from vdb.lib.osv import OSVSource
18
19
  from vdb.lib.utils import parse_purl
19
20
 
21
+ import oras.client
22
+
20
23
  from depscan.lib import privado, utils
21
24
  from depscan.lib.analysis import (
22
25
  PrepareVexOptions,
@@ -29,9 +32,10 @@ from depscan.lib.analysis import (
29
32
  )
30
33
  from depscan.lib.audit import audit, risk_audit, risk_audit_map, type_audit_map
31
34
  from depscan.lib.bom import create_bom, get_pkg_by_type, get_pkg_list, submit_bom
32
- from depscan.lib.config import UNIVERSAL_SCAN_TYPE, license_data_dir, spdx_license_list
35
+ from depscan.lib.config import UNIVERSAL_SCAN_TYPE, license_data_dir, spdx_license_list, vdb_database_url
33
36
  from depscan.lib.license import build_license_data, bulk_lookup
34
37
  from depscan.lib.logger import LOG, console
38
+ from depscan.lib.utils import get_version
35
39
 
36
40
  try:
37
41
  os.environ["PYTHONIOENCODING"] = "utf-8"
@@ -75,13 +79,6 @@ def build_args():
75
79
  dest="cache",
76
80
  help="Cache vulnerability information in platform specific " "user_data_dir",
77
81
  )
78
- parser.add_argument(
79
- "--cache-os",
80
- action="store_true",
81
- default=False,
82
- dest="cache_os",
83
- help="Cache OS vulnerability information in platform specific " "user_data_dir",
84
- )
85
82
  parser.add_argument(
86
83
  "--sync",
87
84
  action="store_true",
@@ -239,6 +236,13 @@ def build_args():
239
236
  dest="cdxgen_server",
240
237
  help="cdxgen server url. Eg: http://cdxgen:9090",
241
238
  )
239
+ parser.add_argument(
240
+ "-v",
241
+ "--version",
242
+ help="Display the version",
243
+ action="version",
244
+ version="%(prog)s " + get_version(),
245
+ )
242
246
  return parser.parse_args()
243
247
 
244
248
 
@@ -383,6 +387,32 @@ def summarise(
383
387
  with open(bom_file, encoding="utf-8") as fp:
384
388
  bom_data = json.load(fp)
385
389
  if bom_data:
390
+ # Add depscan information as metadata
391
+ metadata = bom_data.get("metadata", {})
392
+ tools = metadata.get("tools", {})
393
+ bom_version = str(bom_data.get("version", 1))
394
+ # Update the version
395
+ if bom_version.isdigit():
396
+ bom_version = int(bom_version) + 1
397
+ bom_data["version"] = bom_version
398
+ # Update the tools section
399
+ if isinstance(tools, dict):
400
+ components = tools.get("components", [])
401
+ ds_version = get_version()
402
+ ds_purl = f"pkg:pypi/owasp-depscan@{ds_version}"
403
+ components.append(
404
+ {
405
+ "type": "application",
406
+ "name": "owasp-depscan",
407
+ "version": ds_version,
408
+ "purl": ds_purl,
409
+ "bom-ref": ds_purl,
410
+ }
411
+ )
412
+ tools["components"] = components
413
+ metadata["tools"] = tools
414
+ bom_data["metadata"] = metadata
415
+
386
416
  bom_data["vulnerabilities"] = pkg_vulnerabilities
387
417
  # Look for any privado json file
388
418
  if os.path.exists(privado_json_file):
@@ -421,17 +451,10 @@ async def cache():
421
451
  :return: a JSON response indicating the status of the caching operation.
422
452
  """
423
453
  db = db_lib.get()
424
- q = request.args
425
454
  if not db_lib.index_count(db["index_file"]):
426
- sources_list = [OSVSource(), NvdSource()]
427
- if os.environ.get("GITHUB_TOKEN"):
428
- sources_list.insert(0, GitHubSource())
429
- # Include aqua source when ?os=true query string is passed
430
- if q.get("os", "").lower() in ("true", "1"):
431
- sources_list.insert(0, AquaSource())
432
- for s in sources_list:
433
- LOG.debug("Refreshing %s", s.__class__.__name__)
434
- s.refresh()
455
+ oras_client = oras.client.OrasClient()
456
+ paths_list = oras_client.pull(target = vdb_database_url, outdir = data_dir)
457
+ LOG.debug(f'VDB data is stored at: {paths_list}')
435
458
  return {
436
459
  "error": "false",
437
460
  "message": "vulnerability database cached successfully",
@@ -573,7 +596,7 @@ def main():
573
596
  else:
574
597
  project_types_list = utils.detect_project_type(src_dir)
575
598
  db = db_lib.get()
576
- run_cacher = args.cache or args.cache_os
599
+ run_cacher = args.cache
577
600
  areport_file = (
578
601
  args.report_file
579
602
  if args.report_file
@@ -712,26 +735,15 @@ def main():
712
735
  run_cacher = True
713
736
  else:
714
737
  LOG.debug("Vulnerability database loaded from %s", config.vdb_bin_file)
738
+
715
739
  sources_list = [OSVSource(), NvdSource()]
716
740
  if os.environ.get("GITHUB_TOKEN"):
717
741
  sources_list.insert(0, GitHubSource())
718
742
  if run_cacher:
719
- if (
720
- args.cache_os
721
- or args.deep_scan
722
- or project_type in ("docker", "podman", "yaml-manifest", "os")
723
- ):
724
- sources_list.insert(0, AquaSource())
725
- LOG.info(
726
- "OS Vulnerability database would be downloaded for the "
727
- "first time. To avoid this step, manually download the "
728
- "vulnerability database using the ORAS cli and set the "
729
- "environment variable VDB_HOME."
730
- )
731
- for s in sources_list:
732
- LOG.debug("Refreshing %s", s.__class__.__name__)
733
- s.refresh()
734
- run_cacher = False
743
+ oras_client = oras.client.OrasClient()
744
+ paths_list = oras_client.pull(target = vdb_database_url, outdir = data_dir)
745
+ LOG.debug(f'VDB data is stored at: {paths_list}')
746
+ run_cacher = False
735
747
  elif args.sync:
736
748
  for s in sources_list:
737
749
  LOG.debug("Syncing %s", s.__class__.__name__)
depscan/lib/bom.py CHANGED
@@ -245,6 +245,69 @@ def resource_path(relative_path):
245
245
  return os.path.join(base_path, relative_path)
246
246
 
247
247
 
248
+ def exec_cdxgen(bin=True):
249
+ if bin:
250
+ cdxgen_cmd = os.environ.get("CDXGEN_CMD", "cdxgen")
251
+ if not shutil.which(cdxgen_cmd):
252
+ local_bin = resource_path(
253
+ os.path.join(
254
+ "local_bin",
255
+ "cdxgen.exe" if sys.platform == "win32" else "cdxgen",
256
+ )
257
+ )
258
+ if not os.path.exists(local_bin):
259
+ LOG.warning(
260
+ "%s command not found. Please install using npm install "
261
+ "@cyclonedx/cdxgen or set PATH variable",
262
+ cdxgen_cmd,
263
+ )
264
+ return False
265
+ try:
266
+ cdxgen_cmd = local_bin
267
+ # Set the plugins directory as an environment variable
268
+ os.environ["CDXGEN_PLUGINS_DIR"] = resource_path("local_bin")
269
+ return cdxgen_cmd
270
+ except Exception:
271
+ return None
272
+
273
+ else:
274
+ # cdxgen_cmd = (
275
+ # os.environ.get("CDXGEN_CMD", "cdxgen")
276
+ # if sys.platform != "win32"
277
+ # else os.environ.get("CDXGEN_CMD", "cdxgen.CMD")
278
+ # )
279
+ lbin = os.getenv("APPDATA") if sys.platform == "win32" else "local_bin"
280
+ local_bin = resource_path(
281
+ os.path.join(
282
+ f"{lbin}\\npm\\" if sys.platform == "win32" else "local_bin",
283
+ "cdxgen" if sys.platform != "win32" else "cdxgen.cmd",
284
+ )
285
+ )
286
+ if not os.path.exists(local_bin):
287
+ LOG.warning(
288
+ "%s command not found. Please install using npm install "
289
+ "@cyclonedx/cdxgen or set PATH variable",
290
+ local_bin,
291
+ )
292
+ return None
293
+ try:
294
+ cdxgen_cmd = local_bin
295
+ # Set the plugins directory as an environment variable
296
+ os.environ["CDXGEN_PLUGINS_DIR"] = (
297
+ resource_path("local_bin")
298
+ if sys.platform != "win32"
299
+ else resource_path(
300
+ os.path.join(
301
+ lbin,
302
+ "\\npm\\node_modules\\@cyclonedx\\cdxgen\\node_modules\\@cyclonedx\\cdxgen-plugins-bin\\plugins",
303
+ )
304
+ )
305
+ )
306
+ return cdxgen_cmd
307
+ except Exception:
308
+ return None
309
+
310
+
248
311
  def create_bom(project_type, bom_file, src_dir=".", deep=False, options={}):
249
312
  """
250
313
  Method to create BOM file by executing cdxgen command
@@ -303,27 +366,9 @@ def create_bom(project_type, bom_file, src_dir=".", deep=False, options={}):
303
366
  "Unable to generate SBoM with cdxgen server. Trying to "
304
367
  "generate one locally."
305
368
  )
306
- cdxgen_cmd = os.environ.get("CDXGEN_CMD", "cdxgen")
307
- if not shutil.which(cdxgen_cmd):
308
- local_bin = resource_path(
309
- os.path.join(
310
- "local_bin",
311
- "cdxgen.exe" if sys.platform == "win32" else "cdxgen",
312
- )
313
- )
314
- if not os.path.exists(local_bin):
315
- LOG.warning(
316
- "%s command not found. Please install using npm install "
317
- "@cyclonedx/cdxgen or set PATH variable",
318
- cdxgen_cmd,
319
- )
320
- return False
321
- try:
322
- cdxgen_cmd = local_bin
323
- # Set the plugins directory as an environment variable
324
- os.environ["CDXGEN_PLUGINS_DIR"] = resource_path("local_bin")
325
- except Exception:
326
- pass
369
+ cdxgen_cmd = exec_cdxgen()
370
+ if not cdxgen_cmd:
371
+ cdxgen_cmd = exec_cdxgen(False)
327
372
  if project_type in ("docker",):
328
373
  LOG.info(
329
374
  "Generating Software Bill-of-Materials for container image %s. "
@@ -335,7 +380,10 @@ def create_bom(project_type, bom_file, src_dir=".", deep=False, options={}):
335
380
  args.append("--deep")
336
381
  LOG.info("About to perform deep scan. This would take a while ...")
337
382
  args.append(src_dir)
338
- exec_tool(args)
383
+ if cdxgen_cmd:
384
+ exec_tool(args)
385
+ else:
386
+ LOG.warning("Unable to locate cdxgen command. ")
339
387
  return os.path.exists(bom_file)
340
388
 
341
389
 
depscan/lib/config.py CHANGED
@@ -296,6 +296,8 @@ npm_app_info = {"name": "appthreat-depscan", "version": "1.0.0"}
296
296
 
297
297
  pypi_server = "https://pypi.org/pypi"
298
298
 
299
+ vdb_database_url = "ghcr.io/appthreat/vdb:v5"
300
+
299
301
  # Package risk scoring using a simple weighted formula with no backing
300
302
  # research All parameters and their max value and weight can be overridden
301
303
  # using environment variables
depscan/lib/normalize.py CHANGED
@@ -245,7 +245,7 @@ def dedup(project_type, pkg_list):
245
245
  version = None
246
246
  if res.matched_by:
247
247
  version = res.matched_by.split("|")[-1]
248
- full_pkg = vid + ":" + package_issue.affected_location.package
248
+ full_pkg = package_issue.affected_location.package
249
249
  if package_issue.affected_location.vendor:
250
250
  full_pkg = (
251
251
  f"{package_issue.affected_location.vendor}:"
@@ -253,6 +253,7 @@ def dedup(project_type, pkg_list):
253
253
  )
254
254
  if version:
255
255
  full_pkg = full_pkg + ":" + version
256
+ full_pkg = vid + ":" + full_pkg
256
257
  # Ignore any result with the exclude fix location
257
258
  # Required for debian
258
259
  if fixed_location == placeholder_exclude_version:
depscan/lib/utils.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import ast
2
2
  import os
3
+ import pkg_resources
3
4
  import re
4
5
  from collections import defaultdict
5
6
 
@@ -366,3 +367,10 @@ def get_all_imports(src_dir):
366
367
  import_list.add(pkg)
367
368
  import_list.add(pkg.lower().replace("py", ""))
368
369
  return import_list
370
+
371
+
372
+ def get_version():
373
+ """
374
+ Returns the version of depscan
375
+ """
376
+ return pkg_resources.get_distribution("owasp-depscan").version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: owasp-depscan
3
- Version: 4.2.5
3
+ Version: 4.2.7
4
4
  Summary: Fully open-source security audit for project dependencies based on known vulnerabilities and advisories.
5
5
  Author-email: Team AppThreat <cloud@appthreat.com>
6
6
  License: MIT
@@ -19,8 +19,9 @@ Classifier: Topic :: Utilities
19
19
  Requires-Python: >=3.8
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
- Requires-Dist: appthreat-vulnerability-db >=5.4.1
22
+ Requires-Dist: appthreat-vulnerability-db >=5.4.2
23
23
  Requires-Dist: defusedxml
24
+ Requires-Dist: oras
24
25
  Requires-Dist: PyYAML
25
26
  Requires-Dist: rich
26
27
  Requires-Dist: quart
@@ -55,7 +56,7 @@ OWASP dep-scan is a fully open-source security audit tool based on known vulnera
55
56
  - NVD
56
57
  - GitHub
57
58
  - NPM
58
- - Linux [vuln-list](https://github.com/appthreat/vuln-list) (Use `--cache-os`)
59
+ - Linux [vuln-list](https://github.com/appthreat/vuln-list)
59
60
 
60
61
  ### Linux distros
61
62
 
@@ -72,7 +73,7 @@ OWASP dep-scan is a fully open-source security audit tool based on known vulnera
72
73
  - Chainguard
73
74
  - Wolfi OS
74
75
 
75
- Application vulnerabilities would be reported for all Linux distros and Windows. To download the full vulnerability database suitable for scanning OS, invoke dep-scan with `--cache-os` for the first time. dep-scan would also download the appropriate database based on project type automatically.
76
+ Application vulnerabilities would be reported for all Linux distros and Windows. To download the full vulnerability database suitable for scanning OS, invoke dep-scan with `--cache` for the first time. dep-scan would also download the appropriate database based on project type automatically.
76
77
 
77
78
  ## Usage
78
79
 
@@ -86,7 +87,7 @@ Use [ORAS cli](https://oras.land/cli/) to download the dep-scan binary and the v
86
87
  export VDB_HOME=depscan
87
88
  mkdir -p $VDB_HOME
88
89
  oras pull ghcr.io/appthreat/vdb:v5 -o $VDB_HOME
89
- oras pull ghcr.io/appthreat/depscan:v4 -o $VDB_HOME
90
+ oras pull ghcr.io/owasp-dep-scan/depscan:v4 -o $VDB_HOME
90
91
  ```
91
92
 
92
93
  ### Single binary executables
@@ -130,13 +131,6 @@ In server mode, use `/cache` endpoint to cache the vulnerability database.
130
131
  curl http://0.0.0.0:7070/cache
131
132
  ```
132
133
 
133
- Cache all vulnerabilities including os.
134
-
135
- ```bash
136
- # This would take over 5 minutes
137
- curl http://0.0.0.0:7070/cache?os=true
138
- ```
139
-
140
134
  Use the `/scan` endpoint to perform scans.
141
135
 
142
136
  ```bash
@@ -177,12 +171,11 @@ depscan --src $PWD --reports-dir $PWD/reports
177
171
  Full list of options are below:
178
172
 
179
173
  ```bash
180
- usage: depscan [-h] [--no-banner] [--cache] [--cache-os] [--sync] [--suggest] [--risk-audit] [--private-ns PRIVATE_NS] [-t PROJECT_TYPE] [--bom BOM] -i SRC_DIR
174
+ usage: depscan [-h] [--no-banner] [--cache] [--sync] [--suggest] [--risk-audit] [--private-ns PRIVATE_NS] [-t PROJECT_TYPE] [--bom BOM] -i SRC_DIR
181
175
  [--reports-dir REPORTS_DIR] [--no-error] [--deep]
182
176
  -h, --help show this help message and exit
183
177
  --no-banner Do not display banner
184
178
  --cache Cache vulnerability information in platform specific user_data_dir
185
- --cache-os Cache OS vulnerability information in platform specific user_data_dir
186
179
  --sync Sync to receive the latest vulnerability data. Should have invoked cache first.
187
180
  --risk-audit Perform package risk audit (slow operation). Npm only.
188
181
  --private-ns PRIVATE_NS
@@ -1,16 +1,16 @@
1
1
  depscan/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- depscan/cli.py,sha256=cAvoT_i7qOCNPCmgojH3Z6WRNE3eQJsiPzcOM9fIGVg,28285
2
+ depscan/cli.py,sha256=5z6u8A7c4hidnwYIvjccxBxxwayWrluPSfaL7FMcrPU,28878
3
3
  depscan/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  depscan/lib/analysis.py,sha256=TIK0TuyxOng7VbDdweTndyouwMHDoTo-JjjzxOTiCxk,42085
5
5
  depscan/lib/audit.py,sha256=rUkrlioaACfKXb7rLhJoSH4F3btpWLQ6OoSFwV0H62w,1246
6
- depscan/lib/bom.py,sha256=J-Pmmz-P1C3jbsf5CiKoHsWD3jS6ntqFcHBf2WcHM7s,14421
7
- depscan/lib/config.py,sha256=NJ-L_2IghlGnIHYVpT0K5hrO5JSeuhlBwOAs1slhprU,12515
6
+ depscan/lib/bom.py,sha256=lJUUkn_CzsG-w0dsTzTIP1tUL60jW48vpfD_G-rcDSA,16159
7
+ depscan/lib/config.py,sha256=9tyjo6uNdlJWyNNVfYD5tEt1wWexEyImMmuO8bK9Yns,12562
8
8
  depscan/lib/license.py,sha256=y4-WZuD2MOunKaLd2EJGcSYP6s3Lp_dgssdzhcl9eEM,2332
9
9
  depscan/lib/logger.py,sha256=PdGrJstLmvwpMnlYx1zZ12jxz4kmbGm5kTSRs_8UcK4,1529
10
- depscan/lib/normalize.py,sha256=oUjPwmlEFdeWQIsTIQC3ix7ArD1nYwNJXHBVJeJa4F8,9980
10
+ depscan/lib/normalize.py,sha256=k8OlhSjzhGieqK1BLJNABRuz2wcwO4J8Ce8lYUsaxik,10008
11
11
  depscan/lib/pkg_query.py,sha256=Hlf3LypsL7EF309HevcfhdjAOPDZbN1XRQOmjQpnxlI,20082
12
12
  depscan/lib/privado.py,sha256=a9VlWHjxo0ibYggEfvTHjEXXqCMqjH-YjRXolilLg0k,5313
13
- depscan/lib/utils.py,sha256=E2NbItX2tu1N1ARGER1RRDasZyHVayH6nwwrngkq9Lc,12128
13
+ depscan/lib/utils.py,sha256=r0Lwgu7A-8ycZzcyFN2DOIF5_iy9kDTNAAG2mw5FQew,12288
14
14
  vendor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  vendor/choosealicense.com/_data/fields.yml,sha256=ydNsITXFUuADzGPM-jcUcJnN0r_qSGgH51oV27nX3Qs,819
16
16
  vendor/choosealicense.com/_data/meta.yml,sha256=rSNmnx0LE6VA9wnR29Y_P9s-TnADQqbdw2enE4i1mWM,1792
@@ -61,9 +61,9 @@ vendor/choosealicense.com/_licenses/vim.txt,sha256=d5GQjXB328L8EBkhKgxcjk344D3K7
61
61
  vendor/choosealicense.com/_licenses/wtfpl.txt,sha256=BxXeubkvQm32MDmlZsBcbzJzBpR5kWgw0JxSR9d7f3k,948
62
62
  vendor/choosealicense.com/_licenses/zlib.txt,sha256=e6dfCeLhxD3NCnIkY4cVIagRaWdRvencjNhHZ1APvpc,1678
63
63
  vendor/spdx/json/licenses.json,sha256=PU1SD-zBi-U4r1XIWJ9qU-KixVWsQ5TJePUejC79yzU,251610
64
- owasp_depscan-4.2.5.dist-info/LICENSE,sha256=oQnCbnZtJ_NLDdOLc-rVY1D1N0RNWLHPpYXcc77xzSo,1073
65
- owasp_depscan-4.2.5.dist-info/METADATA,sha256=HtFh-hhuA_tQCuchKjfAYnvuwxT5MVnesZTNOV5UPKw,21220
66
- owasp_depscan-4.2.5.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
67
- owasp_depscan-4.2.5.dist-info/entry_points.txt,sha256=FxQKHFWZTfKU2eBxHPFRxwhSNexntYygYhquykS8zxA,69
68
- owasp_depscan-4.2.5.dist-info/top_level.txt,sha256=qbHOZvNU2dXANv946hMdP2vOi0ESQB5t2ZY5ktKtXvQ,15
69
- owasp_depscan-4.2.5.dist-info/RECORD,,
64
+ owasp_depscan-4.2.7.dist-info/LICENSE,sha256=oQnCbnZtJ_NLDdOLc-rVY1D1N0RNWLHPpYXcc77xzSo,1073
65
+ owasp_depscan-4.2.7.dist-info/METADATA,sha256=YozihooRaKZpWXOzI0AtSi-GiWlyePzJM_43hdqi5D4,20990
66
+ owasp_depscan-4.2.7.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
67
+ owasp_depscan-4.2.7.dist-info/entry_points.txt,sha256=FxQKHFWZTfKU2eBxHPFRxwhSNexntYygYhquykS8zxA,69
68
+ owasp_depscan-4.2.7.dist-info/top_level.txt,sha256=qbHOZvNU2dXANv946hMdP2vOi0ESQB5t2ZY5ktKtXvQ,15
69
+ owasp_depscan-4.2.7.dist-info/RECORD,,