socketdev 3.6.3__py3-none-any.whl → 3.6.4__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.
socketdev/core/dedupe.py CHANGED
@@ -2,12 +2,45 @@ from collections import defaultdict
2
2
  from typing import Dict, List, Any
3
3
  from socketdev.log import log
4
4
 
5
+ # Props that name the advisory behind a vulnerability alert. Every advisory of
6
+ # one severity on a package shares an alert type (``criticalCVE``, ``cve`` and
7
+ # so on), so these are what tell two of them apart.
8
+ #
9
+ # Socket's CVE alerts carry ``ghsaId`` and ``cveId``. The other names are in no
10
+ # current alert schema; they mirror ``Issue.advisory_id()`` in socket-python-cli
11
+ # (socketsecurity/core/classes.py), which reads alerts from this SDK. Keep the
12
+ # two lists in step.
13
+ ADVISORY_ID_PROPS = ("ghsaId", "ghsa_id", "cveId", "cve_id", "cve")
14
+
15
+ # Policy actions from least to most severe. An unknown or missing action ranks
16
+ # below "ignore", so it never replaces a known action and the merged result
17
+ # doesn't depend on which release is listed first.
18
+ ACTION_RANK = {"ignore": 0, "monitor": 1, "warn": 2, "error": 3}
19
+
5
20
 
6
21
  class Dedupe:
7
22
  @staticmethod
8
23
  def normalize_file_path(path: str) -> str:
9
24
  return path.split("/", 1)[-1] if path and "/" in path else path or ""
10
25
 
26
+ @staticmethod
27
+ def advisory_id(alert: dict) -> str:
28
+ """The alert's GHSA or CVE identifier, upper-cased, or "" if it has none."""
29
+ props = alert.get("props")
30
+ if not isinstance(props, dict):
31
+ return ""
32
+ for prop_name in ADVISORY_ID_PROPS:
33
+ value = props.get(prop_name)
34
+ if isinstance(value, (list, tuple)):
35
+ value = next((v for v in value if isinstance(v, str) and v.strip()), "")
36
+ if isinstance(value, str) and value.strip():
37
+ return value.strip().upper()
38
+ return ""
39
+
40
+ @staticmethod
41
+ def action_rank(action: Any) -> int:
42
+ return ACTION_RANK.get(action, -1) if isinstance(action, str) else -1
43
+
11
44
  @staticmethod
12
45
  def alert_key(alert: dict) -> tuple:
13
46
  return (
@@ -16,21 +49,12 @@ class Dedupe:
16
49
  alert.get("category"),
17
50
  Dedupe.normalize_file_path(alert.get("file")),
18
51
  alert.get("start"),
19
- alert.get("end")
52
+ alert.get("end"),
53
+ Dedupe.advisory_id(alert),
20
54
  )
21
55
 
22
56
  @staticmethod
23
57
  def consolidate_and_merge_alerts(package_group: List[Dict[str, Any]]) -> Dict[str, Any]:
24
- def alert_identity(alert: dict) -> tuple:
25
- return (
26
- alert.get("type"),
27
- alert.get("severity"),
28
- alert.get("category"),
29
- Dedupe.normalize_file_path(alert.get("file")),
30
- alert.get("start"),
31
- alert.get("end")
32
- )
33
-
34
58
  alert_map: Dict[tuple, dict] = {}
35
59
  releases = set()
36
60
  for pkg in package_group:
@@ -38,7 +62,7 @@ class Dedupe:
38
62
  releases.add(release)
39
63
 
40
64
  for alert in pkg.get("alerts", []):
41
- identity = alert_identity(alert)
65
+ identity = Dedupe.alert_key(alert)
42
66
 
43
67
  if identity not in alert_map:
44
68
  # Build alert dict with only fields that exist in the original alert.
@@ -66,8 +90,15 @@ class Dedupe:
66
90
 
67
91
  alert_map[identity] = consolidated_alert
68
92
  else:
69
- if release not in alert_map[identity]["releases"]:
70
- alert_map[identity]["releases"].append(release)
93
+ merged = alert_map[identity]
94
+ if release not in merged["releases"]:
95
+ merged["releases"].append(release)
96
+ # Keep the most severe action seen, so a release that blocks
97
+ # is never hidden behind one that doesn't. Only the action
98
+ # moves: key and props stay with the first sighting, so the
99
+ # key can belong to a release with a less severe action.
100
+ if Dedupe.action_rank(alert.get("action")) > Dedupe.action_rank(merged.get("action")):
101
+ merged["action"] = alert.get("action")
71
102
 
72
103
  base = package_group[0]
73
104
  base["releases"] = sorted(releases)
socketdev/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "3.6.3"
1
+ __version__ = "3.6.4"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: socketdev
3
- Version: 3.6.3
3
+ Version: 3.6.4
4
4
  Summary: Socket Security Python SDK
5
5
  Project-URL: Homepage, https://github.com/SocketDev/socket-sdk-python
6
6
  Author-email: Douglas Coburn <douglas@socket.dev>
@@ -1,7 +1,7 @@
1
1
  socketdev/__init__.py,sha256=4S3ApgU21s_1Wd4bEfife4ifAzmrdzLMS2gvft1a6Vo,4224
2
2
  socketdev/exceptions.py,sha256=yr1O1wkJUi-pvXQuqdAj4phNggHmT2N57I6DOdGdsgI,4225
3
3
  socketdev/log.py,sha256=AgEcsPN3y9U-fze8pTFvLigVvNob2vmNC-TkOOQkkeQ,90
4
- socketdev/version.py,sha256=Y-FgC1VqJrp0YmwoM9m0nqI9YiRGdYqtfNFOz9j36SQ,22
4
+ socketdev/version.py,sha256=q3gcnRqnpustX32RHZbHBlkyA1XrYBRYxZEAyTtm4y4,22
5
5
  socketdev/alertfullscansearch/__init__.py,sha256=YwXrgnrI9z9rAexXFFmoXQcaQdGW47HRhQ58CQBCG3U,884
6
6
  socketdev/alerts/__init__.py,sha256=kGLCNXtXTRz3vl2s_bPQ7xuds_QGwNQnah1TfHzp2MU,846
7
7
  socketdev/alerttypes/__init__.py,sha256=W-m2D9VxbepSAUELJPmWmX40zksGZbQcSzwQ1kjlB1k,1169
@@ -11,7 +11,7 @@ socketdev/auditlog/__init__.py,sha256=vjcVtOK6oujqC6-RW5Hrvmth5BqFkLdinbeyqtycOp
11
11
  socketdev/basics/__init__.py,sha256=9jTEwC4dMUV-9pKpU4twK-hM1cY0xeXAxjDrb37sxoQ,4067
12
12
  socketdev/core/api.py,sha256=JROfXLRZ4IZApCpKw5MJFX21NIAdeBwIzU5oWxAC-3g,6622
13
13
  socketdev/core/classes.py,sha256=jY1oyokpSVDA2XckG1pdVOP5PtxDS8CWta8PX6eZFJc,3608
14
- socketdev/core/dedupe.py,sha256=Fy_HGU77jxt7Dz8TF7AYkEklwtu_xFA40ripaYyBkqs,5774
14
+ socketdev/core/dedupe.py,sha256=16O_njjnO5D3KXtuubrO5CyleZVOt-W__Z-EQsj23wY,7532
15
15
  socketdev/core/enums.py,sha256=daY3vdm4veuYKCWenFOIsGsga85xzkiLfcygb5F1LSk,1416
16
16
  socketdev/core/issues.py,sha256=SKhJz7SrglozeuEk72CbbuCM7X0hgzNMk55uM4wX-TI,68081
17
17
  socketdev/core/retired_token.py,sha256=uwPS_1p1e3JzC8yPD3bBVPhhLsqWsTbChorHEdapLMo,1126
@@ -42,7 +42,7 @@ socketdev/triage/__init__.py,sha256=-h599vThVetfRSOAs1e4IUoMjcXS8xOsUfub41XPiX4,
42
42
  socketdev/uploadmanifests/__init__.py,sha256=-sFHbOW-aw7U0wRfEJT_Edrzx8aCbzD9cTGmVTNJKpw,6043
43
43
  socketdev/utils/__init__.py,sha256=E11UJTsWsN-ZurOwtKvPGOTc9UMP3ND79nPbmNRRQ6E,17666
44
44
  socketdev/webhooks/__init__.py,sha256=fme6K7ma_Gvk_TFOLz9jVcR5QJbDpMHXqRaU3x_RShY,3507
45
- socketdev-3.6.3.dist-info/METADATA,sha256=nF3B_mgWWHkrJTCz03BrCjodkkIXDD68aHN2eCki0BU,61607
46
- socketdev-3.6.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
47
- socketdev-3.6.3.dist-info/licenses/LICENSE,sha256=mC0II_UuE-_gCG9XqOLNyrV3crnROzMpdAetGnMrhpw,1068
48
- socketdev-3.6.3.dist-info/RECORD,,
45
+ socketdev-3.6.4.dist-info/METADATA,sha256=kAoRiPBM2yp9JfvjpdAJ2plxHX-twf1QTEUwPfVQ6ww,61607
46
+ socketdev-3.6.4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
47
+ socketdev-3.6.4.dist-info/licenses/LICENSE,sha256=mC0II_UuE-_gCG9XqOLNyrV3crnROzMpdAetGnMrhpw,1068
48
+ socketdev-3.6.4.dist-info/RECORD,,