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,78 @@
1
+ """
2
+ MASVS-CRYPTO Vulnerability Patterns
3
+
4
+ Patterns for detecting cryptographic vulnerabilities in Flutter/Dart code.
5
+ Maps to OWASP MASVS v2.1.0 CRYPTO category.
6
+
7
+ Catalog Reference: V005-V007
8
+ """
9
+
10
+ CRYPTO_PATTERNS = [
11
+ {
12
+ 'vulnerability_id': 'V005',
13
+ 'title': 'Weak Hashing Algorithms (MD5/SHA1)',
14
+ 'description': 'Using deprecated or weak hashing algorithms like MD5 or SHA1. These algorithms have known vulnerabilities and should not be used for security-sensitive operations.',
15
+ 'severity': 'high',
16
+ 'masvs_category': 'CRYPTO',
17
+ 'masvs_control': 'MASVS-CRYPTO-1',
18
+ 'cwe_id': 'CWE-327',
19
+ 'remediation': 'Use strong hashing algorithms: SHA-256, SHA-3, or bcrypt/Argon2 for password hashing. MD5/SHA1 are only acceptable for non-security checksums.',
20
+ 'patterns': [
21
+ r'\b(?:md5|sha1)\s*\.\s*(?:convert|hash|digest)',
22
+ r'import\s+["\']package:crypto/md5\.dart["\']',
23
+ r'import\s+["\']package:crypto/sha1\.dart["\']',
24
+ r'Md5\s*\(\s*\)',
25
+ r'Sha1\s*\(\s*\)',
26
+ ],
27
+ 'false_positive_patterns': [
28
+ r'//.*(?:MD5|SHA1)',
29
+ r'checksum',
30
+ r'file.*hash',
31
+ r'etag',
32
+ ]
33
+ },
34
+ {
35
+ 'vulnerability_id': 'V006',
36
+ 'title': 'Hardcoded Encryption Keys',
37
+ 'description': 'Encryption keys hardcoded in source code. Compromises all encrypted data if source code is exposed through reverse engineering or repository access.',
38
+ 'severity': 'critical',
39
+ 'masvs_category': 'CRYPTO',
40
+ 'masvs_control': 'MASVS-CRYPTO-2',
41
+ 'cwe_id': 'CWE-321',
42
+ 'remediation': 'Generate keys dynamically, store in secure storage (flutter_secure_storage), or use a key management service. Derive keys from user credentials using PBKDF2/Argon2.',
43
+ 'patterns': [
44
+ r'(?:encryption[_-]?key|aes[_-]?key|secret[_-]?key|crypto[_-]?key)\s*[:=]\s*["\'][^"\']{8,}["\']',
45
+ r'(?:const|final)\s+\w*[Kk]ey\w*\s*=\s*["\'][A-Za-z0-9+/=]{16,}["\']',
46
+ r'Key\s*\(\s*["\'][A-Za-z0-9+/=]{16,}["\']\s*\)',
47
+ r'(?:const|final)\s+\w*[Ii][Vv]\w*\s*=\s*["\'][A-Za-z0-9+/=]{16,}["\']',
48
+ ],
49
+ 'false_positive_patterns': [
50
+ r'//.*key',
51
+ r'TODO|FIXME|example|test',
52
+ r'generateKey',
53
+ r'deriveKey',
54
+ ]
55
+ },
56
+ {
57
+ 'vulnerability_id': 'V007',
58
+ 'title': 'Insecure Random Number Generation',
59
+ 'description': 'Using non-cryptographic random number generators for security-sensitive operations like token generation, nonces, or key generation.',
60
+ 'severity': 'medium',
61
+ 'masvs_category': 'CRYPTO',
62
+ 'masvs_control': 'MASVS-CRYPTO-1',
63
+ 'cwe_id': 'CWE-338',
64
+ 'remediation': 'Use Random.secure() for cryptographically secure random numbers in Dart. Never use math.Random() for security-sensitive operations.',
65
+ 'patterns': [
66
+ # Seeded Random is ALWAYS predictable and insecure
67
+ r'Random\s*\(\s*\d+\s*\)',
68
+ # Random used in token/key/password generation context
69
+ r'(?:token|key|password|pin|secret|nonce|salt|otp|session[_]?id)\s*[+=].*Random',
70
+ r'generate(?:Token|Key|Password|Pin|Secret|Nonce|Salt|Otp|Session).*Random\s*\(',
71
+ ],
72
+ 'false_positive_patterns': [
73
+ r'Random\s*\.\s*secure',
74
+ r'SecureRandom',
75
+ r'Random\.secure\s*\(',
76
+ ]
77
+ },
78
+ ]
@@ -0,0 +1,61 @@
1
+ """
2
+ MASVS-NETWORK Vulnerability Patterns
3
+
4
+ Patterns for detecting network security vulnerabilities in Flutter/Dart code.
5
+ Maps to OWASP MASVS v2.1.0 NETWORK category.
6
+
7
+ Catalog Reference: V011-V013
8
+ """
9
+
10
+ NETWORK_PATTERNS = [
11
+ {
12
+ 'vulnerability_id': 'V011',
13
+ 'title': 'Insecure HTTP Connections',
14
+ 'description': 'Using unencrypted HTTP instead of HTTPS for network communication. Data transmitted in plaintext can be intercepted by attackers on the same network.',
15
+ 'severity': 'high',
16
+ 'masvs_category': 'NETWORK',
17
+ 'masvs_control': 'MASVS-NETWORK-1',
18
+ 'cwe_id': 'CWE-319',
19
+ 'remediation': 'Always use HTTPS for network communication. Configure Network Security Config on Android to block cleartext traffic. Use http package with https:// URLs only.',
20
+ 'patterns': [
21
+ r'["\']http://(?!localhost|127\.0\.0\.1|10\.|192\.168\.|172\.(?:1[6-9]|2[0-9]|3[0-1])\.)[^"\']+["\']',
22
+ r'Uri\.parse\s*\(\s*["\']http://(?!localhost)',
23
+ r'baseUrl\s*[:=]\s*["\']http://(?!localhost)',
24
+ r'\.get\s*\(\s*["\']http://(?!localhost)',
25
+ r'\.post\s*\(\s*["\']http://(?!localhost)',
26
+ ],
27
+ 'false_positive_patterns': [
28
+ r'http://localhost',
29
+ r'http://127\.0\.0\.1',
30
+ r'http://10\.',
31
+ r'//.*http://',
32
+ r'http://example\.com',
33
+ ]
34
+ },
35
+ {
36
+ 'vulnerability_id': 'V012',
37
+ 'title': 'Disabled SSL/TLS Certificate Validation',
38
+ 'description': 'Disabling or bypassing SSL certificate validation allows man-in-the-middle attacks. Attackers can intercept and modify all network traffic.',
39
+ 'severity': 'critical',
40
+ 'masvs_category': 'NETWORK',
41
+ 'masvs_control': 'MASVS-NETWORK-1',
42
+ 'cwe_id': 'CWE-295',
43
+ 'remediation': 'Never disable certificate validation in production. Use certificate pinning for additional security. Only bypass for development with proper safeguards and kDebugMode checks.',
44
+ 'patterns': [
45
+ r'badCertificateCallback\s*[:=]\s*\([^)]*\)\s*=>\s*true',
46
+ r'onBadCertificate\s*[:=]\s*\([^)]*\)\s*=>\s*true',
47
+ r'badCertificateCallback.*return\s+true',
48
+ r'HttpOverrides\.global\s*=',
49
+ r'allowLegacyUnsafeRenegotiation\s*[:=]\s*true',
50
+ ],
51
+ 'false_positive_patterns': [
52
+ r'kDebugMode',
53
+ r'kReleaseMode\s*\?\s*false',
54
+ r'if\s*\(\s*!kReleaseMode\s*\)',
55
+ ]
56
+ },
57
+ # V013 has been moved to a project-level pubspec.yaml check
58
+ # (see scanner.py _check_pubspec_security method)
59
+ # Old approach: matching Dio() / http.Client() per line → massive false positives
60
+ # New approach: check if app uses HTTP clients but has no cert pinning package
61
+ ]
@@ -0,0 +1,164 @@
1
+ """
2
+ Pattern Registry Module
3
+
4
+ Central registry for all vulnerability detection patterns.
5
+ Matches the Flutter Vulnerability Catalog v2.0 (26 vulnerabilities).
6
+ """
7
+
8
+ from typing import List, Dict, Optional
9
+ from .base_pattern import BasePattern, RegexPattern
10
+
11
+ # Import all pattern categories
12
+ from .storage_patterns import STORAGE_PATTERNS
13
+ from .crypto_patterns import CRYPTO_PATTERNS
14
+ from .auth_patterns import AUTH_PATTERNS
15
+ from .network_patterns import NETWORK_PATTERNS
16
+ from .platform_patterns import PLATFORM_PATTERNS
17
+ from .code_patterns import CODE_PATTERNS
18
+ from .resilience_patterns import RESILIENCE_PATTERNS
19
+ from .privacy_patterns import PRIVACY_PATTERNS
20
+
21
+
22
+ class PatternRegistry:
23
+ """
24
+ Central registry for all vulnerability detection patterns.
25
+
26
+ This class manages the loading and retrieval of vulnerability patterns
27
+ organized by MASVS category.
28
+
29
+ Catalog Mapping:
30
+ - STORAGE: V001-V004 (4 patterns)
31
+ - CRYPTO: V005-V007 (3 patterns)
32
+ - AUTH: V008-V010 (3 patterns)
33
+ - NETWORK: V011-V013 (3 patterns)
34
+ - PLATFORM: V014-V017 (4 patterns)
35
+ - CODE: V018-V021 (4 patterns)
36
+ - RESILIENCE: V022-V024 (3 patterns)
37
+ - PRIVACY: V025-V026 (2 patterns)
38
+
39
+ Total: 26 vulnerability patterns
40
+ """
41
+
42
+ def __init__(self):
43
+ """Initialize the registry and load all patterns."""
44
+ self._patterns: Dict[str, List[BasePattern]] = {
45
+ 'STORAGE': [],
46
+ 'CRYPTO': [],
47
+ 'AUTH': [],
48
+ 'NETWORK': [],
49
+ 'PLATFORM': [],
50
+ 'CODE': [],
51
+ 'RESILIENCE': [],
52
+ 'PRIVACY': []
53
+ }
54
+
55
+ self._load_patterns()
56
+
57
+ def _load_patterns(self):
58
+ """Load all patterns from pattern modules."""
59
+ # Load storage patterns (V001-V004)
60
+ for pattern_def in STORAGE_PATTERNS:
61
+ self._patterns['STORAGE'].append(self._create_pattern(pattern_def))
62
+
63
+ # Load crypto patterns (V005-V007)
64
+ for pattern_def in CRYPTO_PATTERNS:
65
+ self._patterns['CRYPTO'].append(self._create_pattern(pattern_def))
66
+
67
+ # Load auth patterns (V008-V010)
68
+ for pattern_def in AUTH_PATTERNS:
69
+ self._patterns['AUTH'].append(self._create_pattern(pattern_def))
70
+
71
+ # Load network patterns (V011-V013)
72
+ for pattern_def in NETWORK_PATTERNS:
73
+ self._patterns['NETWORK'].append(self._create_pattern(pattern_def))
74
+
75
+ # Load platform patterns (V014-V017)
76
+ for pattern_def in PLATFORM_PATTERNS:
77
+ self._patterns['PLATFORM'].append(self._create_pattern(pattern_def))
78
+
79
+ # Load code patterns (V018-V021)
80
+ for pattern_def in CODE_PATTERNS:
81
+ self._patterns['CODE'].append(self._create_pattern(pattern_def))
82
+
83
+ # Load resilience patterns (V022-V024)
84
+ for pattern_def in RESILIENCE_PATTERNS:
85
+ self._patterns['RESILIENCE'].append(self._create_pattern(pattern_def))
86
+
87
+ # Load privacy patterns (V025-V026)
88
+ for pattern_def in PRIVACY_PATTERNS:
89
+ self._patterns['PRIVACY'].append(self._create_pattern(pattern_def))
90
+
91
+ def _create_pattern(self, pattern_def: dict) -> RegexPattern:
92
+ """Create a RegexPattern from a pattern definition dictionary."""
93
+ return RegexPattern(
94
+ vulnerability_id=pattern_def['vulnerability_id'],
95
+ title=pattern_def['title'],
96
+ description=pattern_def['description'],
97
+ severity=pattern_def['severity'],
98
+ masvs_category=pattern_def['masvs_category'],
99
+ masvs_control=pattern_def['masvs_control'],
100
+ remediation=pattern_def['remediation'],
101
+ cwe_id=pattern_def.get('cwe_id', ''),
102
+ patterns=pattern_def['patterns'],
103
+ false_positive_patterns=pattern_def.get('false_positive_patterns', []),
104
+ context_false_positive_patterns=pattern_def.get('context_false_positive_patterns', [])
105
+ )
106
+
107
+ def get_all_patterns(self) -> List[BasePattern]:
108
+ """Get all registered patterns."""
109
+ all_patterns = []
110
+ for category_patterns in self._patterns.values():
111
+ all_patterns.extend(category_patterns)
112
+ return all_patterns
113
+
114
+ def get_patterns_by_category(self, category: str) -> List[BasePattern]:
115
+ """
116
+ Get patterns for a specific MASVS category.
117
+
118
+ Args:
119
+ category: MASVS category name
120
+
121
+ Returns:
122
+ List of patterns for the category
123
+ """
124
+ return self._patterns.get(category, [])
125
+
126
+ def get_pattern_by_id(self, vulnerability_id: str) -> Optional[BasePattern]:
127
+ """
128
+ Get a specific pattern by its vulnerability ID.
129
+
130
+ Args:
131
+ vulnerability_id: The vulnerability ID (e.g., 'V001')
132
+
133
+ Returns:
134
+ The pattern if found, None otherwise
135
+ """
136
+ for pattern in self.get_all_patterns():
137
+ if pattern.vulnerability_id == vulnerability_id:
138
+ return pattern
139
+ return None
140
+
141
+ def get_pattern_count(self) -> int:
142
+ """Get total number of registered patterns."""
143
+ return len(self.get_all_patterns())
144
+
145
+ def get_category_counts(self) -> Dict[str, int]:
146
+ """Get pattern counts by category."""
147
+ return {
148
+ category: len(patterns)
149
+ for category, patterns in self._patterns.items()
150
+ }
151
+
152
+ def get_catalog_summary(self) -> str:
153
+ """Get a summary of the vulnerability catalog."""
154
+ counts = self.get_category_counts()
155
+ total = self.get_pattern_count()
156
+
157
+ summary = "Flutter Vulnerability Catalog v2.0\n"
158
+ summary += "=" * 40 + "\n"
159
+ for category, count in counts.items():
160
+ summary += f"MASVS-{category}: {count} patterns\n"
161
+ summary += "=" * 40 + "\n"
162
+ summary += f"Total: {total} vulnerability patterns\n"
163
+
164
+ return summary
@@ -0,0 +1,97 @@
1
+ """
2
+ MASVS-PLATFORM Vulnerability Patterns
3
+
4
+ Patterns for detecting platform interaction vulnerabilities in Flutter/Dart code.
5
+ Maps to OWASP MASVS v2.1.0 PLATFORM category.
6
+
7
+ Catalog Reference: V014-V017
8
+ """
9
+
10
+ PLATFORM_PATTERNS = [
11
+ {
12
+ 'vulnerability_id': 'V014',
13
+ 'title': 'Insecure Deep Link Handling',
14
+ 'description': 'Deep links that don\'t validate input before processing sensitive operations. Attackers can craft malicious deep links to trigger unintended actions.',
15
+ 'severity': 'medium',
16
+ 'masvs_category': 'PLATFORM',
17
+ 'masvs_control': 'MASVS-PLATFORM-1',
18
+ 'cwe_id': 'CWE-939',
19
+ 'remediation': 'Validate all deep link parameters. Implement allowlist for valid deep link paths. Require authentication for sensitive deep link actions.',
20
+ 'patterns': [
21
+ r'onGenerateRoute\s*:\s*\([^)]*\)\s*{',
22
+ r'uni_links.*getInitialLink',
23
+ r'app_links.*getInitialAppLink',
24
+ r'getInitialLink\s*\(\s*\)\.then',
25
+ r'linkStream\.listen',
26
+ ],
27
+ 'false_positive_patterns': [
28
+ r'validate.*[Ll]ink',
29
+ r'sanitize.*[Uu]ri',
30
+ r'isValidDeepLink',
31
+ r'verifyDeepLink',
32
+ ]
33
+ },
34
+ {
35
+ 'vulnerability_id': 'V015',
36
+ 'title': 'WebView with JavaScript Enabled',
37
+ 'description': 'WebView components with JavaScript enabled loading untrusted content. JavaScript can be used for XSS attacks or to access sensitive WebView APIs.',
38
+ 'severity': 'medium',
39
+ 'masvs_category': 'PLATFORM',
40
+ 'masvs_control': 'MASVS-PLATFORM-2',
41
+ 'cwe_id': 'CWE-749',
42
+ 'remediation': 'Disable JavaScript unless strictly required. Only load trusted content. Implement Content Security Policy. Validate and sanitize all URLs before loading.',
43
+ 'patterns': [
44
+ r'javascriptMode\s*:\s*JavascriptMode\.unrestricted',
45
+ r'javaScriptMode\s*:\s*JavaScriptMode\.unrestricted',
46
+ r'setJavaScriptEnabled\s*\(\s*true\s*\)',
47
+ r'WebView\s*\([^)]*javascriptMode[^)]*unrestricted',
48
+ ],
49
+ 'false_positive_patterns': [
50
+ r'javascriptMode\s*:\s*JavascriptMode\.disabled',
51
+ r'trustedDomain',
52
+ ]
53
+ },
54
+ {
55
+ 'vulnerability_id': 'V016',
56
+ 'title': 'Exposed JavaScript Bridge',
57
+ 'description': 'JavaScript bridges that expose sensitive native functionality to web content. Malicious web content can invoke native functions.',
58
+ 'severity': 'high',
59
+ 'masvs_category': 'PLATFORM',
60
+ 'masvs_control': 'MASVS-PLATFORM-2',
61
+ 'cwe_id': 'CWE-749',
62
+ 'remediation': 'Minimize JavaScript bridge exposure. Validate all messages from JavaScript. Only expose necessary functions. Implement origin checking.',
63
+ 'patterns': [
64
+ r'addJavaScriptChannel\s*\(',
65
+ r'JavaScriptChannel\s*\(',
66
+ r'evaluateJavascript\s*\([^)]*\$',
67
+ r'runJavaScript\s*\([^)]*\+',
68
+ r'webViewController\.addJavaScriptChannel',
69
+ ],
70
+ 'false_positive_patterns': [
71
+ r'validateMessage',
72
+ r'sanitizeInput',
73
+ r'trustedOrigin',
74
+ ]
75
+ },
76
+ {
77
+ 'vulnerability_id': 'V017',
78
+ 'title': 'Sensitive UI Not Protected from Screenshots',
79
+ 'description': 'Screens displaying sensitive data (passwords, financial info) are not protected from screenshots or screen recording. Data may leak through screenshots or recent apps view.',
80
+ 'severity': 'low',
81
+ 'masvs_category': 'PLATFORM',
82
+ 'masvs_control': 'MASVS-PLATFORM-3',
83
+ 'cwe_id': 'CWE-200',
84
+ 'remediation': 'Use flutter_windowmanager or platform channels to set FLAG_SECURE on Android. Use appropriate UIScreen settings on iOS. Implement screen capture detection.',
85
+ 'patterns': [
86
+ r'TextField\s*\([^)]*obscureText\s*:\s*true',
87
+ r'TextFormField\s*\([^)]*obscureText\s*:\s*true',
88
+ r'CupertinoTextField\s*\([^)]*obscureText\s*:\s*true',
89
+ ],
90
+ 'false_positive_patterns': [
91
+ r'flutter_windowmanager',
92
+ r'FlutterWindowManager',
93
+ r'FLAG_SECURE',
94
+ r'setSecureFlag',
95
+ ]
96
+ },
97
+ ]
@@ -0,0 +1,64 @@
1
+ """
2
+ MASVS-PRIVACY Vulnerability Patterns
3
+
4
+ Patterns for detecting privacy-related vulnerabilities in Flutter/Dart code.
5
+ Maps to OWASP MASVS v2.1.0 PRIVACY category.
6
+
7
+ Catalog Reference: V025-V026
8
+ """
9
+
10
+ PRIVACY_PATTERNS = [
11
+ {
12
+ 'vulnerability_id': 'V025',
13
+ 'title': 'Excessive Permission Requests',
14
+ 'description': 'App requests more permissions than necessary for its functionality, violating the principle of least privilege and potentially exposing user data.',
15
+ 'severity': 'medium',
16
+ 'masvs_category': 'PRIVACY',
17
+ 'masvs_control': 'MASVS-PRIVACY-1',
18
+ 'cwe_id': 'CWE-250',
19
+ 'remediation': 'Review and minimize required permissions. Request permissions at runtime only when needed. Clearly explain to users why each permission is required.',
20
+ 'patterns': [
21
+ # Only flag Android manifest entries requesting dangerous permissions
22
+ # Individual Dart permission.request() calls are normal Flutter behaviour
23
+ r'uses-permission.*(?:CAMERA|RECORD_AUDIO|ACCESS_FINE_LOCATION|READ_CONTACTS|READ_SMS|READ_PHONE_STATE|READ_CALL_LOG|READ_EXTERNAL_STORAGE)',
24
+ # Flag requesting many permissions in a single batch (4+ = suspicious)
25
+ r'await\s*\[.*Permission\.\w+.*Permission\.\w+.*Permission\.\w+.*Permission\.\w+.*\]\.request\(\)',
26
+ ],
27
+ 'false_positive_patterns': [
28
+ r'permissionStatus',
29
+ r'isGranted',
30
+ r'checkPermission',
31
+ r'<!--', # Commented-out manifest entries
32
+ ]
33
+ },
34
+ {
35
+ 'vulnerability_id': 'V026',
36
+ 'title': 'Collection of Persistent Device Identifiers',
37
+ 'description': 'App collects hardware identifiers (IMEI, MAC address, Android ID) that can track users across app reinstalls. This raises privacy concerns and may violate regulations.',
38
+ 'severity': 'medium',
39
+ 'masvs_category': 'PRIVACY',
40
+ 'masvs_control': 'MASVS-PRIVACY-2',
41
+ 'cwe_id': 'CWE-359',
42
+ 'remediation': 'Avoid collecting persistent device identifiers. Use instance-specific identifiers that reset on reinstall. For advertising, use the platform advertising ID with user consent.',
43
+ 'patterns': [
44
+ # Only match androidId when it's being READ from device info, not used as a named parameter
45
+ r'\.androidId\b',
46
+ r'Settings\.Secure\.ANDROID_ID',
47
+ r'getIMEI\s*\(',
48
+ r'getMacAddress\s*\(',
49
+ r'identifierForVendor',
50
+ r'advertisingIdentifier',
51
+ r'DeviceInfoPlugin.*(?:androidId|identifierForVendor)',
52
+ r'device_info_plus.*androidId',
53
+ ],
54
+ 'false_positive_patterns': [
55
+ r'advertisingId.*consent',
56
+ r'privacyPolicy',
57
+ r'userConsent',
58
+ # Named parameters for store product IDs (e.g., androidId: 'com.app.product')
59
+ r"""androidId\s*:\s*['"]""",
60
+ # Constructor field declarations (e.g., required this.androidId)
61
+ r'this\.androidId',
62
+ ]
63
+ },
64
+ ]
@@ -0,0 +1,68 @@
1
+ """
2
+ MASVS-RESILIENCE Vulnerability Patterns
3
+
4
+ Patterns for detecting anti-tampering and reverse engineering weaknesses.
5
+ Maps to OWASP MASVS v2.1.0 RESILIENCE category.
6
+
7
+ Catalog Reference: V022-V024
8
+ """
9
+
10
+ RESILIENCE_PATTERNS = [
11
+ {
12
+ 'vulnerability_id': 'V022',
13
+ 'title': 'Missing Root/Jailbreak Detection',
14
+ 'description': 'App does not detect if running on a rooted/jailbroken device. Rooted devices can bypass app security controls and access protected data.',
15
+ 'severity': 'medium',
16
+ 'masvs_category': 'RESILIENCE',
17
+ 'masvs_control': 'MASVS-RESILIENCE-1',
18
+ 'cwe_id': 'CWE-919',
19
+ 'remediation': 'Implement root/jailbreak detection using flutter_jailbreak_detection, root_checker, or safe_device packages. Take appropriate action (warn user, limit functionality, or exit) when detected.',
20
+ 'patterns': [
21
+ # V022 is now handled separately by scanning pubspec.yaml
22
+ # These patterns are intentionally left empty
23
+ ],
24
+ 'false_positive_patterns': []
25
+ },
26
+ {
27
+ 'vulnerability_id': 'V023',
28
+ 'title': 'Missing App Integrity Verification',
29
+ 'description': 'App does not verify its own integrity, allowing modified or repackaged versions to run. Attackers can inject malicious code.',
30
+ 'severity': 'medium',
31
+ 'masvs_category': 'RESILIENCE',
32
+ 'masvs_control': 'MASVS-RESILIENCE-2',
33
+ 'cwe_id': 'CWE-354',
34
+ 'remediation': 'Implement app integrity checking using Play Integrity API (Android) or App Attest (iOS). Verify app signature at runtime. Use code signing verification.',
35
+ 'patterns': [
36
+ # Patterns indicating apps handling sensitive data without integrity checks
37
+ r'(?:payment|banking|financial)(?:Service|Manager|Controller)',
38
+ r'(?:license|subscription|premium)(?:Check|Verify|Manager)',
39
+ ],
40
+ 'false_positive_patterns': [
41
+ r'PlayIntegrity',
42
+ r'AppAttest',
43
+ r'integrityCheck',
44
+ r'signatureVerif',
45
+ r'checksumValid',
46
+ r'freeRASP',
47
+ ]
48
+ },
49
+ {
50
+ 'vulnerability_id': 'V024',
51
+ 'title': 'Missing Code Obfuscation',
52
+ 'description': 'Release build does not use code obfuscation, making reverse engineering significantly easier. Class and method names reveal application logic.',
53
+ 'severity': 'low',
54
+ 'masvs_category': 'RESILIENCE',
55
+ 'masvs_control': 'MASVS-RESILIENCE-3',
56
+ 'cwe_id': 'CWE-656',
57
+ 'remediation': 'Enable Dart obfuscation in release builds using --obfuscate flag with --split-debug-info. Example: flutter build apk --obfuscate --split-debug-info=./debug-info',
58
+ 'patterns': [
59
+ # Patterns detecting build commands without obfuscation
60
+ r'flutter\s+build\s+(?:apk|appbundle|ios|ipa)(?!.*--obfuscate)',
61
+ ],
62
+ 'false_positive_patterns': [
63
+ r'--obfuscate',
64
+ r'--split-debug-info',
65
+ r'proguard',
66
+ ]
67
+ },
68
+ ]
@@ -0,0 +1,111 @@
1
+ """
2
+ MASVS-STORAGE Vulnerability Patterns
3
+
4
+ Patterns for detecting insecure data storage vulnerabilities in Flutter/Dart code.
5
+ Maps to OWASP MASVS v2.1.0 STORAGE category.
6
+
7
+ Catalog Reference: V001-V004
8
+ """
9
+
10
+ STORAGE_PATTERNS = [
11
+ {
12
+ 'vulnerability_id': 'V001',
13
+ 'title': 'Hardcoded API Keys/Secrets',
14
+ 'description': 'API keys, passwords, or secrets hardcoded directly in source code. Attackers can extract these through reverse engineering or by accessing the source repository.',
15
+ 'severity': 'high',
16
+ 'masvs_category': 'STORAGE',
17
+ 'masvs_control': 'MASVS-STORAGE-1',
18
+ 'cwe_id': 'CWE-798',
19
+ 'remediation': 'Store secrets in secure storage (flutter_secure_storage), environment variables, or a secrets management service. Never commit credentials to source control.',
20
+ 'patterns': [
21
+ r'(?:api[_-]?key|apikey|secret|password|token|credential|auth[_-]?token|access[_-]?token|private[_-]?key)\s*[:=]\s*["\'][^"\']{8,}["\']',
22
+ r'(?:const|final)\s+\w*(?:key|secret|password|token|credential)\w*\s*=\s*["\'][^"\']+["\']',
23
+ r'sk-[A-Za-z0-9]{20,}',
24
+ r'Bearer\s+[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+',
25
+ ],
26
+ 'false_positive_patterns': [
27
+ r'//.*(?:api[_-]?key|password|token)',
28
+ r'\*.*(?:api[_-]?key|password|token)',
29
+ r'TODO|FIXME|example|placeholder|your[_-]?key|<.*>',
30
+ # NOTE: Config constants (kebab-case, snake_case, kOption*, *Key variables)
31
+ # are now handled by the shared Dart/Flutter whitelist in base_pattern.py
32
+ # The following are V001-specific FP filters:
33
+ # UI label strings (e.g., 'Password', 'Enter password')
34
+ r"""['"](Enter\s+|Confirm\s+|New\s+|Old\s+|Current\s+)?[Pp]assword['"]\s*[,;)\]]""",
35
+ # UI display strings with spaces (e.g., 'Forgot Password?', 'Reset Password')
36
+ r"""(?:const|final)\s+(?:\w+\s+)*\w+\s*=\s*['"][^'"]*\s+[^'"]*(?:[Pp]assword|[Tt]oken)[^'"]*['"]""",
37
+ # Short string values (less than 8 chars) that happen to contain keyword
38
+ r"""(?:password|token|secret|key)\s*[:=]\s*['"][^'"]{0,7}['"]""",
39
+ # Hint text and label patterns
40
+ r'(?:hint|label|placeholder|text)\s*:\s*["\'].*(?:password|token)',
41
+ # Map key lookups (e.g., data['password'])
42
+ r"""\[['"](?:password|token|key|secret)['"]\]""",
43
+ ]
44
+ },
45
+ {
46
+ 'vulnerability_id': 'V002',
47
+ 'title': 'Sensitive Data in SharedPreferences',
48
+ 'description': 'Storing sensitive data (passwords, tokens, PII) in SharedPreferences without encryption. SharedPreferences data is stored in plaintext XML files accessible on rooted devices.',
49
+ 'severity': 'high',
50
+ 'masvs_category': 'STORAGE',
51
+ 'masvs_control': 'MASVS-STORAGE-1',
52
+ 'cwe_id': 'CWE-312',
53
+ 'remediation': 'Use flutter_secure_storage for sensitive data, which encrypts data using platform-specific secure storage (Keychain on iOS, EncryptedSharedPreferences on Android).',
54
+ 'patterns': [
55
+ # Only flag when a sensitive keyword appears as a QUOTED STRING key name
56
+ # e.g., prefs.setString('password', value) or prefs.setString("auth_token", value)
57
+ # Does NOT match: prefs.setBool(key, value) where 'key' is a variable
58
+ r'(?:prefs|preferences|sharedPrefs|sharedPreferences)\??\s*\.\s*set(?:String|Int|Bool|Double)\s*\(\s*["\'](?:password|token|secret|credential|auth|session|pin)',
59
+ r'SharedPreferences.*set(?:String|Int|Bool)\s*\(\s*["\'](?:password|token|secret|credential|auth|session|pin)',
60
+ ],
61
+ 'false_positive_patterns': [
62
+ r'flutter_secure_storage',
63
+ r'EncryptedSharedPreferences',
64
+ r'secureStorage',
65
+ # Non-sensitive SharedPreferences keys
66
+ r'(?:theme|locale|language|onboarding|remember_me|saved_email|first_launch|dark_mode|font_size|notification)',
67
+ ]
68
+ },
69
+ {
70
+ 'vulnerability_id': 'V003',
71
+ 'title': 'Logging Sensitive Data',
72
+ 'description': 'Printing sensitive information (passwords, tokens, PII) to logs using print(), debugPrint(), or logging frameworks. Logs may be accessible through ADB or crash reports.',
73
+ 'severity': 'medium',
74
+ 'masvs_category': 'STORAGE',
75
+ 'masvs_control': 'MASVS-STORAGE-2',
76
+ 'cwe_id': 'CWE-532',
77
+ 'remediation': 'Remove sensitive data from logs. Use conditional logging that is disabled in release builds. Implement log sanitization.',
78
+ 'patterns': [
79
+ r'(?:print|log|debugPrint|logger)\s*\(.*\b(?:password|token|secret|key|credential|session|auth)',
80
+ r'print\s*\(\s*["\'].*(?:password|token|secret)',
81
+ r'log\s*\(\s*["\'].*(?:Auth|Token|Password)',
82
+ ],
83
+ 'false_positive_patterns': [
84
+ r'kDebugMode\s*\?\s*print',
85
+ # NOTE: Function declarations, function calls, kOption constants,
86
+ # super.key, and .keys are now handled by the shared whitelist.
87
+ # V003-specific FP filters:
88
+ # Log messages that mention keywords in a descriptive/error context
89
+ r"""(?:print|log|debugPrint)\s*\(\s*['"][^'"]*(?:Ignore|Failed|Error|Invalid|Wrong|Missing|Disabled|not enabled)[^'"]*(?:password|token|auth|session)""",
90
+ ],
91
+ 'context_false_positive_patterns': [
92
+ r'kReleaseMode',
93
+ r'if\s*\(\s*kDebugMode\s*\)',
94
+ ]
95
+ },
96
+ {
97
+ 'vulnerability_id': 'V004',
98
+ 'title': 'Sensitive Data in Clipboard',
99
+ 'description': 'Copying sensitive data to the system clipboard. Other apps can access clipboard content, and it may persist after the app is closed.',
100
+ 'severity': 'medium',
101
+ 'masvs_category': 'STORAGE',
102
+ 'masvs_control': 'MASVS-STORAGE-2',
103
+ 'cwe_id': 'CWE-200',
104
+ 'remediation': 'Avoid copying sensitive data to clipboard. If necessary, clear clipboard after a timeout. Warn users before copying sensitive data.',
105
+ 'patterns': [
106
+ r'Clipboard\.setData.*\b(?:password|token|secret|key|credential)',
107
+ r'ClipboardData\s*\(.*(?:password|token|secret)',
108
+ ],
109
+ 'false_positive_patterns': []
110
+ },
111
+ ]
@@ -0,0 +1,11 @@
1
+ """
2
+ Reporters Module
3
+
4
+ Contains output formatters for scan results.
5
+ """
6
+
7
+ from .console_reporter import ConsoleReporter
8
+ from .json_reporter import JsonReporter
9
+ from .html_reporter import HtmlReporter
10
+
11
+ __all__ = ['ConsoleReporter', 'JsonReporter', 'HtmlReporter']