Skip to content

Commit 9a90843

Browse files
authored
CM-48734 - Update file filtering for all scan types (#313)
1 parent ac26e55 commit 9a90843

File tree

2 files changed

+67
-26
lines changed

2 files changed

+67
-26
lines changed

cycode/cli/consts.py

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,40 @@
1414
SCA_SCAN_TYPE = 'sca'
1515
SAST_SCAN_TYPE = 'sast'
1616

17-
IAC_SCAN_SUPPORTED_FILES = ('.tf', '.tf.json', '.json', '.yaml', '.yml', 'dockerfile')
17+
IAC_SCAN_SUPPORTED_FILE_EXTENSIONS = ('.tf', '.tf.json', '.json', '.yaml', '.yml', '.dockerfile', '.containerfile')
18+
IAC_SCAN_SUPPORTED_FILE_PREFIXES = ('dockerfile', 'containerfile')
1819

1920
SECRET_SCAN_FILE_EXTENSIONS_TO_IGNORE = (
20-
'.7z',
21+
'.DS_Store',
2122
'.bmp',
22-
'.bz2',
23-
'.dmg',
24-
'.exe',
2523
'.gif',
26-
'.gz',
2724
'.ico',
28-
'.jar',
29-
'.jpg',
30-
'.jpeg',
31-
'.png',
32-
'.rar',
33-
'.realm',
34-
'.s7z',
35-
'.svg',
36-
'.tar',
3725
'.tif',
3826
'.tiff',
3927
'.webp',
40-
'.zi',
28+
'.mp3',
29+
'.mp4',
30+
'.mkv',
31+
'.avi',
32+
'.mov',
33+
'.mpg',
34+
'.mpeg',
35+
'.wav',
36+
'.vob',
37+
'.aac',
38+
'.flac',
39+
'.ogg',
40+
'.mka',
41+
'.wma',
42+
'.wmv',
43+
'.psd',
44+
'.ai',
45+
'.model',
4146
'.lock',
4247
'.css',
43-
'.less',
44-
'.dll',
45-
'.enc',
46-
'.deb',
47-
'.obj',
48-
'.model',
48+
'.pdf',
49+
'.odt',
50+
'.iso',
4951
)
5052

5153
SCA_CONFIGURATION_SCAN_SUPPORTED_FILES = ( # keep in lowercase
@@ -55,11 +57,18 @@
5557
'composer.lock',
5658
'go.sum',
5759
'go.mod',
60+
'go.mod.graph',
5861
'gopkg.lock',
5962
'pom.xml',
63+
'bom.json',
64+
'bcde.mvndeps',
6065
'build.gradle',
66+
'.gradle',
6167
'gradle.lockfile',
6268
'build.gradle.kts',
69+
'.gradle.kts',
70+
'.properties',
71+
'.kt', # config KT files
6372
'package.json',
6473
'package-lock.json',
6574
'yarn.lock',
@@ -69,9 +78,10 @@
6978
'packages.lock.json',
7079
'nuget.config',
7180
'.csproj',
81+
'.vbproj',
7282
'gemfile',
7383
'gemfile.lock',
74-
'build.sbt',
84+
'.sbt',
7585
'build.scala',
7686
'build.sbt.lock',
7787
'pyproject.toml',
@@ -84,14 +94,36 @@
8494
'mix.lock',
8595
'package.swift',
8696
'package.resolved',
97+
'pubspec.yaml',
98+
'pubspec.lock',
99+
'conanfile.py',
100+
'conanfile.txt',
101+
'maven_install.json',
102+
'conan.lock',
87103
)
88104

89-
SCA_EXCLUDED_PATHS = ('node_modules',)
105+
SCA_EXCLUDED_PATHS = (
106+
'node_modules',
107+
'venv',
108+
'.venv',
109+
'__pycache__',
110+
'.pytest_cache',
111+
'.tox',
112+
'.mvn',
113+
'.gradle',
114+
'.npm',
115+
'.yarn',
116+
'.bundle',
117+
'.bloop',
118+
'.build',
119+
'.dart_tool',
120+
'.pub',
121+
)
90122

91123
PROJECT_FILES_BY_ECOSYSTEM_MAP = {
92124
'crates': ['Cargo.lock', 'Cargo.toml'],
93125
'composer': ['composer.json', 'composer.lock'],
94-
'go': ['go.sum', 'go.mod', 'Gopkg.lock'],
126+
'go': ['go.sum', 'go.mod', 'go.mod.graph', 'Gopkg.lock'],
95127
'maven_pom': ['pom.xml'],
96128
'maven_gradle': ['build.gradle', 'build.gradle.kts', 'gradle.lockfile'],
97129
'npm': ['package.json', 'package-lock.json', 'yarn.lock', 'npm-shrinkwrap.json', '.npmrc'],
@@ -104,6 +136,8 @@
104136
'pypi_setup': ['setup.py'],
105137
'hex': ['mix.exs', 'mix.lock'],
106138
'swift_pm': ['Package.swift', 'Package.resolved'],
139+
'dart': ['pubspec.yaml', 'pubspec.lock'],
140+
'conan': ['conanfile.py', 'conanfile.txt', 'conan.lock'],
107141
}
108142

109143
COMMIT_RANGE_SCAN_SUPPORTED_SCAN_TYPES = [SECRET_SCAN_TYPE, SCA_SCAN_TYPE]

cycode/cli/files_collector/excluder.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ def _is_file_relevant_for_sca_scan(filename: str) -> bool:
5151

5252
class Excluder:
5353
def __init__(self) -> None:
54+
self._scannable_prefixes: dict[str, tuple[str, ...]] = {
55+
consts.IAC_SCAN_TYPE: consts.IAC_SCAN_SUPPORTED_FILE_PREFIXES,
56+
}
5457
self._scannable_extensions: dict[str, tuple[str, ...]] = {
55-
consts.IAC_SCAN_TYPE: consts.IAC_SCAN_SUPPORTED_FILES,
58+
consts.IAC_SCAN_TYPE: consts.IAC_SCAN_SUPPORTED_FILE_EXTENSIONS,
5659
consts.SCA_SCAN_TYPE: consts.SCA_CONFIGURATION_SCAN_SUPPORTED_FILES,
5760
}
5861
self._non_scannable_extensions: dict[str, tuple[str, ...]] = {
@@ -74,6 +77,10 @@ def _is_file_extension_supported(self, scan_type: str, filename: str) -> bool:
7477
if non_scannable_extensions:
7578
return not filename.endswith(non_scannable_extensions)
7679

80+
scannable_prefixes = self._scannable_prefixes.get(scan_type)
81+
if scannable_prefixes:
82+
return filename.startswith(scannable_prefixes)
83+
7784
return True
7885

7986
def _is_relevant_file_to_scan_common(self, scan_type: str, filename: str) -> bool:

0 commit comments

Comments
 (0)