|
17 | 17 | from pathlib import Path |
18 | 18 | from typing import Any |
19 | 19 |
|
20 | | -from coretrace_python.dependency.graph import Advisory, AdvisoryEntryPoint, Condition, normalize |
| 20 | +from coretrace_python.dependency.graph import ( |
| 21 | + Advisory, |
| 22 | + AdvisoryEntryPoint, |
| 23 | + AttackerArgument, |
| 24 | + Condition, |
| 25 | + normalize, |
| 26 | +) |
21 | 27 | from coretrace_python.findings import Severity |
22 | 28 | from coretrace_python.semantic.symbols import SymbolId |
23 | 29 |
|
@@ -155,6 +161,19 @@ def _entry_point_entry(entry_point: AdvisoryEntryPoint) -> dict[str, Any]: |
155 | 161 | } |
156 | 162 | if entry_point.read: |
157 | 163 | entry["read"] = True |
| 164 | + if entry_point.attacker_arguments: |
| 165 | + entry["attacker_arguments"] = [_attacker_argument_entry(a) for a in entry_point.attacker_arguments] |
| 166 | + return entry |
| 167 | + |
| 168 | + |
| 169 | +def _attacker_argument_entry(argument: AttackerArgument) -> dict[str, Any]: |
| 170 | + entry: dict[str, Any] = {} |
| 171 | + if argument.argument is not None: |
| 172 | + entry["argument"] = argument.argument |
| 173 | + if argument.position is not None: |
| 174 | + entry["position"] = argument.position |
| 175 | + if argument.variadic: |
| 176 | + entry["variadic"] = True |
158 | 177 | return entry |
159 | 178 |
|
160 | 179 |
|
@@ -206,9 +225,25 @@ def _entry_point(entry: Mapping[str, Any]) -> AdvisoryEntryPoint: |
206 | 225 | str(entry["justification"]), |
207 | 226 | tuple(_condition(c) for c in entry.get("conditions") or []), |
208 | 227 | read, |
| 228 | + tuple(_attacker_argument(a) for a in entry.get("attacker_arguments") or []), |
209 | 229 | ) |
210 | 230 |
|
211 | 231 |
|
| 232 | +def _attacker_argument(entry: Mapping[str, Any]) -> AttackerArgument: |
| 233 | + argument, position, variadic = entry.get("argument"), entry.get("position"), entry.get("variadic", False) |
| 234 | + if argument is not None and not isinstance(argument, str): |
| 235 | + raise TypeError(f"attacker argument name must be a string, got {argument!r}") |
| 236 | + if position is not None and (not isinstance(position, int) or isinstance(position, bool) or position < 0): |
| 237 | + raise TypeError(f"attacker argument position must be a non-negative integer, got {position!r}") |
| 238 | + if not isinstance(variadic, bool): |
| 239 | + raise TypeError(f"attacker argument variadic must be true or false, got {variadic!r}") |
| 240 | + if argument is None and position is None: |
| 241 | + raise ValueError("an attacker argument needs a name, a position or both") |
| 242 | + if variadic and position is None: |
| 243 | + raise ValueError("a variadic attacker argument needs the position it starts at") |
| 244 | + return AttackerArgument(argument, position, variadic) |
| 245 | + |
| 246 | + |
212 | 247 | def _condition(entry: Mapping[str, Any]) -> Condition: |
213 | 248 | position = entry.get("position") |
214 | 249 | if position is not None and (not isinstance(position, int) or isinstance(position, bool) or position < 0): |
|
0 commit comments