Skip to content

Commit 590e61f

Browse files
authored
CM-50645 - Fix secrets commit history scan (#327)
1 parent 810acbe commit 590e61f

File tree

5 files changed

+290
-11
lines changed

5 files changed

+290
-11
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.12.9-alpine3.21 AS base
22
WORKDIR /usr/cycode/app
3-
RUN apk add git=2.47.2-r0
3+
RUN apk add git=2.47.3-r0
44

55
FROM base AS builder
66
ENV POETRY_VERSION=1.8.3

cycode/cli/files_collector/commit_range_documents.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ def get_diff_file_path(diff: 'Diff', relative: bool = False) -> Optional[str]:
193193

194194
if diff.b_blob:
195195
return diff.b_blob.abspath
196-
return diff.a_blob.abspath
196+
if diff.a_blob:
197+
return diff.a_blob.abspath
198+
199+
return None
197200

198201

199202
def get_diff_file_content(diff: 'Diff') -> str:

cycode/cli/user_settings/configuration_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def add_exclusion(self, scope: str, scan_type: str, exclusion_type: str, value:
8282
@staticmethod
8383
def _merge_exclusions(local_exclusions: dict, global_exclusions: dict) -> dict:
8484
keys = set(list(local_exclusions.keys()) + list(global_exclusions.keys()))
85-
return {key: local_exclusions.get(key, []) + global_exclusions.get(key, []) for key in keys}
85+
return {key: (local_exclusions.get(key) or []) + (global_exclusions.get(key) or []) for key in keys}
8686

8787
def get_or_create_installation_id(self) -> str:
8888
config_file_manager = self.get_config_file_manager()

cycode/cli/utils/yaml_utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import yaml
66

7+
from cycode.logger import get_logger
8+
9+
logger = get_logger('YAML Utils')
10+
711

812
def _deep_update(source: dict[Hashable, Any], overrides: dict[Hashable, Any]) -> dict[Hashable, Any]:
913
for key, value in overrides.items():
@@ -15,10 +19,16 @@ def _deep_update(source: dict[Hashable, Any], overrides: dict[Hashable, Any]) ->
1519
return source
1620

1721

18-
def _yaml_safe_load(file: TextIO) -> dict[Hashable, Any]:
22+
def _yaml_object_safe_load(file: TextIO) -> dict[Hashable, Any]:
1923
# loader.get_single_data could return None
2024
loaded_file = yaml.safe_load(file)
21-
if loaded_file is None:
25+
26+
if not isinstance(loaded_file, dict):
27+
# forbid literals at the top level
28+
logger.debug(
29+
'YAML file does not contain a dictionary at the top level: %s',
30+
{'filename': file.name, 'actual_type': type(loaded_file)},
31+
)
2232
return {}
2333

2434
return loaded_file
@@ -29,7 +39,7 @@ def read_yaml_file(filename: str) -> dict[Hashable, Any]:
2939
return {}
3040

3141
with open(filename, encoding='UTF-8') as file:
32-
return _yaml_safe_load(file)
42+
return _yaml_object_safe_load(file)
3343

3444

3545
def write_yaml_file(filename: str, content: dict[Hashable, Any]) -> None:

0 commit comments

Comments
 (0)