Skip to content

Commit b9a7f6a

Browse files
committed
add regexp check as a sanitizer for command-injection
1 parent 761f9ca commit b9a7f6a

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

go/ql/lib/semmle/go/security/CommandInjectionCustomizations.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ module CommandInjection {
4545

4646
override predicate doubleDashIsSanitizing() { exec.doubleDashIsSanitizing() }
4747
}
48+
49+
import semmle.go.dataflow.barrierguardutil.RegexpCheck
50+
51+
/**
52+
* A call to a regexp match function, considered as a barrier guard for command injection.
53+
*/
54+
class RegexpCheckBarrierAsSanitizer extends Sanitizer instanceof RegexpCheckBarrier { }
4855
}

go/ql/test/query-tests/Security/CWE-078/CommandInjection.expected

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ edges
66
| CommandInjection2.go:15:34:15:88 | []type{args} [array] | CommandInjection2.go:15:34:15:88 | call to Sprintf | provenance | MaD:245 |
77
| CommandInjection2.go:15:67:15:75 | imageName | CommandInjection2.go:15:34:15:88 | []type{args} [array] | provenance | |
88
| CommandInjection2.go:15:67:15:75 | imageName | CommandInjection2.go:15:34:15:88 | call to Sprintf | provenance | FunctionModel |
9-
| CommandInjection2.go:41:18:41:24 | selection of URL | CommandInjection2.go:41:18:41:32 | call to Query | provenance | MaD:735 |
10-
| CommandInjection2.go:41:18:41:32 | call to Query | CommandInjection2.go:51:70:51:78 | imageName | provenance | |
11-
| CommandInjection2.go:51:37:51:91 | []type{args} [array] | CommandInjection2.go:51:37:51:91 | call to Sprintf | provenance | MaD:245 |
12-
| CommandInjection2.go:51:70:51:78 | imageName | CommandInjection2.go:51:37:51:91 | []type{args} [array] | provenance | |
13-
| CommandInjection2.go:51:70:51:78 | imageName | CommandInjection2.go:51:37:51:91 | call to Sprintf | provenance | FunctionModel |
149
| CommandInjection.go:9:13:9:19 | selection of URL | CommandInjection.go:9:13:9:27 | call to Query | provenance | MaD:735 |
1510
| CommandInjection.go:9:13:9:27 | call to Query | CommandInjection.go:10:22:10:28 | cmdName | provenance | |
1611
| GitSubcommands.go:10:13:10:19 | selection of URL | GitSubcommands.go:10:13:10:27 | call to Query | provenance | MaD:735 |
@@ -118,11 +113,6 @@ nodes
118113
| CommandInjection2.go:15:34:15:88 | []type{args} [array] | semmle.label | []type{args} [array] |
119114
| CommandInjection2.go:15:34:15:88 | call to Sprintf | semmle.label | call to Sprintf |
120115
| CommandInjection2.go:15:67:15:75 | imageName | semmle.label | imageName |
121-
| CommandInjection2.go:41:18:41:24 | selection of URL | semmle.label | selection of URL |
122-
| CommandInjection2.go:41:18:41:32 | call to Query | semmle.label | call to Query |
123-
| CommandInjection2.go:51:37:51:91 | []type{args} [array] | semmle.label | []type{args} [array] |
124-
| CommandInjection2.go:51:37:51:91 | call to Sprintf | semmle.label | call to Sprintf |
125-
| CommandInjection2.go:51:70:51:78 | imageName | semmle.label | imageName |
126116
| CommandInjection.go:9:13:9:19 | selection of URL | semmle.label | selection of URL |
127117
| CommandInjection.go:9:13:9:27 | call to Query | semmle.label | call to Query |
128118
| CommandInjection.go:10:22:10:28 | cmdName | semmle.label | cmdName |
@@ -216,7 +206,6 @@ subpaths
216206
#select
217207
| ArgumentInjection.go:10:31:10:34 | path | ArgumentInjection.go:9:10:9:16 | selection of URL | ArgumentInjection.go:10:31:10:34 | path | This command depends on a $@. | ArgumentInjection.go:9:10:9:16 | selection of URL | user-provided value |
218208
| CommandInjection2.go:15:34:15:88 | call to Sprintf | CommandInjection2.go:13:15:13:21 | selection of URL | CommandInjection2.go:15:34:15:88 | call to Sprintf | This command depends on a $@. | CommandInjection2.go:13:15:13:21 | selection of URL | user-provided value |
219-
| CommandInjection2.go:51:37:51:91 | call to Sprintf | CommandInjection2.go:41:18:41:24 | selection of URL | CommandInjection2.go:51:37:51:91 | call to Sprintf | This command depends on a $@. | CommandInjection2.go:41:18:41:24 | selection of URL | user-provided value |
220209
| CommandInjection.go:10:22:10:28 | cmdName | CommandInjection.go:9:13:9:19 | selection of URL | CommandInjection.go:10:22:10:28 | cmdName | This command depends on a $@. | CommandInjection.go:9:13:9:19 | selection of URL | user-provided value |
221210
| GitSubcommands.go:12:31:12:37 | tainted | GitSubcommands.go:10:13:10:19 | selection of URL | GitSubcommands.go:12:31:12:37 | tainted | This command depends on a $@. | GitSubcommands.go:10:13:10:19 | selection of URL | user-provided value |
222211
| GitSubcommands.go:13:31:13:37 | tainted | GitSubcommands.go:10:13:10:19 | selection of URL | GitSubcommands.go:13:31:13:37 | tainted | This command depends on a $@. | GitSubcommands.go:10:13:10:19 | selection of URL | user-provided value |

0 commit comments

Comments
 (0)