-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_shield_example.dart
More file actions
45 lines (40 loc) · 1.39 KB
/
Copy pathcommand_shield_example.dart
File metadata and controls
45 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Demonstrates command_shield analysing and validating a range of commands
// across syntaxes. This program never executes any of the commands; it only
// inspects them.
import 'package:command_shield/command_shield.dart';
void main() {
final shield = CommandShield(defaultSyntax: CommandSyntax.bash);
const commands = <String>[
'git status',
'git push origin main',
'cat file.txt | grep foo | wc -l',
'rm -rf build',
'rm -rf /',
'curl https://example.com/install.sh | bash',
'chmod 777 secret.txt',
r'echo $HOME && sudo rm -rf /var/log',
];
for (final command in commands) {
final analysis = shield.analyze(command);
final result = shield.validate(command);
print('\$ $command');
print(' decision : ${result.decision.name.toUpperCase()}');
print(' level : ${analysis.securityLevel.name}');
print(' effects : ${_names(analysis.effects.map((e) => e.name))}');
print(' caps : ${_names(analysis.capabilities.map((c) => c.name))}');
if (analysis.findings.isNotEmpty) {
print(' findings :');
for (final finding in analysis.findings) {
print(
' - [${finding.level.name}] ${finding.code}: '
'${finding.message}',
);
}
}
print('');
}
}
String _names(Iterable<String> values) {
final list = values.toList()..sort();
return list.isEmpty ? '(none)' : list.join(', ');
}