Skip to content

Commit 6978bd7

Browse files
committed
chore: add config variable to defaults.ini and minor cleanup
Signed-off-by: Amine <[email protected]>
1 parent 2815028 commit 6978bd7

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ docs/_build
181181
bin/
182182
requirements.txt
183183
.macaron_env_file
184-
**/.DS_Store
184+
.DS_Store

src/macaron/config/defaults.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,5 @@ major_threshold = 20
600600
epoch_threshold = 3
601601
# The number of days +/- the day of publish the calendar versioning day may be.
602602
day_publish_error = 4
603+
# THe threshold for the number of repeated spaces in a line from the source code.
604+
repeated_spaces_threshold =

src/macaron/malware_analyzer/pypi_heuristics/sourcecode/white_spaces.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ def _load_defaults(self) -> int:
4848
The repeated spaces threshold.
4949
"""
5050
section_name = "heuristic.pypi"
51+
default_threshold = 50
52+
5153
if defaults.has_section(section_name):
5254
section = defaults[section_name]
53-
return section.getint("repeated_spaces_threshold", 50)
55+
value_str = section.get("repeated_spaces_threshold", fallback=str(default_threshold))
56+
if value_str is not None and value_str.isdigit():
57+
return int(value_str)
58+
return default_threshold
5459

55-
return 50
60+
return default_threshold
5661

5762
def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicResult, dict[str, JsonType]]:
5863
"""Analyze the package.

src/macaron/slsa_analyzer/checks/detect_malicious_metadata_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
385385
386386
% Package released with excessive whitespace in the code .
387387
{Confidence.HIGH.value}::trigger(malware_high_confidence_4) :-
388-
quickUndetailed, forceSetup, failed({Heuristics.WHITE_SPACES.value}).
388+
forceSetup, failed({Heuristics.WHITE_SPACES.value}).
389389
390390
% Package released recently with little detail, with multiple releases as a trust marker, but frequent and with
391391
% the same code.

0 commit comments

Comments
 (0)