fosslight-binary 5.1.8__tar.gz → 5.1.9__tar.gz

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.
Files changed (26) hide show
  1. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/PKG-INFO +1 -1
  2. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/setup.py +1 -1
  3. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/_binary.py +18 -5
  4. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/_jar_analysis.py +40 -29
  5. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/binary_analysis.py +10 -3
  6. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary.egg-info/PKG-INFO +1 -1
  7. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/LICENSE +0 -0
  8. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/LICENSES/Apache-2.0.txt +0 -0
  9. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/LICENSES/LicenseRef-3rd_party_licenses.txt +0 -0
  10. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/MANIFEST.in +0 -0
  11. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/README.md +0 -0
  12. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/requirements.txt +0 -0
  13. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/setup.cfg +0 -0
  14. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/LICENSES/LICENSE +0 -0
  15. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/LICENSES/LicenseRef-3rd_party_licenses.txt +0 -0
  16. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/__init__.py +0 -0
  17. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/_binary_dao.py +0 -0
  18. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/_help.py +0 -0
  19. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/_simple_mode.py +0 -0
  20. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary/cli.py +0 -0
  21. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary.egg-info/SOURCES.txt +0 -0
  22. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary.egg-info/dependency_links.txt +0 -0
  23. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary.egg-info/entry_points.txt +0 -0
  24. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary.egg-info/requires.txt +0 -0
  25. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/src/fosslight_binary.egg-info/top_level.txt +0 -0
  26. {fosslight_binary-5.1.8 → fosslight_binary-5.1.9}/tests/test_fosslight_binary.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_binary
3
- Version: 5.1.8
3
+ Version: 5.1.9
4
4
  Summary: FOSSLight Binary Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_binary_scanner
6
6
  Download-URL: https://github.com/fosslight/fosslight_binary_scanner
@@ -33,7 +33,7 @@ if __name__ == "__main__":
33
33
 
34
34
  setup(
35
35
  name=_PACKAEG_NAME,
36
- version='5.1.8',
36
+ version='5.1.9',
37
37
  package_dir={"": "src"},
38
38
  packages=find_packages(where='src'),
39
39
  description='FOSSLight Binary Scanner',
@@ -2,14 +2,18 @@
2
2
  # -*- coding: utf-8 -*-
3
3
  # Copyright (c) 2020 LG Electronics Inc.
4
4
  # SPDX-License-Identifier: Apache-2.0
5
- from fosslight_util.oss_item import FileItem
5
+ import os
6
6
  import urllib.parse
7
7
  import logging
8
8
  import fosslight_util.constant as constant
9
+ from typing import Tuple
10
+ from fosslight_util.oss_item import FileItem
9
11
 
10
12
  EXCLUDE_TRUE_VALUE = "Exclude"
11
13
  TLSH_CHECKSUM_NULL = "0"
12
14
  MAX_EXCEL_URL_LENGTH = 255
15
+ EXCEEDED_VUL_URL_LENGTH_COMMENT = f"Exceeded the maximum vulnerability URL length of {MAX_EXCEL_URL_LENGTH} characters."
16
+ _PACKAGE_DIR = ["node_modules", "venv", "Pods", "Carthage"]
13
17
 
14
18
  logger = logging.getLogger(constant.LOGGER_NAME)
15
19
 
@@ -54,12 +58,9 @@ class BinaryItem(FileItem):
54
58
  nvd_url = ", ".join(nvd_url).strip()
55
59
 
56
60
  if nvd_url and len(nvd_url) > MAX_EXCEL_URL_LENGTH:
57
- oss.comment = f"Exceeded the maximum vulnerability URL length of {MAX_EXCEL_URL_LENGTH} characters."
61
+ oss.comment = EXCEEDED_VUL_URL_LENGTH_COMMENT
58
62
  return nvd_url
59
63
 
60
- def get_print_binary_only(self):
61
- return (self.source_name_or_path + "\t" + self.checksum + "\t" + self.tlsh)
62
-
63
64
  def get_print_array(self):
64
65
  items = []
65
66
  if self.oss_items:
@@ -110,3 +111,15 @@ class BinaryItem(FileItem):
110
111
  if self.comment:
111
112
  json_item["comment"] = self.comment
112
113
  return items
114
+
115
+
116
+ def is_package_dir(bin_with_path: str, _root_path: str) -> Tuple[bool, str]:
117
+ is_pkg = False
118
+ pkg_path = ""
119
+ path_parts = bin_with_path.split(os.path.sep)
120
+ for pkg_dir in _PACKAGE_DIR:
121
+ if pkg_dir in path_parts:
122
+ pkg_index = path_parts.index(pkg_dir)
123
+ pkg_path = os.path.sep.join(path_parts[:pkg_index + 1]).replace(_root_path, '', 1)
124
+ is_pkg = True
125
+ return is_pkg, pkg_path
@@ -8,7 +8,7 @@ import json
8
8
  import os
9
9
  import sys
10
10
  import fosslight_util.constant as constant
11
- from ._binary import BinaryItem, VulnerabilityItem
11
+ from ._binary import BinaryItem, VulnerabilityItem, is_package_dir
12
12
  from fosslight_util.oss_item import OssItem
13
13
  from dependency_check import run as dependency_check_run
14
14
 
@@ -57,29 +57,42 @@ def get_oss_lic_in_jar(data):
57
57
  return license
58
58
 
59
59
 
60
+ def merge_oss_and_vul_items(bin, key, oss_list, vulnerability_items):
61
+ bin.set_oss_items(oss_list)
62
+ if vulnerability_items and vulnerability_items.get(key):
63
+ bin.vulnerability_items.extend(vulnerability_items.get(key, []))
64
+
65
+
60
66
  def merge_binary_list(owasp_items, vulnerability_items, bin_list):
61
67
  not_found_bin = []
62
68
 
63
- # key : file_path / value : oss_list for one binary
69
+ # key : file_path / value : {"oss_list": [oss], "sha1": sha1} for one binary
64
70
  for key, value in owasp_items.items():
65
71
  found = False
72
+ oss_list = value["oss_list"]
73
+ sha1 = value.get("sha1", "")
66
74
  for bin in bin_list:
67
75
  if bin.source_name_or_path == key:
68
- for oss in value:
76
+ found = True
77
+ for oss in oss_list:
69
78
  if oss.name and oss.license:
70
79
  bin.found_in_owasp = True
71
80
  break
72
- bin.set_oss_items(value)
73
- if vulnerability_items and vulnerability_items.get(key):
74
- bin.vulnerability_items.extend(vulnerability_items.get(key))
75
- found = True
76
- break
81
+ merge_oss_and_vul_items(bin, key, oss_list, vulnerability_items)
82
+ else:
83
+ if bin.checksum == sha1:
84
+ merge_oss_and_vul_items(bin, key, oss_list, vulnerability_items)
77
85
 
78
86
  if not found:
79
87
  bin_item = BinaryItem(os.path.abspath(key))
80
88
  bin_item.binary_name_without_path = os.path.basename(key)
81
89
  bin_item.source_name_or_path = key
82
- bin_item.set_oss_items(value)
90
+
91
+ is_pkg, _ = is_package_dir(bin_item.source_name_or_path, '')
92
+ if is_pkg:
93
+ continue
94
+
95
+ bin_item.set_oss_items(oss_list)
83
96
  not_found_bin.append(bin_item)
84
97
 
85
98
  bin_list += not_found_bin
@@ -192,7 +205,8 @@ def analyze_jar_file(path_to_find_bin, path_to_exclude):
192
205
  success = False
193
206
  return owasp_items, vulnerability_items, success
194
207
 
195
- dependencies = jar_contents.get("dependencies")
208
+ dependencies = jar_contents.get("dependencies", [])
209
+
196
210
  try:
197
211
  for val in dependencies:
198
212
  bin_with_path = ""
@@ -204,6 +218,8 @@ def analyze_jar_file(path_to_find_bin, path_to_exclude):
204
218
  oss_license = get_oss_lic_in_jar(val)
205
219
  oss_name_found = False
206
220
 
221
+ sha1 = val.get("sha1", "")
222
+
207
223
  all_evidence = val.get("evidenceCollected", {})
208
224
  vulnerability = val.get("vulnerabilityIds", [])
209
225
  all_pkg_info = val.get("packages", [])
@@ -259,31 +275,26 @@ def analyze_jar_file(path_to_find_bin, path_to_exclude):
259
275
  # Get Vulnerability Info.
260
276
  vulnerability_items = get_vulnerability_info(file_with_path, vulnerability, vulnerability_items, remove_vulnerability_items)
261
277
 
262
- if oss_name != "" or oss_ver != "" or oss_license != "" or oss_dl_url != "":
263
- oss_list_for_file = owasp_items.get(file_with_path, [])
264
-
265
- existing_oss = None
266
- for item in oss_list_for_file:
267
- if item.name == oss_name and item.version == oss_ver:
268
- existing_oss = item
269
- break
270
-
271
- if not existing_oss:
272
- oss = OssItem(oss_name, oss_ver, oss_license, oss_dl_url)
273
- oss.comment = "OWASP result"
278
+ if oss_name or oss_license or oss_dl_url:
279
+ oss = OssItem(oss_name, oss_ver, oss_license, oss_dl_url)
280
+ oss.comment = "OWASP result"
274
281
 
275
- if file_with_path in owasp_items:
276
- owasp_items[file_with_path].append(oss)
277
- else:
278
- owasp_items[file_with_path] = [oss]
282
+ if file_with_path in owasp_items:
283
+ owasp_items[file_with_path]["oss_list"].append(oss)
284
+ # Update sha1 if not already set or if current sha1 is empty
285
+ if not owasp_items[file_with_path]["sha1"] and sha1:
286
+ owasp_items[file_with_path]["sha1"] = sha1
287
+ else:
288
+ owasp_items[file_with_path] = {
289
+ "oss_list": [oss],
290
+ "sha1": sha1
291
+ }
279
292
  except Exception as ex:
280
- logger.debug(f"Error to get depency Info in jar_contets: {ex}")
281
- success = False
293
+ logger.debug(f"Error to get dependency Info in jar_contents: {ex}")
282
294
 
283
295
  try:
284
296
  if os.path.isfile(json_file):
285
297
  os.remove(json_file)
286
298
  except Exception as ex:
287
299
  logger.debug(f"Error - There is no .json file : {ex}")
288
-
289
300
  return owasp_items, vulnerability_items, success
@@ -16,7 +16,7 @@ from fosslight_util.set_log import init_log
16
16
  import fosslight_util.constant as constant
17
17
  from fosslight_util.output_format import check_output_formats_v2, write_output_file
18
18
  from ._binary_dao import get_oss_info_from_db
19
- from ._binary import BinaryItem, TLSH_CHECKSUM_NULL
19
+ from ._binary import BinaryItem, TLSH_CHECKSUM_NULL, is_package_dir
20
20
  from ._jar_analysis import analyze_jar_file, merge_binary_list
21
21
  from ._simple_mode import print_simple_mode, filter_binary, init_simple
22
22
  from fosslight_util.correct import correct_with_yaml
@@ -165,8 +165,15 @@ def get_file_list(path_to_find, abs_path_to_exclude):
165
165
  bin_with_path = os.path.join(root, file)
166
166
  bin_item = BinaryItem(bin_with_path)
167
167
  bin_item.binary_name_without_path = file
168
- bin_item.source_name_or_path = bin_with_path.replace(
169
- _root_path, '', 1)
168
+ bin_item.source_name_or_path = bin_with_path.replace(_root_path, '', 1)
169
+
170
+ is_pkg, pkg_path = is_package_dir(bin_with_path, _root_path)
171
+ if is_pkg:
172
+ bin_item.source_name_or_path = pkg_path
173
+ if not any(x.source_name_or_path == bin_item.source_name_or_path for x in bin_list):
174
+ bin_item.exclude = True
175
+ bin_list.append(bin_item)
176
+ continue
170
177
 
171
178
  if any(dir_name in dir_path for dir_name in _EXCLUDE_DIR):
172
179
  bin_item.exclude = True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fosslight_binary
3
- Version: 5.1.8
3
+ Version: 5.1.9
4
4
  Summary: FOSSLight Binary Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_binary_scanner
6
6
  Download-URL: https://github.com/fosslight/fosslight_binary_scanner