|
| 1 | +/** |
| 2 | + * Provides classes modeling security-relevant aspects of the 'io/fs' package. |
| 3 | + */ |
| 4 | + |
| 5 | +import go |
| 6 | + |
| 7 | +/** |
| 8 | + * Provides classes modeling security-relevant aspects of the 'io/fs' package. |
| 9 | + */ |
| 10 | +module IoFs { |
| 11 | + /** Gets the package name `io/fs`. */ |
| 12 | + string packagePath() { result = "io/fs" } |
| 13 | + |
| 14 | + private class FunctionModels extends TaintTracking::FunctionModel { |
| 15 | + FunctionInput inp; |
| 16 | + FunctionOutput outp; |
| 17 | + |
| 18 | + FunctionModels() { |
| 19 | + //signature: func Glob(fsys FS, pattern string) (matches []string, err error) |
| 20 | + this.hasQualifiedName(packagePath(), "Glob") and |
| 21 | + (inp.isParameter(0) and outp.isResult(0)) |
| 22 | + or |
| 23 | + //signature: func ReadFile(fsys FS, name string) ([]byte, error) |
| 24 | + this.hasQualifiedName(packagePath(), "ReadFile") and |
| 25 | + (inp.isParameter(0) and outp.isResult(0)) |
| 26 | + or |
| 27 | + //signature: func ReadDir(fsys FS, name string) ([]DirEntry, error) |
| 28 | + this.hasQualifiedName(packagePath(), "ReadDir") and |
| 29 | + (inp.isParameter(0) and outp.isResult(0)) |
| 30 | + or |
| 31 | + //signature: func Sub(fsys FS, dir string) (FS, error) |
| 32 | + this.hasQualifiedName(packagePath(), "Sub") and |
| 33 | + (inp.isParameter(0) and outp.isResult(0)) |
| 34 | + } |
| 35 | + |
| 36 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 37 | + input = inp and output = outp |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Models a step from `fs` to `path` and `d` in |
| 43 | + * `fs.WalkDir(fs, "root", func(path string, d DirEntry, err error) {}` |
| 44 | + */ |
| 45 | + private class WalkDirStep extends TaintTracking::AdditionalTaintStep { |
| 46 | + override predicate step(DataFlow::Node pred, DataFlow::Node succ) { |
| 47 | + //signature: func WalkDir(fsys FS, root string, fn WalkDirFunc) error |
| 48 | + exists(DataFlow::CallNode call, DataFlow::FunctionNode f | |
| 49 | + call.getTarget().hasQualifiedName(packagePath(), "WalkDir") and |
| 50 | + f.getASuccessor*() = call.getArgument(2) |
| 51 | + | |
| 52 | + pred = call.getArgument(0) and |
| 53 | + succ = f.getParameter([0, 1]) |
| 54 | + ) |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + private class MethodModels extends TaintTracking::FunctionModel, Method { |
| 59 | + FunctionInput inp; |
| 60 | + FunctionOutput outp; |
| 61 | + |
| 62 | + MethodModels() { |
| 63 | + //signature: func (DirEntry).Name() string |
| 64 | + this.implements(packagePath(), "DirEntry", "Name") and |
| 65 | + (inp.isReceiver() and outp.isResult()) |
| 66 | + or |
| 67 | + //signature: func (DirEntry).Info() (FileInfo, error) |
| 68 | + this.implements(packagePath(), "DirEntry", "Info") and |
| 69 | + (inp.isReceiver() and outp.isResult(0)) |
| 70 | + or |
| 71 | + //signature: func (FS).Open(name string) (File, error) |
| 72 | + this.implements(packagePath(), "FS", "Open") and |
| 73 | + (inp.isReceiver() and outp.isResult(0)) |
| 74 | + or |
| 75 | + //signature: func (GlobFS).Glob(pattern string) ([]string, error) |
| 76 | + this.implements(packagePath(), "GlobFS", "Glob") and |
| 77 | + (inp.isReceiver() and outp.isResult(0)) |
| 78 | + or |
| 79 | + //signature: func (ReadDirFS).ReadDir(name string) ([]DirEntry, error) |
| 80 | + this.implements(packagePath(), "ReadDirFS", "ReadDir") and |
| 81 | + (inp.isReceiver() and outp.isResult(0)) |
| 82 | + or |
| 83 | + //signature: func (ReadFileFS).ReadFile(name string) ([]byte, error) |
| 84 | + this.implements(packagePath(), "ReadFileFS", "ReadFile") and |
| 85 | + (inp.isReceiver() and outp.isResult(0)) |
| 86 | + or |
| 87 | + //signature: func (SubFS).Sub(dir string) (FS, error) |
| 88 | + this.implements(packagePath(), "SubFS", "Sub") and |
| 89 | + (inp.isReceiver() and outp.isResult(0)) |
| 90 | + or |
| 91 | + //signature: func (File).Read([]byte) (int, error) |
| 92 | + this.implements(packagePath(), "File", "Read") and |
| 93 | + (inp.isReceiver() and outp.isParameter(0)) |
| 94 | + } |
| 95 | + |
| 96 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 97 | + input = inp and output = outp |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments