11
11
import json
12
12
import logging
13
13
import os
14
- import subprocess # nosec
14
+ import subprocess # nosec B404
15
15
import tempfile
16
16
17
17
import yaml
@@ -120,7 +120,7 @@ def _load_defaults(self, resources_path: str) -> tuple[str, str | None, set[str]
120
120
121
121
semgrep_commands : list [str ] = ["semgrep" , "scan" , "--validate" , "--oss-only" , "--config" , custom_rule_path ]
122
122
try :
123
- process = subprocess .run (semgrep_commands , check = True , capture_output = True ) # nosec
123
+ process = subprocess .run (semgrep_commands , check = True , capture_output = True ) # nosec B603
124
124
except (subprocess .CalledProcessError , subprocess .TimeoutExpired ) as semgrep_error :
125
125
error_msg = (
126
126
f"Unable to run semgrep validation on { custom_rule_path } with arguments "
@@ -185,8 +185,8 @@ def _extract_rule_ids(self, path: str, target_files: set[str]) -> set[str]:
185
185
If any Semgrep rule file could not be safely loaded, or if their format was not in the expected Semgrep
186
186
format, or if there were any files in 'target_files' not found when searching in 'path'.
187
187
"""
188
- # We keep a record of any file paths we coulnd 't find to provide a more useful error message, rather than raising
189
- # an error on the first missing file we see.
188
+ # We keep a record of any file paths we couldn 't find to provide a more useful error message, rather than
189
+ # raising an error on the first missing file we see.
190
190
missing_files : list [str ] = []
191
191
target_file_paths : list [str ] = []
192
192
rule_ids : set [str ] = set ()
@@ -211,7 +211,7 @@ def _extract_rule_ids(self, path: str, target_files: set[str]) -> set[str]:
211
211
logger .debug (error_msg )
212
212
raise ConfigurationError (error_msg ) from yaml_error
213
213
214
- # should be a top-level key "rules", and then a list of rules (dictionaries) with "id" entries
214
+ # Should be a top-level key "rules", and then a list of rules (dictionaries) with "id" entries.
215
215
try :
216
216
for semgrep_rule in semgrep_ruleset ["rules" ]:
217
217
rule_ids .add (semgrep_rule ["id" ])
@@ -243,7 +243,7 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes
243
243
if there is no source code available.
244
244
"""
245
245
analysis_result : dict = {}
246
- # since we have to run them anyway, return disabled rule findings for debug information
246
+ # Since we have to run them anyway, return disabled rule findings for debug information.
247
247
disabled_results : dict = {}
248
248
# Here, we disable 'nosemgrep' ignoring so that this is not an evasion method of our scan (i.e. malware includes
249
249
# 'nosemgrep' comments to prevent our scan detecting those code lines). Read more about the 'nosemgrep' feature
@@ -266,7 +266,7 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes
266
266
semgrep_commands .append (f"--json-output={ output_json_file .name } " )
267
267
logger .debug ("executing: %s." , semgrep_commands )
268
268
try :
269
- process = subprocess .run (semgrep_commands , check = True , capture_output = True ) # nosec
269
+ process = subprocess .run (semgrep_commands , check = True , capture_output = True ) # nosec B603
270
270
except (subprocess .CalledProcessError , subprocess .TimeoutExpired ) as semgrep_error :
271
271
error_msg = (
272
272
f"Unable to run semgrep on { source_code_path } with arguments { semgrep_commands } : { semgrep_error } "
@@ -320,7 +320,7 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes
320
320
analysis_result [rule_id ] = {"message" : message , "detections" : []}
321
321
analysis_result [rule_id ]["detections" ].append ({"file" : file , "start" : start , "end" : end })
322
322
323
- # some semgrep rules were triggered, even after removing disabled ones
323
+ # Some semgrep rules were triggered, even after removing disabled ones.
324
324
if analysis_result :
325
325
result = HeuristicResult .FAIL
326
326
0 commit comments