flutter-security-analyzer 1.0.1__tar.gz → 1.1.0__tar.gz
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.
- {flutter_security_analyzer-1.0.1/src/flutter_security_analyzer.egg-info → flutter_security_analyzer-1.1.0}/PKG-INFO +61 -5
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/README.md +60 -4
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/__init__.py +1 -1
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/main.py +4 -2
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/reporters/__init__.py +2 -1
- flutter_security_analyzer-1.1.0/src/flutter_security_analyzer/reporters/sarif_reporter.py +253 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0/src/flutter_security_analyzer.egg-info}/PKG-INFO +61 -5
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer.egg-info/SOURCES.txt +2 -0
- flutter_security_analyzer-1.1.0/tests/test_sarif_reporter.py +195 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/LICENSE +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/pyproject.toml +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/setup.cfg +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/__main__.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/core/__init__.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/core/config.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/core/scanner.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/mappers/__init__.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/mappers/masvs_mapper.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/__init__.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/auth_patterns.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/base_pattern.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/code_patterns.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/crypto_patterns.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/network_patterns.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/pattern_registry.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/platform_patterns.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/privacy_patterns.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/resilience_patterns.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/patterns/storage_patterns.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/reporters/console_reporter.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/reporters/html_reporter.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/reporters/json_reporter.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer/utils/__init__.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer.egg-info/dependency_links.txt +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer.egg-info/entry_points.txt +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer.egg-info/requires.txt +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/src/flutter_security_analyzer.egg-info/top_level.txt +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/tests/test_config_scanning.py +0 -0
- {flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/tests/test_scanner.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flutter-security-analyzer
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Static security analysis tool for Flutter/Dart applications with MASVS compliance mapping
|
|
5
5
|
Author-email: Caleb Elebhose <elebhosec@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -48,8 +48,8 @@ This tool is developed as part of an MSc Cybersecurity final year project at the
|
|
|
48
48
|
|
|
49
49
|
- **Pattern-Based Detection**: Regex-based vulnerability detection for Dart code
|
|
50
50
|
- **MASVS Compliance Mapping**: All findings mapped to OWASP MASVS v2.1.0 controls
|
|
51
|
-
- **Multiple Output Formats**: Console, JSON, and
|
|
52
|
-
- **CI/CD Integration**: Exit codes
|
|
51
|
+
- **Multiple Output Formats**: Console, JSON, HTML and SARIF reports
|
|
52
|
+
- **CI/CD Integration**: Exit codes for pipelines, and a GitHub Action that puts findings in GitHub code scanning
|
|
53
53
|
- **26 Vulnerability Checks**: Covering all 8 MASVS categories
|
|
54
54
|
|
|
55
55
|
## Sample Report
|
|
@@ -120,6 +120,9 @@ flutter-security-analyzer ./my_flutter_app -f json -o results.json
|
|
|
120
120
|
|
|
121
121
|
# HTML report
|
|
122
122
|
flutter-security-analyzer ./my_flutter_app -f html -o report.html
|
|
123
|
+
|
|
124
|
+
# SARIF 2.1.0, for GitHub code scanning and other security dashboards
|
|
125
|
+
flutter-security-analyzer ./my_flutter_app -f sarif -o results.sarif
|
|
123
126
|
```
|
|
124
127
|
|
|
125
128
|
### Filter by Severity
|
|
@@ -150,7 +153,58 @@ flutter-security-analyzer ./my_flutter_app -v
|
|
|
150
153
|
- `1`: High severity findings detected
|
|
151
154
|
- `2`: Critical findings detected
|
|
152
155
|
|
|
153
|
-
### GitHub
|
|
156
|
+
### GitHub Action
|
|
157
|
+
|
|
158
|
+
The repository is also a GitHub Action. It scans your project and uploads the findings to GitHub code scanning, so they appear in the Security tab and on the affected lines of pull requests.
|
|
159
|
+
|
|
160
|
+
```yaml
|
|
161
|
+
name: Flutter security scan
|
|
162
|
+
|
|
163
|
+
on:
|
|
164
|
+
push:
|
|
165
|
+
branches: [main]
|
|
166
|
+
pull_request:
|
|
167
|
+
|
|
168
|
+
permissions:
|
|
169
|
+
contents: read
|
|
170
|
+
security-events: write # needed to upload results to code scanning
|
|
171
|
+
|
|
172
|
+
jobs:
|
|
173
|
+
scan:
|
|
174
|
+
runs-on: ubuntu-latest
|
|
175
|
+
steps:
|
|
176
|
+
- uses: actions/checkout@v7
|
|
177
|
+
with:
|
|
178
|
+
persist-credentials: false
|
|
179
|
+
|
|
180
|
+
- uses: eCaleb/flutter-security-analyzer@v1.1.0
|
|
181
|
+
with:
|
|
182
|
+
path: .
|
|
183
|
+
fail-on: high
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
For supply-chain safety, pin the action to a full commit SHA rather than a tag. The scanner is installed from the action's own code, so the pin fixes the scanner version too.
|
|
187
|
+
|
|
188
|
+
| Input | Default | Description |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| `path` | `.` | Flutter project directory or Dart file to scan, relative to the repository root |
|
|
191
|
+
| `severity` | `low` | Lowest severity to report: `critical`, `high`, `medium`, `low` or `info` |
|
|
192
|
+
| `masvs-categories` | all | Space-separated MASVS categories, for example `STORAGE CRYPTO` |
|
|
193
|
+
| `config` | none | Path to a scanner configuration file |
|
|
194
|
+
| `sarif-file` | `flutter-security-analyzer.sarif` | Where to write the SARIF report |
|
|
195
|
+
| `upload-sarif` | `true` | Upload the report to code scanning. Needs `security-events: write` |
|
|
196
|
+
| `category` | `flutter-security-analyzer` | Code scanning category. Use a different one for each path if you scan several |
|
|
197
|
+
| `fail-on` | `high` | Fail the step when findings at or above this severity are reported, or `never`. Checked after the upload |
|
|
198
|
+
|
|
199
|
+
| Output | Description |
|
|
200
|
+
|---|---|
|
|
201
|
+
| `sarif-file` | Path to the SARIF report |
|
|
202
|
+
| `findings` | Total number of findings |
|
|
203
|
+
| `critical`, `high` | Number of critical and high findings |
|
|
204
|
+
|
|
205
|
+
Code scanning is free for public repositories. Private repositories need GitHub Code Security. To use the report elsewhere without uploading it, set `upload-sarif: 'false'` and keep the file as an artifact.
|
|
206
|
+
|
|
207
|
+
### Other CI systems
|
|
154
208
|
|
|
155
209
|
```yaml
|
|
156
210
|
- name: Security Scan
|
|
@@ -202,11 +256,13 @@ flutter-security-analyzer/
|
|
|
202
256
|
│ └── reporters/
|
|
203
257
|
│ ├── console_reporter.py
|
|
204
258
|
│ ├── json_reporter.py
|
|
205
|
-
│
|
|
259
|
+
│ ├── html_reporter.py
|
|
260
|
+
│ └── sarif_reporter.py # SARIF 2.1.0 for code scanning
|
|
206
261
|
├── tests/
|
|
207
262
|
├── docs/images/ # README screenshots
|
|
208
263
|
├── samples/ # Deliberately vulnerable and secure sample apps
|
|
209
264
|
├── .github/workflows/
|
|
265
|
+
├── action.yml # GitHub Action
|
|
210
266
|
├── Dockerfile
|
|
211
267
|
├── pyproject.toml
|
|
212
268
|
├── requirements.txt
|
|
@@ -17,8 +17,8 @@ This tool is developed as part of an MSc Cybersecurity final year project at the
|
|
|
17
17
|
|
|
18
18
|
- **Pattern-Based Detection**: Regex-based vulnerability detection for Dart code
|
|
19
19
|
- **MASVS Compliance Mapping**: All findings mapped to OWASP MASVS v2.1.0 controls
|
|
20
|
-
- **Multiple Output Formats**: Console, JSON, and
|
|
21
|
-
- **CI/CD Integration**: Exit codes
|
|
20
|
+
- **Multiple Output Formats**: Console, JSON, HTML and SARIF reports
|
|
21
|
+
- **CI/CD Integration**: Exit codes for pipelines, and a GitHub Action that puts findings in GitHub code scanning
|
|
22
22
|
- **26 Vulnerability Checks**: Covering all 8 MASVS categories
|
|
23
23
|
|
|
24
24
|
## Sample Report
|
|
@@ -89,6 +89,9 @@ flutter-security-analyzer ./my_flutter_app -f json -o results.json
|
|
|
89
89
|
|
|
90
90
|
# HTML report
|
|
91
91
|
flutter-security-analyzer ./my_flutter_app -f html -o report.html
|
|
92
|
+
|
|
93
|
+
# SARIF 2.1.0, for GitHub code scanning and other security dashboards
|
|
94
|
+
flutter-security-analyzer ./my_flutter_app -f sarif -o results.sarif
|
|
92
95
|
```
|
|
93
96
|
|
|
94
97
|
### Filter by Severity
|
|
@@ -119,7 +122,58 @@ flutter-security-analyzer ./my_flutter_app -v
|
|
|
119
122
|
- `1`: High severity findings detected
|
|
120
123
|
- `2`: Critical findings detected
|
|
121
124
|
|
|
122
|
-
### GitHub
|
|
125
|
+
### GitHub Action
|
|
126
|
+
|
|
127
|
+
The repository is also a GitHub Action. It scans your project and uploads the findings to GitHub code scanning, so they appear in the Security tab and on the affected lines of pull requests.
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
name: Flutter security scan
|
|
131
|
+
|
|
132
|
+
on:
|
|
133
|
+
push:
|
|
134
|
+
branches: [main]
|
|
135
|
+
pull_request:
|
|
136
|
+
|
|
137
|
+
permissions:
|
|
138
|
+
contents: read
|
|
139
|
+
security-events: write # needed to upload results to code scanning
|
|
140
|
+
|
|
141
|
+
jobs:
|
|
142
|
+
scan:
|
|
143
|
+
runs-on: ubuntu-latest
|
|
144
|
+
steps:
|
|
145
|
+
- uses: actions/checkout@v7
|
|
146
|
+
with:
|
|
147
|
+
persist-credentials: false
|
|
148
|
+
|
|
149
|
+
- uses: eCaleb/flutter-security-analyzer@v1.1.0
|
|
150
|
+
with:
|
|
151
|
+
path: .
|
|
152
|
+
fail-on: high
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
For supply-chain safety, pin the action to a full commit SHA rather than a tag. The scanner is installed from the action's own code, so the pin fixes the scanner version too.
|
|
156
|
+
|
|
157
|
+
| Input | Default | Description |
|
|
158
|
+
|---|---|---|
|
|
159
|
+
| `path` | `.` | Flutter project directory or Dart file to scan, relative to the repository root |
|
|
160
|
+
| `severity` | `low` | Lowest severity to report: `critical`, `high`, `medium`, `low` or `info` |
|
|
161
|
+
| `masvs-categories` | all | Space-separated MASVS categories, for example `STORAGE CRYPTO` |
|
|
162
|
+
| `config` | none | Path to a scanner configuration file |
|
|
163
|
+
| `sarif-file` | `flutter-security-analyzer.sarif` | Where to write the SARIF report |
|
|
164
|
+
| `upload-sarif` | `true` | Upload the report to code scanning. Needs `security-events: write` |
|
|
165
|
+
| `category` | `flutter-security-analyzer` | Code scanning category. Use a different one for each path if you scan several |
|
|
166
|
+
| `fail-on` | `high` | Fail the step when findings at or above this severity are reported, or `never`. Checked after the upload |
|
|
167
|
+
|
|
168
|
+
| Output | Description |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `sarif-file` | Path to the SARIF report |
|
|
171
|
+
| `findings` | Total number of findings |
|
|
172
|
+
| `critical`, `high` | Number of critical and high findings |
|
|
173
|
+
|
|
174
|
+
Code scanning is free for public repositories. Private repositories need GitHub Code Security. To use the report elsewhere without uploading it, set `upload-sarif: 'false'` and keep the file as an artifact.
|
|
175
|
+
|
|
176
|
+
### Other CI systems
|
|
123
177
|
|
|
124
178
|
```yaml
|
|
125
179
|
- name: Security Scan
|
|
@@ -171,11 +225,13 @@ flutter-security-analyzer/
|
|
|
171
225
|
│ └── reporters/
|
|
172
226
|
│ ├── console_reporter.py
|
|
173
227
|
│ ├── json_reporter.py
|
|
174
|
-
│
|
|
228
|
+
│ ├── html_reporter.py
|
|
229
|
+
│ └── sarif_reporter.py # SARIF 2.1.0 for code scanning
|
|
175
230
|
├── tests/
|
|
176
231
|
├── docs/images/ # README screenshots
|
|
177
232
|
├── samples/ # Deliberately vulnerable and secure sample apps
|
|
178
233
|
├── .github/workflows/
|
|
234
|
+
├── action.yml # GitHub Action
|
|
179
235
|
├── Dockerfile
|
|
180
236
|
├── pyproject.toml
|
|
181
237
|
├── requirements.txt
|
|
@@ -22,6 +22,7 @@ from flutter_security_analyzer.core.config import ScannerConfig
|
|
|
22
22
|
from flutter_security_analyzer.reporters.console_reporter import ConsoleReporter
|
|
23
23
|
from flutter_security_analyzer.reporters.json_reporter import JsonReporter
|
|
24
24
|
from flutter_security_analyzer.reporters.html_reporter import HtmlReporter
|
|
25
|
+
from flutter_security_analyzer.reporters.sarif_reporter import SarifReporter
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
def parse_arguments() -> argparse.Namespace:
|
|
@@ -48,7 +49,7 @@ def parse_arguments() -> argparse.Namespace:
|
|
|
48
49
|
parser.add_argument(
|
|
49
50
|
'-f', '--format',
|
|
50
51
|
type=str,
|
|
51
|
-
choices=['console', 'json', 'html'],
|
|
52
|
+
choices=['console', 'json', 'html', 'sarif'],
|
|
52
53
|
default='console',
|
|
53
54
|
help='Output format (default: console)'
|
|
54
55
|
)
|
|
@@ -97,7 +98,8 @@ def create_reporter(format_type: str, output_path: Optional[str]):
|
|
|
97
98
|
reporters = {
|
|
98
99
|
'console': ConsoleReporter,
|
|
99
100
|
'json': JsonReporter,
|
|
100
|
-
'html': HtmlReporter
|
|
101
|
+
'html': HtmlReporter,
|
|
102
|
+
'sarif': SarifReporter
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
reporter_class = reporters.get(format_type, ConsoleReporter)
|
|
@@ -7,5 +7,6 @@ Contains output formatters for scan results.
|
|
|
7
7
|
from .console_reporter import ConsoleReporter
|
|
8
8
|
from .json_reporter import JsonReporter
|
|
9
9
|
from .html_reporter import HtmlReporter
|
|
10
|
+
from .sarif_reporter import SarifReporter
|
|
10
11
|
|
|
11
|
-
__all__ = ['ConsoleReporter', 'JsonReporter', 'HtmlReporter']
|
|
12
|
+
__all__ = ['ConsoleReporter', 'JsonReporter', 'HtmlReporter', 'SarifReporter']
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""
|
|
2
|
+
SARIF Reporter Module
|
|
3
|
+
|
|
4
|
+
Outputs scan results in SARIF 2.1.0, the format GitHub code scanning and
|
|
5
|
+
most security dashboards read. Uploaded to GitHub, each finding appears in
|
|
6
|
+
the repository's Security tab and as an annotation on the affected line in
|
|
7
|
+
pull requests.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import json
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path, PurePath
|
|
15
|
+
from typing import Dict, List, Optional
|
|
16
|
+
from urllib.parse import quote
|
|
17
|
+
|
|
18
|
+
from flutter_security_analyzer.core.scanner import Finding, ScanResults
|
|
19
|
+
from flutter_security_analyzer.patterns.pattern_registry import PatternRegistry
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
SARIF_SCHEMA = 'https://json.schemastore.org/sarif-2.1.0.json'
|
|
23
|
+
SARIF_VERSION = '2.1.0'
|
|
24
|
+
TOOL_NAME = 'Flutter Security Analyzer'
|
|
25
|
+
INFORMATION_URI = 'https://github.com/eCaleb/flutter-security-analyzer'
|
|
26
|
+
MASVS_URI = 'https://mas.owasp.org/MASVS/'
|
|
27
|
+
|
|
28
|
+
# SARIF result levels for each scanner severity
|
|
29
|
+
LEVELS = {
|
|
30
|
+
'critical': 'error',
|
|
31
|
+
'high': 'error',
|
|
32
|
+
'medium': 'warning',
|
|
33
|
+
'low': 'note',
|
|
34
|
+
'info': 'note',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# GitHub turns this score into the severity shown on an alert:
|
|
38
|
+
# 9.0 and above is critical, 7.0 to 8.9 high, 4.0 to 6.9 medium, below 4.0 low
|
|
39
|
+
SECURITY_SEVERITY = {
|
|
40
|
+
'critical': '9.5',
|
|
41
|
+
'high': '8.0',
|
|
42
|
+
'medium': '5.5',
|
|
43
|
+
'low': '3.0',
|
|
44
|
+
'info': '1.0',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class SarifReporter:
|
|
49
|
+
"""
|
|
50
|
+
Reporter that outputs findings as a SARIF 2.1.0 log.
|
|
51
|
+
|
|
52
|
+
Every rule the scanner knows is listed, so an alert can always show the
|
|
53
|
+
rule's description and remediation, even for rules with no findings.
|
|
54
|
+
File paths are written relative to the current directory where possible,
|
|
55
|
+
which in GitHub Actions is the repository root that code scanning expects.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(self, output_path: Optional[str] = None):
|
|
59
|
+
"""
|
|
60
|
+
Initialize the SARIF reporter.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
output_path: If provided, output will be written to this file
|
|
64
|
+
"""
|
|
65
|
+
self.output_path = output_path
|
|
66
|
+
self.pattern_registry = PatternRegistry()
|
|
67
|
+
|
|
68
|
+
def generate(self, results: ScanResults):
|
|
69
|
+
"""
|
|
70
|
+
Generate the SARIF report.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
results: ScanResults object containing findings
|
|
74
|
+
"""
|
|
75
|
+
sarif_output = json.dumps(self.build_log(results), indent=2)
|
|
76
|
+
|
|
77
|
+
if self.output_path:
|
|
78
|
+
self._write_to_file(sarif_output)
|
|
79
|
+
else:
|
|
80
|
+
print(sarif_output)
|
|
81
|
+
|
|
82
|
+
def build_log(self, results: ScanResults) -> dict:
|
|
83
|
+
"""Build the SARIF log as a dictionary."""
|
|
84
|
+
rules = self._build_rules(results.findings)
|
|
85
|
+
rule_index = {rule['id']: index for index, rule in enumerate(rules)}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
'$schema': SARIF_SCHEMA,
|
|
89
|
+
'version': SARIF_VERSION,
|
|
90
|
+
'runs': [
|
|
91
|
+
{
|
|
92
|
+
'tool': {
|
|
93
|
+
'driver': {
|
|
94
|
+
'name': TOOL_NAME,
|
|
95
|
+
'version': results.scanner_version,
|
|
96
|
+
'semanticVersion': results.scanner_version,
|
|
97
|
+
'informationUri': INFORMATION_URI,
|
|
98
|
+
'rules': rules,
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
'invocations': [{'executionSuccessful': True}],
|
|
102
|
+
'results': [
|
|
103
|
+
self._build_result(finding, rule_index[finding.vulnerability_id])
|
|
104
|
+
for finding in results.findings
|
|
105
|
+
],
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
def _build_rules(self, findings: List[Finding]) -> List[dict]:
|
|
111
|
+
"""Describe every registered rule, plus any found only by project checks."""
|
|
112
|
+
rules: Dict[str, dict] = {}
|
|
113
|
+
|
|
114
|
+
for pattern in self.pattern_registry.get_all_patterns():
|
|
115
|
+
rules[pattern.vulnerability_id] = self._build_rule(
|
|
116
|
+
rule_id=pattern.vulnerability_id,
|
|
117
|
+
title=pattern.title,
|
|
118
|
+
description=pattern.description,
|
|
119
|
+
severity=pattern.severity,
|
|
120
|
+
masvs_category=pattern.masvs_category,
|
|
121
|
+
masvs_control=pattern.masvs_control,
|
|
122
|
+
remediation=pattern.remediation,
|
|
123
|
+
cwe_id=pattern.cwe_id,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
for finding in findings:
|
|
127
|
+
if finding.vulnerability_id not in rules:
|
|
128
|
+
rules[finding.vulnerability_id] = self._build_rule(
|
|
129
|
+
rule_id=finding.vulnerability_id,
|
|
130
|
+
title=finding.title,
|
|
131
|
+
description=finding.description,
|
|
132
|
+
severity=finding.severity,
|
|
133
|
+
masvs_category=finding.masvs_category,
|
|
134
|
+
masvs_control=finding.masvs_control,
|
|
135
|
+
remediation=finding.remediation,
|
|
136
|
+
cwe_id=finding.cwe_id,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
return [rules[rule_id] for rule_id in sorted(rules)]
|
|
140
|
+
|
|
141
|
+
def _build_rule(self, rule_id: str, title: str, description: str, severity: str,
|
|
142
|
+
masvs_category: str, masvs_control: str, remediation: str,
|
|
143
|
+
cwe_id: str) -> dict:
|
|
144
|
+
"""Build one SARIF reportingDescriptor."""
|
|
145
|
+
category = masvs_category if masvs_category.startswith('MASVS-') else f'MASVS-{masvs_category}'
|
|
146
|
+
tags = ['security', category]
|
|
147
|
+
cwe_number = self._cwe_number(cwe_id)
|
|
148
|
+
if cwe_number:
|
|
149
|
+
tags.append(f'external/cwe/cwe-{cwe_number}')
|
|
150
|
+
|
|
151
|
+
help_text = f'{remediation}\n\nOWASP MASVS: {masvs_control}.'
|
|
152
|
+
help_markdown = f'{remediation}\n\nOWASP MASVS: [{masvs_control}]({MASVS_URI})'
|
|
153
|
+
if cwe_number:
|
|
154
|
+
cwe_uri = f'https://cwe.mitre.org/data/definitions/{cwe_number}.html'
|
|
155
|
+
help_text += f' {cwe_id}.'
|
|
156
|
+
help_markdown += f', [{cwe_id}]({cwe_uri})'
|
|
157
|
+
|
|
158
|
+
rule = {
|
|
159
|
+
'id': rule_id,
|
|
160
|
+
'name': self._rule_name(title),
|
|
161
|
+
'shortDescription': {'text': title},
|
|
162
|
+
'fullDescription': {'text': description},
|
|
163
|
+
'help': {'text': help_text, 'markdown': help_markdown},
|
|
164
|
+
'helpUri': f'https://cwe.mitre.org/data/definitions/{cwe_number}.html' if cwe_number else MASVS_URI,
|
|
165
|
+
'defaultConfiguration': {'level': LEVELS.get(severity, 'warning')},
|
|
166
|
+
'properties': {
|
|
167
|
+
'tags': tags,
|
|
168
|
+
'security-severity': SECURITY_SEVERITY.get(severity, '5.5'),
|
|
169
|
+
'masvs-control': masvs_control,
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
return rule
|
|
173
|
+
|
|
174
|
+
def _build_result(self, finding: Finding, rule_index: int) -> dict:
|
|
175
|
+
"""Build one SARIF result."""
|
|
176
|
+
uri, is_relative = self._artifact_uri(finding.file_path)
|
|
177
|
+
artifact_location = {'uri': uri}
|
|
178
|
+
if is_relative:
|
|
179
|
+
artifact_location['uriBaseId'] = '%SRCROOT%'
|
|
180
|
+
|
|
181
|
+
region = {'startLine': max(1, int(finding.line_number or 1))}
|
|
182
|
+
snippet = (finding.code_snippet or '').strip()
|
|
183
|
+
if snippet:
|
|
184
|
+
region['snippet'] = {'text': snippet}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
'ruleId': finding.vulnerability_id,
|
|
188
|
+
'ruleIndex': rule_index,
|
|
189
|
+
'level': LEVELS.get(finding.severity, 'warning'),
|
|
190
|
+
'message': {'text': f'{finding.title}: {finding.description}'},
|
|
191
|
+
'locations': [
|
|
192
|
+
{
|
|
193
|
+
'physicalLocation': {
|
|
194
|
+
'artifactLocation': artifact_location,
|
|
195
|
+
'region': region,
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
'partialFingerprints': {
|
|
200
|
+
'flutterSecurityAnalyzer/v1': self._fingerprint(finding, uri, snippet),
|
|
201
|
+
},
|
|
202
|
+
'properties': {
|
|
203
|
+
'severity': finding.severity,
|
|
204
|
+
'confidence': finding.confidence,
|
|
205
|
+
'masvs-category': finding.masvs_category,
|
|
206
|
+
'masvs-control': finding.masvs_control,
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@staticmethod
|
|
211
|
+
def _artifact_uri(file_path: str):
|
|
212
|
+
"""
|
|
213
|
+
Return the file's URI and whether it is relative.
|
|
214
|
+
|
|
215
|
+
Paths under the current directory become relative URIs with forward
|
|
216
|
+
slashes, as code scanning expects. Anything else becomes a file:// URI.
|
|
217
|
+
"""
|
|
218
|
+
absolute = Path(file_path).resolve()
|
|
219
|
+
try:
|
|
220
|
+
relative = absolute.relative_to(Path.cwd().resolve())
|
|
221
|
+
return quote(PurePath(relative).as_posix()), True
|
|
222
|
+
except ValueError:
|
|
223
|
+
return absolute.as_uri(), False
|
|
224
|
+
|
|
225
|
+
@staticmethod
|
|
226
|
+
def _fingerprint(finding: Finding, uri: str, snippet: str) -> str:
|
|
227
|
+
"""
|
|
228
|
+
Identify a finding without its line number, so an alert keeps its
|
|
229
|
+
identity when code above it moves.
|
|
230
|
+
"""
|
|
231
|
+
normalised = re.sub(r'\s+', ' ', snippet)
|
|
232
|
+
key = '|'.join([finding.vulnerability_id, uri, normalised])
|
|
233
|
+
return hashlib.sha256(key.encode('utf-8')).hexdigest()
|
|
234
|
+
|
|
235
|
+
@staticmethod
|
|
236
|
+
def _rule_name(title: str) -> str:
|
|
237
|
+
"""Turn a rule title into a PascalCase name, e.g. HardcodedAPIKeysSecrets."""
|
|
238
|
+
words = re.findall(r'[A-Za-z0-9]+', title)
|
|
239
|
+
return ''.join(word[:1].upper() + word[1:] for word in words)
|
|
240
|
+
|
|
241
|
+
@staticmethod
|
|
242
|
+
def _cwe_number(cwe_id: str) -> str:
|
|
243
|
+
"""Return the number from an id such as CWE-798, or an empty string."""
|
|
244
|
+
match = re.search(r'(\d+)', cwe_id or '')
|
|
245
|
+
return match.group(1) if match else ''
|
|
246
|
+
|
|
247
|
+
def _write_to_file(self, sarif_output: str):
|
|
248
|
+
"""Write SARIF output to file."""
|
|
249
|
+
try:
|
|
250
|
+
with open(self.output_path, 'w', encoding='utf-8') as f:
|
|
251
|
+
f.write(sarif_output)
|
|
252
|
+
except IOError as e:
|
|
253
|
+
print(f"Error writing to file: {e}", file=sys.stderr)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flutter-security-analyzer
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Static security analysis tool for Flutter/Dart applications with MASVS compliance mapping
|
|
5
5
|
Author-email: Caleb Elebhose <elebhosec@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -48,8 +48,8 @@ This tool is developed as part of an MSc Cybersecurity final year project at the
|
|
|
48
48
|
|
|
49
49
|
- **Pattern-Based Detection**: Regex-based vulnerability detection for Dart code
|
|
50
50
|
- **MASVS Compliance Mapping**: All findings mapped to OWASP MASVS v2.1.0 controls
|
|
51
|
-
- **Multiple Output Formats**: Console, JSON, and
|
|
52
|
-
- **CI/CD Integration**: Exit codes
|
|
51
|
+
- **Multiple Output Formats**: Console, JSON, HTML and SARIF reports
|
|
52
|
+
- **CI/CD Integration**: Exit codes for pipelines, and a GitHub Action that puts findings in GitHub code scanning
|
|
53
53
|
- **26 Vulnerability Checks**: Covering all 8 MASVS categories
|
|
54
54
|
|
|
55
55
|
## Sample Report
|
|
@@ -120,6 +120,9 @@ flutter-security-analyzer ./my_flutter_app -f json -o results.json
|
|
|
120
120
|
|
|
121
121
|
# HTML report
|
|
122
122
|
flutter-security-analyzer ./my_flutter_app -f html -o report.html
|
|
123
|
+
|
|
124
|
+
# SARIF 2.1.0, for GitHub code scanning and other security dashboards
|
|
125
|
+
flutter-security-analyzer ./my_flutter_app -f sarif -o results.sarif
|
|
123
126
|
```
|
|
124
127
|
|
|
125
128
|
### Filter by Severity
|
|
@@ -150,7 +153,58 @@ flutter-security-analyzer ./my_flutter_app -v
|
|
|
150
153
|
- `1`: High severity findings detected
|
|
151
154
|
- `2`: Critical findings detected
|
|
152
155
|
|
|
153
|
-
### GitHub
|
|
156
|
+
### GitHub Action
|
|
157
|
+
|
|
158
|
+
The repository is also a GitHub Action. It scans your project and uploads the findings to GitHub code scanning, so they appear in the Security tab and on the affected lines of pull requests.
|
|
159
|
+
|
|
160
|
+
```yaml
|
|
161
|
+
name: Flutter security scan
|
|
162
|
+
|
|
163
|
+
on:
|
|
164
|
+
push:
|
|
165
|
+
branches: [main]
|
|
166
|
+
pull_request:
|
|
167
|
+
|
|
168
|
+
permissions:
|
|
169
|
+
contents: read
|
|
170
|
+
security-events: write # needed to upload results to code scanning
|
|
171
|
+
|
|
172
|
+
jobs:
|
|
173
|
+
scan:
|
|
174
|
+
runs-on: ubuntu-latest
|
|
175
|
+
steps:
|
|
176
|
+
- uses: actions/checkout@v7
|
|
177
|
+
with:
|
|
178
|
+
persist-credentials: false
|
|
179
|
+
|
|
180
|
+
- uses: eCaleb/flutter-security-analyzer@v1.1.0
|
|
181
|
+
with:
|
|
182
|
+
path: .
|
|
183
|
+
fail-on: high
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
For supply-chain safety, pin the action to a full commit SHA rather than a tag. The scanner is installed from the action's own code, so the pin fixes the scanner version too.
|
|
187
|
+
|
|
188
|
+
| Input | Default | Description |
|
|
189
|
+
|---|---|---|
|
|
190
|
+
| `path` | `.` | Flutter project directory or Dart file to scan, relative to the repository root |
|
|
191
|
+
| `severity` | `low` | Lowest severity to report: `critical`, `high`, `medium`, `low` or `info` |
|
|
192
|
+
| `masvs-categories` | all | Space-separated MASVS categories, for example `STORAGE CRYPTO` |
|
|
193
|
+
| `config` | none | Path to a scanner configuration file |
|
|
194
|
+
| `sarif-file` | `flutter-security-analyzer.sarif` | Where to write the SARIF report |
|
|
195
|
+
| `upload-sarif` | `true` | Upload the report to code scanning. Needs `security-events: write` |
|
|
196
|
+
| `category` | `flutter-security-analyzer` | Code scanning category. Use a different one for each path if you scan several |
|
|
197
|
+
| `fail-on` | `high` | Fail the step when findings at or above this severity are reported, or `never`. Checked after the upload |
|
|
198
|
+
|
|
199
|
+
| Output | Description |
|
|
200
|
+
|---|---|
|
|
201
|
+
| `sarif-file` | Path to the SARIF report |
|
|
202
|
+
| `findings` | Total number of findings |
|
|
203
|
+
| `critical`, `high` | Number of critical and high findings |
|
|
204
|
+
|
|
205
|
+
Code scanning is free for public repositories. Private repositories need GitHub Code Security. To use the report elsewhere without uploading it, set `upload-sarif: 'false'` and keep the file as an artifact.
|
|
206
|
+
|
|
207
|
+
### Other CI systems
|
|
154
208
|
|
|
155
209
|
```yaml
|
|
156
210
|
- name: Security Scan
|
|
@@ -202,11 +256,13 @@ flutter-security-analyzer/
|
|
|
202
256
|
│ └── reporters/
|
|
203
257
|
│ ├── console_reporter.py
|
|
204
258
|
│ ├── json_reporter.py
|
|
205
|
-
│
|
|
259
|
+
│ ├── html_reporter.py
|
|
260
|
+
│ └── sarif_reporter.py # SARIF 2.1.0 for code scanning
|
|
206
261
|
├── tests/
|
|
207
262
|
├── docs/images/ # README screenshots
|
|
208
263
|
├── samples/ # Deliberately vulnerable and secure sample apps
|
|
209
264
|
├── .github/workflows/
|
|
265
|
+
├── action.yml # GitHub Action
|
|
210
266
|
├── Dockerfile
|
|
211
267
|
├── pyproject.toml
|
|
212
268
|
├── requirements.txt
|
|
@@ -30,6 +30,8 @@ src/flutter_security_analyzer/reporters/__init__.py
|
|
|
30
30
|
src/flutter_security_analyzer/reporters/console_reporter.py
|
|
31
31
|
src/flutter_security_analyzer/reporters/html_reporter.py
|
|
32
32
|
src/flutter_security_analyzer/reporters/json_reporter.py
|
|
33
|
+
src/flutter_security_analyzer/reporters/sarif_reporter.py
|
|
33
34
|
src/flutter_security_analyzer/utils/__init__.py
|
|
34
35
|
tests/test_config_scanning.py
|
|
36
|
+
tests/test_sarif_reporter.py
|
|
35
37
|
tests/test_scanner.py
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for the SARIF reporter.
|
|
3
|
+
|
|
4
|
+
GitHub code scanning rejects or misplaces results when the SARIF log breaks
|
|
5
|
+
its rules, so these tests check the parts it relies on: one rule per id, a
|
|
6
|
+
ruleIndex that points at the right rule, valid levels, a security-severity
|
|
7
|
+
score in the right band, line numbers of 1 or more, and file paths written
|
|
8
|
+
relative to the repository root with forward slashes.
|
|
9
|
+
|
|
10
|
+
Author: Caleb Elebhose
|
|
11
|
+
Module: WB7103/WB7104 MSc Cybersecurity Project
|
|
12
|
+
University of Chester
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import shutil
|
|
18
|
+
import subprocess
|
|
19
|
+
import sys
|
|
20
|
+
import tempfile
|
|
21
|
+
import unittest
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
REPO_ROOT = Path(__file__).resolve().parent.parent
|
|
25
|
+
sys.path.insert(0, str(REPO_ROOT / 'src'))
|
|
26
|
+
|
|
27
|
+
from flutter_security_analyzer import __version__ # noqa: E402
|
|
28
|
+
from flutter_security_analyzer.core.config import ScannerConfig # noqa: E402
|
|
29
|
+
from flutter_security_analyzer.core.scanner import SecurityScanner # noqa: E402
|
|
30
|
+
from flutter_security_analyzer.reporters.sarif_reporter import SarifReporter # noqa: E402
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
SAMPLES = REPO_ROOT / 'samples'
|
|
34
|
+
LEVELS = {'critical': 'error', 'high': 'error', 'medium': 'warning', 'low': 'note', 'info': 'note'}
|
|
35
|
+
SEVERITY_BANDS = {
|
|
36
|
+
'critical': (9.0, 10.0),
|
|
37
|
+
'high': (7.0, 8.9),
|
|
38
|
+
'medium': (4.0, 6.9),
|
|
39
|
+
'low': (0.1, 3.9),
|
|
40
|
+
'info': (0.1, 3.9),
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def build_log(path):
|
|
45
|
+
"""Scan a path and return the SARIF log as a dictionary."""
|
|
46
|
+
results = SecurityScanner(ScannerConfig()).scan(Path(path))
|
|
47
|
+
return results, SarifReporter().build_log(results)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class TestSarifStructure(unittest.TestCase):
|
|
51
|
+
"""Checks on a scan of the sample apps, run from the repository root."""
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def setUpClass(cls):
|
|
55
|
+
cls._old_cwd = os.getcwd()
|
|
56
|
+
os.chdir(REPO_ROOT)
|
|
57
|
+
cls.results, cls.log = build_log('samples')
|
|
58
|
+
cls.sarif_run = cls.log['runs'][0]
|
|
59
|
+
cls.rules = cls.sarif_run['tool']['driver']['rules']
|
|
60
|
+
|
|
61
|
+
@classmethod
|
|
62
|
+
def tearDownClass(cls):
|
|
63
|
+
os.chdir(cls._old_cwd)
|
|
64
|
+
|
|
65
|
+
def test_top_level_fields(self):
|
|
66
|
+
self.assertEqual(self.log['version'], '2.1.0')
|
|
67
|
+
self.assertIn('sarif-2.1.0', self.log['$schema'])
|
|
68
|
+
self.assertEqual(len(self.log['runs']), 1)
|
|
69
|
+
|
|
70
|
+
def test_driver_reports_the_package_version(self):
|
|
71
|
+
driver = self.sarif_run['tool']['driver']
|
|
72
|
+
self.assertEqual(driver['name'], 'Flutter Security Analyzer')
|
|
73
|
+
self.assertEqual(driver['version'], __version__)
|
|
74
|
+
self.assertEqual(driver['semanticVersion'], __version__)
|
|
75
|
+
|
|
76
|
+
def test_rule_ids_are_unique(self):
|
|
77
|
+
ids = [rule['id'] for rule in self.rules]
|
|
78
|
+
self.assertEqual(len(ids), len(set(ids)))
|
|
79
|
+
self.assertGreaterEqual(len(ids), 25)
|
|
80
|
+
|
|
81
|
+
def test_rules_have_text_and_severity(self):
|
|
82
|
+
for rule in self.rules:
|
|
83
|
+
with self.subTest(rule=rule['id']):
|
|
84
|
+
self.assertTrue(rule['shortDescription']['text'])
|
|
85
|
+
self.assertTrue(rule['fullDescription']['text'])
|
|
86
|
+
self.assertTrue(rule['help']['text'])
|
|
87
|
+
self.assertIn('security', rule['properties']['tags'])
|
|
88
|
+
self.assertTrue(rule['name'].isalnum())
|
|
89
|
+
float(rule['properties']['security-severity'])
|
|
90
|
+
|
|
91
|
+
def test_one_result_per_finding(self):
|
|
92
|
+
self.assertEqual(len(self.sarif_run['results']), len(self.results.findings))
|
|
93
|
+
self.assertGreater(len(self.sarif_run['results']), 0)
|
|
94
|
+
|
|
95
|
+
def test_rule_index_points_at_the_rule(self):
|
|
96
|
+
for result in self.sarif_run['results']:
|
|
97
|
+
self.assertEqual(self.rules[result['ruleIndex']]['id'], result['ruleId'])
|
|
98
|
+
|
|
99
|
+
def test_levels_match_severity(self):
|
|
100
|
+
for result in self.sarif_run['results']:
|
|
101
|
+
severity = result['properties']['severity']
|
|
102
|
+
self.assertEqual(result['level'], LEVELS[severity])
|
|
103
|
+
|
|
104
|
+
def test_security_severity_falls_in_githubs_band(self):
|
|
105
|
+
for result in self.sarif_run['results']:
|
|
106
|
+
rule = self.rules[result['ruleIndex']]
|
|
107
|
+
score = float(rule['properties']['security-severity'])
|
|
108
|
+
low, high = SEVERITY_BANDS[result['properties']['severity']]
|
|
109
|
+
self.assertTrue(low <= score <= high, f"{rule['id']} scored {score}")
|
|
110
|
+
|
|
111
|
+
def test_locations_are_relative_with_forward_slashes(self):
|
|
112
|
+
for result in self.sarif_run['results']:
|
|
113
|
+
location = result['locations'][0]['physicalLocation']
|
|
114
|
+
uri = location['artifactLocation']['uri']
|
|
115
|
+
self.assertEqual(location['artifactLocation']['uriBaseId'], '%SRCROOT%')
|
|
116
|
+
self.assertTrue(uri.startswith('samples/'), uri)
|
|
117
|
+
self.assertNotIn('\\', uri)
|
|
118
|
+
self.assertGreaterEqual(location['region']['startLine'], 1)
|
|
119
|
+
|
|
120
|
+
def test_fingerprints_ignore_line_numbers(self):
|
|
121
|
+
for result in self.sarif_run['results']:
|
|
122
|
+
fingerprint = result['partialFingerprints']['flutterSecurityAnalyzer/v1']
|
|
123
|
+
self.assertEqual(len(fingerprint), 64)
|
|
124
|
+
|
|
125
|
+
def test_log_is_json_serialisable(self):
|
|
126
|
+
json.loads(json.dumps(self.log))
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class TestSarifPaths(unittest.TestCase):
|
|
130
|
+
"""File paths in unusual places."""
|
|
131
|
+
|
|
132
|
+
def setUp(self):
|
|
133
|
+
self._old_cwd = os.getcwd()
|
|
134
|
+
self.temp_dir = tempfile.mkdtemp()
|
|
135
|
+
project = Path(self.temp_dir) / 'my app' / 'lib'
|
|
136
|
+
project.mkdir(parents=True)
|
|
137
|
+
shutil.copy(SAMPLES / 'vulnerable_app.dart', project / 'main.dart')
|
|
138
|
+
|
|
139
|
+
def tearDown(self):
|
|
140
|
+
os.chdir(self._old_cwd)
|
|
141
|
+
shutil.rmtree(self.temp_dir, ignore_errors=True)
|
|
142
|
+
|
|
143
|
+
def test_spaces_are_percent_encoded(self):
|
|
144
|
+
os.chdir(self.temp_dir)
|
|
145
|
+
_, log = build_log('my app')
|
|
146
|
+
uris = {r['locations'][0]['physicalLocation']['artifactLocation']['uri']
|
|
147
|
+
for r in log['runs'][0]['results']}
|
|
148
|
+
self.assertEqual(uris, {'my%20app/lib/main.dart'})
|
|
149
|
+
|
|
150
|
+
def test_paths_outside_the_current_directory_become_file_uris(self):
|
|
151
|
+
os.chdir(REPO_ROOT)
|
|
152
|
+
_, log = build_log(Path(self.temp_dir) / 'my app')
|
|
153
|
+
location = log['runs'][0]['results'][0]['locations'][0]['physicalLocation']
|
|
154
|
+
self.assertTrue(location['artifactLocation']['uri'].startswith('file://'))
|
|
155
|
+
self.assertNotIn('uriBaseId', location['artifactLocation'])
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class TestSarifEmptyScan(unittest.TestCase):
|
|
159
|
+
"""A clean project still produces a valid log with the rule list."""
|
|
160
|
+
|
|
161
|
+
def test_no_findings(self):
|
|
162
|
+
temp_dir = tempfile.mkdtemp()
|
|
163
|
+
try:
|
|
164
|
+
Path(temp_dir, 'main.dart').write_text("void main() {}\n", encoding='utf-8')
|
|
165
|
+
_, log = build_log(temp_dir)
|
|
166
|
+
run = log['runs'][0]
|
|
167
|
+
self.assertEqual(run['results'], [])
|
|
168
|
+
self.assertGreaterEqual(len(run['tool']['driver']['rules']), 25)
|
|
169
|
+
finally:
|
|
170
|
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class TestSarifCommandLine(unittest.TestCase):
|
|
174
|
+
"""The -f sarif option writes a file and keeps the usual exit codes."""
|
|
175
|
+
|
|
176
|
+
def test_cli_writes_sarif(self):
|
|
177
|
+
temp_dir = tempfile.mkdtemp()
|
|
178
|
+
try:
|
|
179
|
+
output = Path(temp_dir) / 'results.sarif'
|
|
180
|
+
env = dict(os.environ, PYTHONPATH=str(REPO_ROOT / 'src'))
|
|
181
|
+
completed = subprocess.run(
|
|
182
|
+
[sys.executable, '-m', 'flutter_security_analyzer',
|
|
183
|
+
str(SAMPLES / 'vulnerable_app.dart'), '-f', 'sarif', '-o', str(output)],
|
|
184
|
+
env=env, capture_output=True, text=True, check=False,
|
|
185
|
+
)
|
|
186
|
+
self.assertEqual(completed.returncode, 2, completed.stderr)
|
|
187
|
+
log = json.loads(output.read_text(encoding='utf-8'))
|
|
188
|
+
self.assertEqual(log['version'], '2.1.0')
|
|
189
|
+
self.assertGreater(len(log['runs'][0]['results']), 0)
|
|
190
|
+
finally:
|
|
191
|
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if __name__ == '__main__':
|
|
195
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flutter_security_analyzer-1.0.1 → flutter_security_analyzer-1.1.0}/tests/test_config_scanning.py
RENAMED
|
File without changes
|
|
File without changes
|