Skip to content

Commit 6c8ebdf

Browse files
committed
CM-55551 CLI SCA Scan Fails to Detect Indirect Dependencies Due to PNPM Lock File Handling
1 parent 865be0a commit 6c8ebdf

File tree

8 files changed

+52
-6
lines changed

8 files changed

+52
-6
lines changed

cycode/cli/files_collector/sca/base_restore_dependencies.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ def get_manifest_file_path(self, document: Document) -> str:
5555
join_paths(get_path_from_context(self.ctx), document.path) if self.ctx.obj.get('monitor') else document.path
5656
)
5757

58-
def try_restore_dependencies(self, document: Document) -> Optional[Document]:
58+
def try_restore_dependencies(self, document: Document) -> Optional[Document]:
5959
manifest_file_path = self.get_manifest_file_path(document)
60-
restore_file_path = build_dep_tree_path(document.absolute_path, self.get_lock_file_name())
61-
relative_restore_file_path = build_dep_tree_path(document.path, self.get_lock_file_name())
60+
restore_file_paths = [build_dep_tree_path(document.absolute_path, restore_file_path_item) for restore_file_path_item in self.get_lock_file_names()]
61+
restore_file_path = self.get_any_restore_file_already_exist(restore_file_paths)
62+
relative_restore_file_path = build_dep_tree_path(document.path, self.get_restored_lock_file_name(restore_file_path))
6263

63-
if not self.verify_restore_file_already_exist(restore_file_path):
64+
if self.verify_lockfile_missing(restore_file_path):
6465
output = execute_commands(
6566
commands=self.get_commands(manifest_file_path),
6667
timeout=self.command_timeout,
@@ -75,10 +76,21 @@ def try_restore_dependencies(self, document: Document) -> Optional[Document]:
7576

7677
def get_working_directory(self, document: Document) -> Optional[str]:
7778
return os.path.dirname(document.absolute_path)
79+
80+
def get_restored_lock_file_name(self, restore_file_path: str) -> str:
81+
return self.get_lock_file_name()
82+
83+
@staticmethod
84+
def get_any_restore_file_already_exist(restore_file_paths: list[str]) -> Optional[str]:
85+
for restore_file_path in restore_file_paths:
86+
if os.path.isfile(restore_file_path):
87+
return restore_file_path
88+
89+
return None
7890

7991
@staticmethod
80-
def verify_restore_file_already_exist(restore_file_path: str) -> bool:
81-
return os.path.isfile(restore_file_path)
92+
def verify_lockfile_missing(restore_file_path: Optional[str]) -> bool:
93+
return restore_file_path is None
8294

8395
@abstractmethod
8496
def is_project(self, document: Document) -> bool:
@@ -91,3 +103,7 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
91103
@abstractmethod
92104
def get_lock_file_name(self) -> str:
93105
pass
106+
107+
@abstractmethod
108+
def get_lock_file_names(self) -> list[str]:
109+
pass

cycode/cli/files_collector/sca/go/restore_go_dependencies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
4343

4444
def get_lock_file_name(self) -> str:
4545
return GO_RESTORE_FILE_NAME
46+
47+
def get_lock_file_names(self) -> str:
48+
return [self.get_lock_file_name()]

cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
4040

4141
def get_lock_file_name(self) -> str:
4242
return BUILD_GRADLE_DEP_TREE_FILE_NAME
43+
44+
def get_lock_file_names(self) -> str:
45+
return [self.get_lock_file_name()]
4346

4447
def get_working_directory(self, document: Document) -> Optional[str]:
4548
return get_path_from_context(self.ctx) if self.is_gradle_sub_projects() else None

cycode/cli/files_collector/sca/maven/restore_maven_dependencies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
3333

3434
def get_lock_file_name(self) -> str:
3535
return join_paths('target', MAVEN_CYCLONE_DEP_TREE_FILE_NAME)
36+
37+
def get_lock_file_names(self) -> str:
38+
return [self.get_lock_file_name()]
3639

3740
def try_restore_dependencies(self, document: Document) -> Optional[Document]:
3841
manifest_file_path = self.get_manifest_file_path(document)

cycode/cli/files_collector/sca/npm/restore_npm_dependencies.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
NPM_PROJECT_FILE_EXTENSIONS = ['.json']
99
NPM_LOCK_FILE_NAME = 'package-lock.json'
10+
NPM_LOCK_FILE_NAMES = [
11+
NPM_LOCK_FILE_NAME,
12+
'yarn.lock',
13+
'pnpm-lock.yaml',
14+
'deno.lock'
15+
]
1016
NPM_MANIFEST_FILE_NAME = 'package.json'
1117

1218

@@ -29,9 +35,15 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
2935
'--no-audit',
3036
]
3137
]
38+
39+
def get_restored_lock_file_name(self, restore_file_path: str) -> str:
40+
return NPM_LOCK_FILE_NAME if restore_file_path is None else os.path.basename(restore_file_path)
3241

3342
def get_lock_file_name(self) -> str:
3443
return NPM_LOCK_FILE_NAME
44+
45+
def get_lock_file_names(self) -> str:
46+
return NPM_LOCK_FILE_NAMES
3547

3648
@staticmethod
3749
def prepare_manifest_file_path_for_command(manifest_file_path: str) -> str:

cycode/cli/files_collector/sca/nuget/restore_nuget_dependencies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
1919

2020
def get_lock_file_name(self) -> str:
2121
return NUGET_LOCK_FILE_NAME
22+
23+
def get_lock_file_names(self) -> str:
24+
return [self.get_lock_file_name()]

cycode/cli/files_collector/sca/ruby/restore_ruby_dependencies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
1414

1515
def get_lock_file_name(self) -> str:
1616
return RUBY_LOCK_FILE_NAME
17+
18+
def get_lock_file_names(self) -> str:
19+
return [self.get_lock_file_name()]

cycode/cli/files_collector/sca/sbt/restore_sbt_dependencies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
1414

1515
def get_lock_file_name(self) -> str:
1616
return SBT_LOCK_FILE_NAME
17+
18+
def get_lock_file_names(self) -> str:
19+
return [self.get_lock_file_name()]

0 commit comments

Comments
 (0)