|
| 1 | +/** Provides models of commonly used functions and types in the gqlgen packages. */ |
| 2 | + |
| 3 | +import go |
| 4 | + |
| 5 | +/** Provides models of commonly used functions and types in the gqlgen packages. */ |
| 6 | +module Gqlgen { |
| 7 | + /** An autogenerated file containing gqlgen code. */ |
| 8 | + private class GqlgenGeneratedFile extends File { |
| 9 | + GqlgenGeneratedFile() { |
| 10 | + exists(DataFlow::CallNode call | |
| 11 | + call.getReceiver().getType().hasQualifiedName("github.com/99designs/gqlgen/graphql", _) and |
| 12 | + call.getFile() = this |
| 13 | + ) |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + /** A resolver interface. */ |
| 18 | + private class ResolverInterface extends Type { |
| 19 | + ResolverInterface() { |
| 20 | + this.getQualifiedName().matches("%Resolver") and |
| 21 | + this.getEntity().getDeclaration().getFile() instanceof GqlgenGeneratedFile |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + /** A resolver implementation. */ |
| 26 | + private class ResolverInterfaceMethod extends Method { |
| 27 | + ResolverInterfaceMethod() { this.getReceiver().getType() instanceof ResolverInterface } |
| 28 | + } |
| 29 | + |
| 30 | + /** A resolver method which is exposed as a Graphql endpoint */ |
| 31 | + private class ResolverImplementationMethod extends Method { |
| 32 | + ResolverImplementationMethod() { this.implements(any(ResolverInterfaceMethod r)) } |
| 33 | + |
| 34 | + Parameter getAnUntrustedParameter() { |
| 35 | + result.getFunction() = this.getFuncDecl() and |
| 36 | + not result.getType().hasQualifiedName("context", "Context") and |
| 37 | + result.getIndex() > 0 |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + /** A parameter of a resolver method which receives untrusted input. */ |
| 42 | + class ResolverParameter extends UntrustedFlowSource::Range instanceof DataFlow::ParameterNode { |
| 43 | + ResolverParameter() { |
| 44 | + this.asParameter() = any(ResolverImplementationMethod h).getAnUntrustedParameter() |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments