|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `regexp` package. |
| 3 | + */ |
| 4 | + |
| 5 | +import go |
| 6 | + |
| 7 | +/** Provides models of commonly used functions in the `regexp` package. */ |
| 8 | +module Regexp { |
| 9 | + private class FunctionModels extends TaintTracking::FunctionModel { |
| 10 | + FunctionInput inp; |
| 11 | + FunctionOutput outp; |
| 12 | + |
| 13 | + FunctionModels() { |
| 14 | + // signature: func QuoteMeta(s string) string |
| 15 | + hasQualifiedName("regexp", "QuoteMeta") and |
| 16 | + (inp.isParameter(0) and outp.isResult()) |
| 17 | + } |
| 18 | + |
| 19 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 20 | + input = inp and output = outp |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + private class MethodModels extends TaintTracking::FunctionModel, Method { |
| 25 | + FunctionInput inp; |
| 26 | + FunctionOutput outp; |
| 27 | + |
| 28 | + MethodModels() { |
| 29 | + // signature: func (*Regexp).Expand(dst []byte, template []byte, src []byte, match []int) []byte |
| 30 | + this.hasQualifiedName("regexp", "Regexp", "Expand") and |
| 31 | + ( |
| 32 | + inp.isParameter([1, 2]) and |
| 33 | + (outp.isParameter(0) or outp.isResult()) |
| 34 | + ) |
| 35 | + or |
| 36 | + // signature: func (*Regexp).ExpandString(dst []byte, template string, src string, match []int) []byte |
| 37 | + this.hasQualifiedName("regexp", "Regexp", "ExpandString") and |
| 38 | + ( |
| 39 | + inp.isParameter([1, 2]) and |
| 40 | + (outp.isParameter(0) or outp.isResult()) |
| 41 | + ) |
| 42 | + or |
| 43 | + // signature: func (*Regexp).Find(b []byte) []byte |
| 44 | + this.hasQualifiedName("regexp", "Regexp", "Find") and |
| 45 | + (inp.isParameter(0) and outp.isResult()) |
| 46 | + or |
| 47 | + // signature: func (*Regexp).FindAll(b []byte, n int) [][]byte |
| 48 | + this.hasQualifiedName("regexp", "Regexp", "FindAll") and |
| 49 | + (inp.isParameter(0) and outp.isResult()) |
| 50 | + or |
| 51 | + // signature: func (*Regexp).FindAllString(s string, n int) []string |
| 52 | + this.hasQualifiedName("regexp", "Regexp", "FindAllString") and |
| 53 | + (inp.isParameter(0) and outp.isResult()) |
| 54 | + or |
| 55 | + // signature: func (*Regexp).FindAllStringSubmatch(s string, n int) [][]string |
| 56 | + this.hasQualifiedName("regexp", "Regexp", "FindAllStringSubmatch") and |
| 57 | + (inp.isParameter(0) and outp.isResult()) |
| 58 | + or |
| 59 | + // signature: func (*Regexp).FindAllSubmatch(b []byte, n int) [][][]byte |
| 60 | + this.hasQualifiedName("regexp", "Regexp", "FindAllSubmatch") and |
| 61 | + (inp.isParameter(0) and outp.isResult()) |
| 62 | + or |
| 63 | + // signature: func (*Regexp).FindString(s string) string |
| 64 | + this.hasQualifiedName("regexp", "Regexp", "FindString") and |
| 65 | + (inp.isParameter(0) and outp.isResult()) |
| 66 | + or |
| 67 | + // signature: func (*Regexp).FindStringSubmatch(s string) []string |
| 68 | + this.hasQualifiedName("regexp", "Regexp", "FindStringSubmatch") and |
| 69 | + (inp.isParameter(0) and outp.isResult()) |
| 70 | + or |
| 71 | + // signature: func (*Regexp).FindSubmatch(b []byte) [][]byte |
| 72 | + this.hasQualifiedName("regexp", "Regexp", "FindSubmatch") and |
| 73 | + (inp.isParameter(0) and outp.isResult()) |
| 74 | + or |
| 75 | + // signature: func (*Regexp).ReplaceAll(src []byte, repl []byte) []byte |
| 76 | + this.hasQualifiedName("regexp", "Regexp", "ReplaceAll") and |
| 77 | + (inp.isParameter(_) and outp.isResult()) |
| 78 | + or |
| 79 | + // signature: func (*Regexp).ReplaceAllFunc(src []byte, repl func([]byte) []byte) []byte |
| 80 | + this.hasQualifiedName("regexp", "Regexp", "ReplaceAllFunc") and |
| 81 | + (inp.isParameter(_) and outp.isResult()) |
| 82 | + or |
| 83 | + // signature: func (*Regexp).ReplaceAllLiteral(src []byte, repl []byte) []byte |
| 84 | + this.hasQualifiedName("regexp", "Regexp", "ReplaceAllLiteral") and |
| 85 | + (inp.isParameter(_) and outp.isResult()) |
| 86 | + or |
| 87 | + // signature: func (*Regexp).ReplaceAllLiteralString(src string, repl string) string |
| 88 | + this.hasQualifiedName("regexp", "Regexp", "ReplaceAllLiteralString") and |
| 89 | + (inp.isParameter(_) and outp.isResult()) |
| 90 | + or |
| 91 | + // signature: func (*Regexp).ReplaceAllString(src string, repl string) string |
| 92 | + this.hasQualifiedName("regexp", "Regexp", "ReplaceAllString") and |
| 93 | + (inp.isParameter(_) and outp.isResult()) |
| 94 | + or |
| 95 | + // signature: func (*Regexp).ReplaceAllStringFunc(src string, repl func(string) string) string |
| 96 | + this.hasQualifiedName("regexp", "Regexp", "ReplaceAllStringFunc") and |
| 97 | + (inp.isParameter(_) and outp.isResult()) |
| 98 | + or |
| 99 | + // signature: func (*Regexp).Split(s string, n int) []string |
| 100 | + this.hasQualifiedName("regexp", "Regexp", "Split") and |
| 101 | + (inp.isParameter(0) and outp.isResult()) |
| 102 | + } |
| 103 | + |
| 104 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 105 | + input = inp and output = outp |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments