Skip to content

Commit c223e04

Browse files
authored
CM-55551 CLI SCA Scan Fails to Detect Indirect Dependencies Due to PNPM Lock File Handling (#360)
1 parent aac1446 commit c223e04

File tree

8 files changed

+47
-2
lines changed

8 files changed

+47
-2
lines changed

cycode/cli/files_collector/sca/base_restore_dependencies.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ def get_manifest_file_path(self, document: Document) -> str:
5757

5858
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 = [
61+
build_dep_tree_path(document.absolute_path, restore_file_path_item)
62+
for restore_file_path_item in self.get_lock_file_names()
63+
]
64+
restore_file_path = self.get_any_restore_file_already_exist(document, restore_file_paths)
65+
relative_restore_file_path = build_dep_tree_path(
66+
document.path, self.get_restored_lock_file_name(restore_file_path)
67+
)
6268

6369
if not self.verify_restore_file_already_exist(restore_file_path):
6470
output = execute_commands(
@@ -76,6 +82,16 @@ def try_restore_dependencies(self, document: Document) -> Optional[Document]:
7682
def get_working_directory(self, document: Document) -> Optional[str]:
7783
return os.path.dirname(document.absolute_path)
7884

85+
def get_restored_lock_file_name(self, restore_file_path: str) -> str:
86+
return self.get_lock_file_name()
87+
88+
def get_any_restore_file_already_exist(self, document: Document, restore_file_paths: list[str]) -> str:
89+
for restore_file_path in restore_file_paths:
90+
if os.path.isfile(restore_file_path):
91+
return restore_file_path
92+
93+
return build_dep_tree_path(document.absolute_path, self.get_lock_file_name())
94+
7995
@staticmethod
8096
def verify_restore_file_already_exist(restore_file_path: str) -> bool:
8197
return os.path.isfile(restore_file_path)
@@ -91,3 +107,7 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
91107
@abstractmethod
92108
def get_lock_file_name(self) -> str:
93109
pass
110+
111+
@abstractmethod
112+
def get_lock_file_names(self) -> list[str]:
113+
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
@@ -41,6 +41,9 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
4141
def get_lock_file_name(self) -> str:
4242
return BUILD_GRADLE_DEP_TREE_FILE_NAME
4343

44+
def get_lock_file_names(self) -> str:
45+
return [self.get_lock_file_name()]
46+
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
4649

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
3434
def get_lock_file_name(self) -> str:
3535
return join_paths('target', MAVEN_CYCLONE_DEP_TREE_FILE_NAME)
3636

37+
def get_lock_file_names(self) -> str:
38+
return [self.get_lock_file_name()]
39+
3740
def try_restore_dependencies(self, document: Document) -> Optional[Document]:
3841
manifest_file_path = self.get_manifest_file_path(document)
3942
if document.content is None:

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

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

88
NPM_PROJECT_FILE_EXTENSIONS = ['.json']
99
NPM_LOCK_FILE_NAME = 'package-lock.json'
10+
NPM_LOCK_FILE_NAMES = [NPM_LOCK_FILE_NAME, 'yarn.lock', 'pnpm-lock.yaml', 'deno.lock']
1011
NPM_MANIFEST_FILE_NAME = 'package.json'
1112

1213

@@ -30,9 +31,15 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]:
3031
]
3132
]
3233

34+
def get_restored_lock_file_name(self, restore_file_path: str) -> str:
35+
return os.path.basename(restore_file_path)
36+
3337
def get_lock_file_name(self) -> str:
3438
return NPM_LOCK_FILE_NAME
3539

40+
def get_lock_file_names(self) -> str:
41+
return NPM_LOCK_FILE_NAMES
42+
3643
@staticmethod
3744
def prepare_manifest_file_path_for_command(manifest_file_path: str) -> str:
3845
return manifest_file_path.replace(os.sep + NPM_MANIFEST_FILE_NAME, '')

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)