flutter-security-analyzer 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. flutter_security_analyzer/__init__.py +12 -0
  2. flutter_security_analyzer/__main__.py +8 -0
  3. flutter_security_analyzer/core/__init__.py +15 -0
  4. flutter_security_analyzer/core/config.py +128 -0
  5. flutter_security_analyzer/core/scanner.py +543 -0
  6. flutter_security_analyzer/main.py +150 -0
  7. flutter_security_analyzer/mappers/__init__.py +9 -0
  8. flutter_security_analyzer/mappers/masvs_mapper.py +308 -0
  9. flutter_security_analyzer/patterns/__init__.py +32 -0
  10. flutter_security_analyzer/patterns/auth_patterns.py +95 -0
  11. flutter_security_analyzer/patterns/base_pattern.py +514 -0
  12. flutter_security_analyzer/patterns/code_patterns.py +103 -0
  13. flutter_security_analyzer/patterns/crypto_patterns.py +78 -0
  14. flutter_security_analyzer/patterns/network_patterns.py +61 -0
  15. flutter_security_analyzer/patterns/pattern_registry.py +164 -0
  16. flutter_security_analyzer/patterns/platform_patterns.py +97 -0
  17. flutter_security_analyzer/patterns/privacy_patterns.py +64 -0
  18. flutter_security_analyzer/patterns/resilience_patterns.py +68 -0
  19. flutter_security_analyzer/patterns/storage_patterns.py +111 -0
  20. flutter_security_analyzer/reporters/__init__.py +11 -0
  21. flutter_security_analyzer/reporters/console_reporter.py +165 -0
  22. flutter_security_analyzer/reporters/html_reporter.py +230 -0
  23. flutter_security_analyzer/reporters/json_reporter.py +107 -0
  24. flutter_security_analyzer/utils/__init__.py +7 -0
  25. flutter_security_analyzer-1.0.1.dist-info/METADATA +239 -0
  26. flutter_security_analyzer-1.0.1.dist-info/RECORD +30 -0
  27. flutter_security_analyzer-1.0.1.dist-info/WHEEL +5 -0
  28. flutter_security_analyzer-1.0.1.dist-info/entry_points.txt +2 -0
  29. flutter_security_analyzer-1.0.1.dist-info/licenses/LICENSE +21 -0
  30. flutter_security_analyzer-1.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,165 @@
1
+ """
2
+ Console Reporter Module
3
+
4
+ Outputs scan results to the console with colour formatting.
5
+ """
6
+
7
+ import sys
8
+ from typing import Optional
9
+
10
+ from flutter_security_analyzer.core.scanner import ScanResults
11
+
12
+
13
+ class ConsoleReporter:
14
+ """
15
+ Reporter that outputs findings to the console with formatting.
16
+ """
17
+
18
+ # ANSI colour codes
19
+ COLOURS = {
20
+ 'critical': '\033[91m', # Red
21
+ 'high': '\033[93m', # Yellow
22
+ 'medium': '\033[94m', # Blue
23
+ 'low': '\033[96m', # Cyan
24
+ 'info': '\033[90m', # Grey
25
+ 'reset': '\033[0m',
26
+ 'bold': '\033[1m',
27
+ 'green': '\033[92m',
28
+ }
29
+
30
+ def __init__(self, output_path: Optional[str] = None):
31
+ """
32
+ Initialize the console reporter.
33
+
34
+ Args:
35
+ output_path: If provided, output will also be written to this file
36
+ """
37
+ self.output_path = output_path
38
+ self.output_lines = []
39
+
40
+ def generate(self, results: ScanResults):
41
+ """
42
+ Generate and display console report.
43
+
44
+ Args:
45
+ results: ScanResults object containing findings
46
+ """
47
+ self._print_header(results)
48
+ self._print_summary(results)
49
+ self._print_findings(results)
50
+ self._print_footer(results)
51
+
52
+ # Write to file if path provided
53
+ if self.output_path:
54
+ self._write_to_file()
55
+
56
+ def _print(self, text: str = "", colour: str = None):
57
+ """Print text with optional colour."""
58
+ if colour and colour in self.COLOURS:
59
+ formatted = f"{self.COLOURS[colour]}{text}{self.COLOURS['reset']}"
60
+ else:
61
+ formatted = text
62
+
63
+ print(formatted)
64
+ # Store without ANSI codes for file output
65
+ self.output_lines.append(text)
66
+
67
+ def _print_header(self, results: ScanResults):
68
+ """Print report header."""
69
+ self._print()
70
+ self._print("=" * 70, 'bold')
71
+ self._print(" FLUTTER SECURITY SCANNER - SCAN RESULTS", 'bold')
72
+ self._print("=" * 70, 'bold')
73
+ self._print()
74
+ self._print(f" Scan Path: {results.scan_path}")
75
+ self._print(f" Timestamp: {results.scan_timestamp}")
76
+ self._print(f" Duration: {results.scan_duration_seconds:.2f} seconds")
77
+ self._print(f" Files Scanned: {results.total_files_scanned}")
78
+ self._print(f" Lines Scanned: {results.total_lines_scanned}")
79
+ self._print()
80
+
81
+ def _print_summary(self, results: ScanResults):
82
+ """Print findings summary."""
83
+ self._print("-" * 70)
84
+ self._print(" SUMMARY", 'bold')
85
+ self._print("-" * 70)
86
+ self._print()
87
+
88
+ self._print(f" Total Findings: {results.total_findings}")
89
+ self._print()
90
+
91
+ # Severity breakdown
92
+ self._print(f" Critical: {results.critical_count}", 'critical')
93
+ self._print(f" High: {results.high_count}", 'high')
94
+ self._print(f" Medium: {results.medium_count}", 'medium')
95
+ self._print(f" Low: {results.low_count}", 'low')
96
+ self._print(f" Info: {results.info_count}", 'info')
97
+ self._print()
98
+
99
+ def _print_findings(self, results: ScanResults):
100
+ """Print detailed findings."""
101
+ if not results.findings:
102
+ self._print(" No vulnerabilities found!", 'green')
103
+ self._print()
104
+ return
105
+
106
+ self._print("-" * 70)
107
+ self._print(" DETAILED FINDINGS", 'bold')
108
+ self._print("-" * 70)
109
+
110
+ # Group by category
111
+ categories = {}
112
+ for finding in results.findings:
113
+ if finding.masvs_category not in categories:
114
+ categories[finding.masvs_category] = []
115
+ categories[finding.masvs_category].append(finding)
116
+
117
+ for category, findings in sorted(categories.items()):
118
+ self._print()
119
+ self._print(f" [{category}] ({len(findings)} findings)", 'bold')
120
+ self._print()
121
+
122
+ for i, finding in enumerate(findings, 1):
123
+ self._print_finding(finding, i)
124
+
125
+ def _print_finding(self, finding, index: int):
126
+ """Print a single finding."""
127
+ severity_colour = finding.severity
128
+
129
+ self._print(f" {index}. [{finding.severity.upper()}] {finding.title}", severity_colour)
130
+ self._print(f" ID: {finding.vulnerability_id}")
131
+ self._print(f" File: {finding.file_path}")
132
+ self._print(f" Line: {finding.line_number}")
133
+ self._print(f" MASVS: {finding.masvs_control}")
134
+ if finding.cwe_id:
135
+ self._print(f" CWE: {finding.cwe_id}")
136
+ self._print(f" Confidence: {finding.confidence}")
137
+ self._print()
138
+ self._print(f" Description:")
139
+ self._print(f" {finding.description}")
140
+ self._print()
141
+ self._print(f" Code:")
142
+ for line in finding.code_snippet.split('\n'):
143
+ self._print(f" {line}")
144
+ self._print()
145
+ self._print(f" Remediation:")
146
+ self._print(f" {finding.remediation}")
147
+ self._print()
148
+ self._print(" " + "-" * 50)
149
+ self._print()
150
+
151
+ def _print_footer(self, results: ScanResults):
152
+ """Print report footer."""
153
+ self._print("=" * 70)
154
+ self._print(" Scan completed. Review findings and apply remediations.", 'bold')
155
+ self._print(" For MASVS compliance details, see: https://mas.owasp.org/MASVS/")
156
+ self._print("=" * 70)
157
+ self._print()
158
+
159
+ def _write_to_file(self):
160
+ """Write output to file (without ANSI codes)."""
161
+ try:
162
+ with open(self.output_path, 'w', encoding='utf-8') as f:
163
+ f.write('\n'.join(self.output_lines))
164
+ except IOError as e:
165
+ print(f"Error writing to file: {e}", file=sys.stderr)
@@ -0,0 +1,230 @@
1
+ """
2
+ HTML Reporter Module
3
+
4
+ Outputs scan results as an HTML report.
5
+ """
6
+
7
+ import sys
8
+ from typing import Optional
9
+ from datetime import datetime
10
+
11
+ from flutter_security_analyzer.core.scanner import ScanResults
12
+ from flutter_security_analyzer.mappers.masvs_mapper import MasvsMapper
13
+
14
+
15
+ class HtmlReporter:
16
+ """
17
+ Reporter that outputs findings as an HTML report.
18
+
19
+ Generates a standalone HTML file with interactive features
20
+ and professional styling.
21
+ """
22
+
23
+ def __init__(self, output_path: Optional[str] = None):
24
+ """
25
+ Initialize the HTML reporter.
26
+
27
+ Args:
28
+ output_path: If provided, output will be written to this file
29
+ """
30
+ self.output_path = output_path or 'security_report.html'
31
+ self.masvs_mapper = MasvsMapper()
32
+
33
+ def generate(self, results: ScanResults):
34
+ """
35
+ Generate HTML report.
36
+
37
+ Args:
38
+ results: ScanResults object containing findings
39
+ """
40
+ html = self._build_html(results)
41
+ self._write_to_file(html)
42
+ print(f"HTML report generated: {self.output_path}")
43
+
44
+ def _build_html(self, results: ScanResults) -> str:
45
+ """Build the HTML report."""
46
+ findings_html = self._build_findings_html(results)
47
+ compliance_html = self._build_compliance_html(results)
48
+
49
+ return f'''<!DOCTYPE html>
50
+ <html lang="en">
51
+ <head>
52
+ <meta charset="UTF-8">
53
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
54
+ <title>Flutter Security Scan Report</title>
55
+ <style>
56
+ * {{ margin: 0; padding: 0; box-sizing: border-box; }}
57
+ body {{ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif; line-height: 1.6; color: #333; background: #f5f5f5; }}
58
+ .container {{ max-width: 1200px; margin: 0 auto; padding: 20px; }}
59
+ header {{ background: linear-gradient(135deg, #1a237e 0%, #0d47a1 100%); color: white; padding: 30px; border-radius: 8px; margin-bottom: 20px; }}
60
+ header h1 {{ font-size: 2rem; margin-bottom: 10px; }}
61
+ header p {{ opacity: 0.9; }}
62
+ .card {{ background: white; border-radius: 8px; padding: 20px; margin-bottom: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }}
63
+ .card h2 {{ color: #1a237e; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 2px solid #e3f2fd; }}
64
+ .stats {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; margin-bottom: 20px; }}
65
+ .stat {{ text-align: center; padding: 15px; border-radius: 8px; }}
66
+ .stat-critical {{ background: #ffebee; color: #c62828; }}
67
+ .stat-high {{ background: #fff3e0; color: #ef6c00; }}
68
+ .stat-medium {{ background: #e3f2fd; color: #1565c0; }}
69
+ .stat-low {{ background: #e0f7fa; color: #00838f; }}
70
+ .stat-info {{ background: #f5f5f5; color: #616161; }}
71
+ .stat h3 {{ font-size: 2rem; margin-bottom: 5px; }}
72
+ .finding {{ border-left: 4px solid #ccc; padding: 15px; margin-bottom: 15px; background: #fafafa; border-radius: 0 8px 8px 0; }}
73
+ .finding-critical {{ border-color: #c62828; }}
74
+ .finding-high {{ border-color: #ef6c00; }}
75
+ .finding-medium {{ border-color: #1565c0; }}
76
+ .finding-low {{ border-color: #00838f; }}
77
+ .finding-info {{ border-color: #616161; }}
78
+ .finding h3 {{ margin-bottom: 10px; }}
79
+ .finding-meta {{ font-size: 0.9rem; color: #666; margin-bottom: 10px; }}
80
+ .finding-meta span {{ margin-right: 15px; }}
81
+ .code-snippet {{ background: #263238; color: #aed581; padding: 15px; border-radius: 4px; overflow-x: auto; font-family: 'Monaco', 'Menlo', monospace; font-size: 0.85rem; margin: 10px 0; }}
82
+ .remediation {{ background: #e8f5e9; padding: 10px; border-radius: 4px; margin-top: 10px; }}
83
+ .badge {{ display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.8rem; font-weight: bold; text-transform: uppercase; }}
84
+ .badge-critical {{ background: #c62828; color: white; }}
85
+ .badge-high {{ background: #ef6c00; color: white; }}
86
+ .badge-medium {{ background: #1565c0; color: white; }}
87
+ .badge-low {{ background: #00838f; color: white; }}
88
+ .badge-info {{ background: #616161; color: white; }}
89
+ .compliance-table {{ width: 100%; border-collapse: collapse; }}
90
+ .compliance-table th, .compliance-table td {{ padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0; }}
91
+ .compliance-table th {{ background: #f5f5f5; font-weight: 600; }}
92
+ .status-pass {{ color: #2e7d32; }}
93
+ .status-fail {{ color: #c62828; }}
94
+ footer {{ text-align: center; padding: 20px; color: #666; }}
95
+ </style>
96
+ </head>
97
+ <body>
98
+ <div class="container">
99
+ <header>
100
+ <h1>🔒 Flutter Security Scan Report</h1>
101
+ <p>Generated by Flutter Security Scanner v{results.scanner_version}</p>
102
+ <p>MSc Cybersecurity Project - University of Chester</p>
103
+ </header>
104
+
105
+ <div class="card">
106
+ <h2>📊 Scan Overview</h2>
107
+ <p><strong>Path:</strong> {results.scan_path}</p>
108
+ <p><strong>Timestamp:</strong> {results.scan_timestamp}</p>
109
+ <p><strong>Duration:</strong> {results.scan_duration_seconds:.2f} seconds</p>
110
+ <p><strong>Files Scanned:</strong> {results.total_files_scanned}</p>
111
+ <p><strong>Lines Scanned:</strong> {results.total_lines_scanned}</p>
112
+ </div>
113
+
114
+ <div class="card">
115
+ <h2>📈 Summary</h2>
116
+ <div class="stats">
117
+ <div class="stat stat-critical">
118
+ <h3>{results.critical_count}</h3>
119
+ <p>Critical</p>
120
+ </div>
121
+ <div class="stat stat-high">
122
+ <h3>{results.high_count}</h3>
123
+ <p>High</p>
124
+ </div>
125
+ <div class="stat stat-medium">
126
+ <h3>{results.medium_count}</h3>
127
+ <p>Medium</p>
128
+ </div>
129
+ <div class="stat stat-low">
130
+ <h3>{results.low_count}</h3>
131
+ <p>Low</p>
132
+ </div>
133
+ <div class="stat stat-info">
134
+ <h3>{results.info_count}</h3>
135
+ <p>Info</p>
136
+ </div>
137
+ </div>
138
+ </div>
139
+
140
+ <div class="card">
141
+ <h2>✅ MASVS Compliance</h2>
142
+ {compliance_html}
143
+ </div>
144
+
145
+ <div class="card">
146
+ <h2>🔍 Detailed Findings ({results.total_findings})</h2>
147
+ {findings_html}
148
+ </div>
149
+
150
+ <footer>
151
+ <p>Flutter Security Scanner - MSc Cybersecurity Project</p>
152
+ <p>Caleb Elebhose - University of Chester - {datetime.now().year}</p>
153
+ </footer>
154
+ </div>
155
+ </body>
156
+ </html>'''
157
+
158
+ def _build_findings_html(self, results: ScanResults) -> str:
159
+ """Build HTML for findings section."""
160
+ if not results.findings:
161
+ return '<p style="color: #2e7d32; font-weight: bold;">✅ No vulnerabilities found!</p>'
162
+
163
+ html_parts = []
164
+ for finding in results.findings:
165
+ code_snippet = finding.code_snippet.replace('<', '&lt;').replace('>', '&gt;')
166
+
167
+ html_parts.append(f'''
168
+ <div class="finding finding-{finding.severity}">
169
+ <h3>
170
+ <span class="badge badge-{finding.severity}">{finding.severity}</span>
171
+ {finding.title}
172
+ </h3>
173
+ <div class="finding-meta">
174
+ <span>📁 {finding.file_path}</span>
175
+ <span>📍 Line {finding.line_number}</span>
176
+ <span>🏷️ {finding.vulnerability_id}</span>
177
+ <span>📋 {finding.masvs_control}</span>
178
+ {f'<span>🔗 {finding.cwe_id}</span>' if finding.cwe_id else ''}
179
+ </div>
180
+ <p>{finding.description}</p>
181
+ <div class="code-snippet"><pre>{code_snippet}</pre></div>
182
+ <div class="remediation">
183
+ <strong>💡 Remediation:</strong> {finding.remediation}
184
+ </div>
185
+ </div>
186
+ ''')
187
+
188
+ return '\n'.join(html_parts)
189
+
190
+ def _build_compliance_html(self, results: ScanResults) -> str:
191
+ """Build HTML for compliance table."""
192
+ compliance = self.masvs_mapper.get_compliance_summary(results.findings)
193
+
194
+ rows = []
195
+ for category_id, category_data in compliance.items():
196
+ status_class = 'status-pass' if category_data['status'] == 'PASS' else 'status-fail'
197
+ status_icon = '✅' if category_data['status'] == 'PASS' else '❌'
198
+
199
+ rows.append(f'''
200
+ <tr>
201
+ <td><strong>{category_id}</strong></td>
202
+ <td>{category_data['name']}</td>
203
+ <td>{category_data['findings_count']}</td>
204
+ <td class="{status_class}">{status_icon} {category_data['status']}</td>
205
+ </tr>
206
+ ''')
207
+
208
+ return f'''
209
+ <table class="compliance-table">
210
+ <thead>
211
+ <tr>
212
+ <th>Category</th>
213
+ <th>Name</th>
214
+ <th>Findings</th>
215
+ <th>Status</th>
216
+ </tr>
217
+ </thead>
218
+ <tbody>
219
+ {''.join(rows)}
220
+ </tbody>
221
+ </table>
222
+ '''
223
+
224
+ def _write_to_file(self, html: str):
225
+ """Write HTML output to file."""
226
+ try:
227
+ with open(self.output_path, 'w', encoding='utf-8') as f:
228
+ f.write(html)
229
+ except IOError as e:
230
+ print(f"Error writing to file: {e}", file=sys.stderr)
@@ -0,0 +1,107 @@
1
+ """
2
+ JSON Reporter Module
3
+
4
+ Outputs scan results in JSON format for CI/CD integration.
5
+ """
6
+
7
+ import json
8
+ import sys
9
+ from typing import Optional
10
+
11
+ from flutter_security_analyzer.core.scanner import ScanResults
12
+ from flutter_security_analyzer.mappers.masvs_mapper import MasvsMapper
13
+
14
+
15
+ class JsonReporter:
16
+ """
17
+ Reporter that outputs findings in JSON format.
18
+
19
+ This format is suitable for:
20
+ - CI/CD pipeline integration
21
+ - Automated processing
22
+ - API responses
23
+ - SARIF conversion
24
+ """
25
+
26
+ def __init__(self, output_path: Optional[str] = None):
27
+ """
28
+ Initialize the JSON reporter.
29
+
30
+ Args:
31
+ output_path: If provided, output will be written to this file
32
+ """
33
+ self.output_path = output_path
34
+ self.masvs_mapper = MasvsMapper()
35
+
36
+ def generate(self, results: ScanResults):
37
+ """
38
+ Generate JSON report.
39
+
40
+ Args:
41
+ results: ScanResults object containing findings
42
+ """
43
+ report = self._build_report(results)
44
+ json_output = json.dumps(report, indent=2)
45
+
46
+ if self.output_path:
47
+ self._write_to_file(json_output)
48
+ else:
49
+ print(json_output)
50
+
51
+ def _build_report(self, results: ScanResults) -> dict:
52
+ """Build the JSON report structure."""
53
+ return {
54
+ 'scanner': {
55
+ 'name': 'Flutter Security Scanner',
56
+ 'version': results.scanner_version,
57
+ 'project': 'MSc Cybersecurity - University of Chester'
58
+ },
59
+ 'scan': {
60
+ 'path': results.scan_path,
61
+ 'timestamp': results.scan_timestamp,
62
+ 'duration_seconds': results.scan_duration_seconds,
63
+ 'files_scanned': results.total_files_scanned,
64
+ 'lines_scanned': results.total_lines_scanned
65
+ },
66
+ 'summary': {
67
+ 'total_findings': results.total_findings,
68
+ 'severity_counts': {
69
+ 'critical': results.critical_count,
70
+ 'high': results.high_count,
71
+ 'medium': results.medium_count,
72
+ 'low': results.low_count,
73
+ 'info': results.info_count
74
+ },
75
+ 'categories_affected': list(set(f.masvs_category for f in results.findings))
76
+ },
77
+ 'compliance': self.masvs_mapper.get_compliance_summary(results.findings),
78
+ 'findings': [
79
+ {
80
+ 'id': f.vulnerability_id,
81
+ 'title': f.title,
82
+ 'description': f.description,
83
+ 'severity': f.severity,
84
+ 'confidence': f.confidence,
85
+ 'location': {
86
+ 'file': f.file_path,
87
+ 'line': f.line_number,
88
+ 'code_snippet': f.code_snippet
89
+ },
90
+ 'masvs': {
91
+ 'category': f.masvs_category,
92
+ 'control': f.masvs_control
93
+ },
94
+ 'cwe_id': f.cwe_id,
95
+ 'remediation': f.remediation
96
+ }
97
+ for f in results.findings
98
+ ]
99
+ }
100
+
101
+ def _write_to_file(self, json_output: str):
102
+ """Write JSON output to file."""
103
+ try:
104
+ with open(self.output_path, 'w', encoding='utf-8') as f:
105
+ f.write(json_output)
106
+ except IOError as e:
107
+ print(f"Error writing to file: {e}", file=sys.stderr)
@@ -0,0 +1,7 @@
1
+ """
2
+ Utils Module
3
+
4
+ Utility functions and helpers.
5
+ """
6
+
7
+ __all__ = []