|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the `strings` package. |
| 3 | + */ |
| 4 | + |
| 5 | +import go |
| 6 | + |
| 7 | +/** Provides models of commonly used functions in the `strings` package. */ |
| 8 | +module Strings { |
| 9 | + private class FunctionModels extends TaintTracking::FunctionModel { |
| 10 | + FunctionInput inp; |
| 11 | + FunctionOutput outp; |
| 12 | + |
| 13 | + FunctionModels() { |
| 14 | + // signature: func Fields(s string) []string |
| 15 | + hasQualifiedName("strings", "Fields") and |
| 16 | + (inp.isParameter(0) and outp.isResult()) |
| 17 | + or |
| 18 | + // signature: func FieldsFunc(s string, f func(rune) bool) []string |
| 19 | + hasQualifiedName("strings", "FieldsFunc") and |
| 20 | + (inp.isParameter(0) and outp.isResult()) |
| 21 | + or |
| 22 | + // signature: func Join(elems []string, sep string) string |
| 23 | + hasQualifiedName("strings", "Join") and |
| 24 | + (inp.isParameter(_) and outp.isResult()) |
| 25 | + or |
| 26 | + // signature: func Map(mapping func(rune) rune, s string) string |
| 27 | + hasQualifiedName("strings", "Map") and |
| 28 | + (inp.isParameter(1) and outp.isResult()) |
| 29 | + or |
| 30 | + // signature: func NewReader(s string) *Reader |
| 31 | + hasQualifiedName("strings", "NewReader") and |
| 32 | + (inp.isParameter(0) and outp.isResult()) |
| 33 | + or |
| 34 | + // signature: func NewReplacer(oldnew ...string) *Replacer |
| 35 | + hasQualifiedName("strings", "NewReplacer") and |
| 36 | + (inp.isParameter(_) and outp.isResult()) |
| 37 | + or |
| 38 | + // signature: func Repeat(s string, count int) string |
| 39 | + hasQualifiedName("strings", "Repeat") and |
| 40 | + (inp.isParameter(0) and outp.isResult()) |
| 41 | + or |
| 42 | + // signature: func Replace(s string, old string, new string, n int) string |
| 43 | + hasQualifiedName("strings", "Replace") and |
| 44 | + (inp.isParameter([0, 2]) and outp.isResult()) |
| 45 | + or |
| 46 | + // signature: func ReplaceAll(s string, old string, new string) string |
| 47 | + hasQualifiedName("strings", "ReplaceAll") and |
| 48 | + (inp.isParameter([0, 2]) and outp.isResult()) |
| 49 | + or |
| 50 | + // signature: func Split(s string, sep string) []string |
| 51 | + hasQualifiedName("strings", "Split") and |
| 52 | + (inp.isParameter(0) and outp.isResult()) |
| 53 | + or |
| 54 | + // signature: func SplitAfter(s string, sep string) []string |
| 55 | + hasQualifiedName("strings", "SplitAfter") and |
| 56 | + (inp.isParameter(0) and outp.isResult()) |
| 57 | + or |
| 58 | + // signature: func SplitAfterN(s string, sep string, n int) []string |
| 59 | + hasQualifiedName("strings", "SplitAfterN") and |
| 60 | + (inp.isParameter(0) and outp.isResult()) |
| 61 | + or |
| 62 | + // signature: func SplitN(s string, sep string, n int) []string |
| 63 | + hasQualifiedName("strings", "SplitN") and |
| 64 | + (inp.isParameter(0) and outp.isResult()) |
| 65 | + or |
| 66 | + // signature: func Title(s string) string |
| 67 | + hasQualifiedName("strings", "Title") and |
| 68 | + (inp.isParameter(0) and outp.isResult()) |
| 69 | + or |
| 70 | + // signature: func ToLower(s string) string |
| 71 | + hasQualifiedName("strings", "ToLower") and |
| 72 | + (inp.isParameter(0) and outp.isResult()) |
| 73 | + or |
| 74 | + // signature: func ToLowerSpecial(c unicode.SpecialCase, s string) string |
| 75 | + hasQualifiedName("strings", "ToLowerSpecial") and |
| 76 | + (inp.isParameter(1) and outp.isResult()) |
| 77 | + or |
| 78 | + // signature: func ToTitle(s string) string |
| 79 | + hasQualifiedName("strings", "ToTitle") and |
| 80 | + (inp.isParameter(0) and outp.isResult()) |
| 81 | + or |
| 82 | + // signature: func ToTitleSpecial(c unicode.SpecialCase, s string) string |
| 83 | + hasQualifiedName("strings", "ToTitleSpecial") and |
| 84 | + (inp.isParameter(1) and outp.isResult()) |
| 85 | + or |
| 86 | + // signature: func ToUpper(s string) string |
| 87 | + hasQualifiedName("strings", "ToUpper") and |
| 88 | + (inp.isParameter(0) and outp.isResult()) |
| 89 | + or |
| 90 | + // signature: func ToUpperSpecial(c unicode.SpecialCase, s string) string |
| 91 | + hasQualifiedName("strings", "ToUpperSpecial") and |
| 92 | + (inp.isParameter(1) and outp.isResult()) |
| 93 | + or |
| 94 | + // signature: func ToValidUTF8(s string, replacement string) string |
| 95 | + hasQualifiedName("strings", "ToValidUTF8") and |
| 96 | + (inp.isParameter(_) and outp.isResult()) |
| 97 | + or |
| 98 | + // signature: func Trim(s string, cutset string) string |
| 99 | + hasQualifiedName("strings", "Trim") and |
| 100 | + (inp.isParameter(0) and outp.isResult()) |
| 101 | + or |
| 102 | + // signature: func TrimFunc(s string, f func(rune) bool) string |
| 103 | + hasQualifiedName("strings", "TrimFunc") and |
| 104 | + (inp.isParameter(0) and outp.isResult()) |
| 105 | + or |
| 106 | + // signature: func TrimLeft(s string, cutset string) string |
| 107 | + hasQualifiedName("strings", "TrimLeft") and |
| 108 | + (inp.isParameter(0) and outp.isResult()) |
| 109 | + or |
| 110 | + // signature: func TrimLeftFunc(s string, f func(rune) bool) string |
| 111 | + hasQualifiedName("strings", "TrimLeftFunc") and |
| 112 | + (inp.isParameter(0) and outp.isResult()) |
| 113 | + or |
| 114 | + // signature: func TrimPrefix(s string, prefix string) string |
| 115 | + hasQualifiedName("strings", "TrimPrefix") and |
| 116 | + (inp.isParameter(0) and outp.isResult()) |
| 117 | + or |
| 118 | + // signature: func TrimRight(s string, cutset string) string |
| 119 | + hasQualifiedName("strings", "TrimRight") and |
| 120 | + (inp.isParameter(0) and outp.isResult()) |
| 121 | + or |
| 122 | + // signature: func TrimRightFunc(s string, f func(rune) bool) string |
| 123 | + hasQualifiedName("strings", "TrimRightFunc") and |
| 124 | + (inp.isParameter(0) and outp.isResult()) |
| 125 | + or |
| 126 | + // signature: func TrimSpace(s string) string |
| 127 | + hasQualifiedName("strings", "TrimSpace") and |
| 128 | + (inp.isParameter(0) and outp.isResult()) |
| 129 | + or |
| 130 | + // signature: func TrimSuffix(s string, suffix string) string |
| 131 | + hasQualifiedName("strings", "TrimSuffix") and |
| 132 | + (inp.isParameter(0) and outp.isResult()) |
| 133 | + } |
| 134 | + |
| 135 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 136 | + input = inp and output = outp |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + private class MethodModels extends TaintTracking::FunctionModel, Method { |
| 141 | + FunctionInput inp; |
| 142 | + FunctionOutput outp; |
| 143 | + |
| 144 | + MethodModels() { |
| 145 | + // signature: func (*Builder).String() string |
| 146 | + this.hasQualifiedName("strings", "Builder", "String") and |
| 147 | + (inp.isReceiver() and outp.isResult()) |
| 148 | + or |
| 149 | + // signature: func (*Builder).Write(p []byte) (int, error) |
| 150 | + this.hasQualifiedName("strings", "Builder", "Write") and |
| 151 | + (inp.isParameter(0) and outp.isReceiver()) |
| 152 | + or |
| 153 | + // signature: func (*Builder).WriteString(s string) (int, error) |
| 154 | + this.hasQualifiedName("strings", "Builder", "WriteString") and |
| 155 | + (inp.isParameter(0) and outp.isReceiver()) |
| 156 | + or |
| 157 | + // signature: func (*Reader).Read(b []byte) (n int, err error) |
| 158 | + this.hasQualifiedName("strings", "Reader", "Read") and |
| 159 | + (inp.isReceiver() and outp.isParameter(0)) |
| 160 | + or |
| 161 | + // signature: func (*Reader).ReadAt(b []byte, off int64) (n int, err error) |
| 162 | + this.hasQualifiedName("strings", "Reader", "ReadAt") and |
| 163 | + (inp.isReceiver() and outp.isParameter(0)) |
| 164 | + or |
| 165 | + // signature: func (*Reader).Reset(s string) |
| 166 | + this.hasQualifiedName("strings", "Reader", "Reset") and |
| 167 | + (inp.isParameter(0) and outp.isReceiver()) |
| 168 | + or |
| 169 | + // signature: func (*Reader).WriteTo(w io.Writer) (n int64, err error) |
| 170 | + this.hasQualifiedName("strings", "Reader", "WriteTo") and |
| 171 | + (inp.isReceiver() and outp.isParameter(0)) |
| 172 | + or |
| 173 | + // signature: func (*Replacer).Replace(s string) string |
| 174 | + this.hasQualifiedName("strings", "Replacer", "Replace") and |
| 175 | + (inp.isParameter(0) and outp.isResult()) |
| 176 | + or |
| 177 | + // signature: func (*Replacer).WriteString(w io.Writer, s string) (n int, err error) |
| 178 | + this.hasQualifiedName("strings", "Replacer", "WriteString") and |
| 179 | + (inp.isParameter(1) and outp.isParameter(0)) |
| 180 | + } |
| 181 | + |
| 182 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 183 | + input = inp and output = outp |
| 184 | + } |
| 185 | + } |
| 186 | +} |
0 commit comments