Skip to content

Commit 06615b7

Browse files
committed
Fix some issues and add limits for scanning
1 parent 1bf7461 commit 06615b7

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

generate_xlsx_report.py

+14-23
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
from dataclasses import dataclass
2-
from typing import List
1+
# generate_xlsx_report.py
32

4-
import openpyxl
5-
from openpyxl.styles import Font, PatternFill, Alignment
3+
from openpyxl import Workbook
4+
from openpyxl.styles import Font, PatternFill, Alignment, Border, Side
65
from openpyxl.utils import get_column_letter
6+
from typing import List, NamedTuple
7+
import re
78

8-
9-
@dataclass
10-
class ScanResult:
9+
class ScanResult(NamedTuple):
1110
file_path: str
1211
line_number: int
1312
title: str
@@ -27,12 +26,9 @@ def severity_key(result: ScanResult):
2726

2827

2928
def generate_xlsx_report(results: List[ScanResult], output_file: str):
30-
# Sort results by severity
31-
results.sort(key=severity_key)
32-
33-
wb = openpyxl.Workbook()
29+
wb = Workbook()
3430
ws = wb.active
35-
ws.title = "Scan Results"
31+
ws.title = "Security Scan Results"
3632

3733
# Define styles
3834
header_font = Font(bold=True, color="FFFFFF")
@@ -93,17 +89,12 @@ def generate_xlsx_report(results: List[ScanResult], output_file: str):
9389
# Save the workbook
9490
wb.save(output_file)
9591

96-
97-
# Example usage
9892
if __name__ == "__main__":
99-
# Sample data
93+
# Example usage
10094
sample_results = [
101-
ScanResult("file1.abap", 10, "CheckCrossSiteScripting", "Potential XSS vulnerability", "High"),
102-
ScanResult("file2.abap", 25, "CheckHardcodedCredentials", "Hardcoded password detected", "Critical"),
103-
ScanResult("file1.abap", 50, "CheckOSCommandInjection", "Potential OS command injection", "High"),
104-
ScanResult("file3.abap", 100, "CheckWeakCrypto", "Use of weak cryptographic algorithm", "Medium"),
105-
ScanResult("file4.abap", 75, "CheckInfoDisclosure", "Potential information disclosure", "Low"),
95+
ScanResult("file1.abap", 10, "Potential XSS", "Unsanitized input", "High"),
96+
ScanResult("file2.abap", 25, "SQL Injection", "Dynamic SQL query", "Critical"),
97+
# Add more sample results as needed
10698
]
107-
108-
generate_xlsx_report(sample_results, "security_scan_report.xlsx")
109-
print("XLSX report generated successfully.")
99+
generate_xlsx_report(sample_results, "sample_security_scan_report.xlsx")
100+
print("Sample report generated: sample_security_scan_report.xlsx")

scanner.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _load_checks(self):
2727
checks.append(check_class())
2828
return checks
2929

30-
def scan(self, path: str) -> List[ScanResult]:
30+
def scan(self, path: str, limit: int = 40000) -> List[ScanResult]:
3131
results = []
3232
files_to_scan = []
3333

@@ -39,6 +39,13 @@ def scan(self, path: str) -> List[ScanResult]:
3939
for file in files:
4040
if any(file.endswith(ext) for ext in self.config.get_file_extensions()):
4141
files_to_scan.append(os.path.join(root, file))
42+
if len(files_to_scan) >= limit:
43+
break
44+
if len(files_to_scan) >= limit:
45+
break
46+
47+
# Limit the number of files to scan
48+
files_to_scan = files_to_scan[:limit]
4249

4350
# Scan files with progress bar
4451
for file_path in tqdm(files_to_scan, desc="Scanning files", unit="file"):

0 commit comments

Comments
 (0)