1+ /** Provides models of commonly used functions and types in the twirp packages. */
2+
13import go
24import semmle.go.security.RequestForgery
35
6+ /** Provides models of commonly used functions and types in the twirp packages. */
47module Twirp {
58 /**
69 * A *.pb.go file generated by Twirp.
@@ -47,17 +50,27 @@ module Twirp {
4750 /**
4851 * An interface type representing a Twirp service.
4952 */
50- class ServiceInterface extends NamedType {
53+ class ServiceInterface extends InterfaceType {
54+ NamedType serviceInterface ;
55+
5156 ServiceInterface ( ) {
5257 exists ( TypeEntity te |
53- te .getType ( ) = this and
54- // To match an Interface type we need to use a NamedType whose getUnderlying type is an InterfaceType
55- this .getUnderlyingType ( ) instanceof InterfaceType and
58+ te .getType ( ) = serviceInterface and
59+ this instanceof InterfaceType and
60+ serviceInterface .getUnderlyingType ( ) = this and
5661 te .getDeclaration ( ) .getLocation ( ) .getFile ( ) instanceof ServicesGeneratedFile
5762 )
5863 }
5964
60- InterfaceType getInterfaceType ( ) { result = this .getUnderlyingType ( ) }
65+ /**
66+ * Returns the name of the interface
67+ */
68+ override string getName ( ) { result = serviceInterface .getName ( ) }
69+
70+ /**
71+ * Returns the named type on top of this interface type
72+ */
73+ NamedType getNamedType ( ) { result = serviceInterface }
6174 }
6275
6376 /**
@@ -68,7 +81,7 @@ module Twirp {
6881
6982 ServiceClient ( ) {
7083 exists ( ServiceInterface i |
71- pointerType .implements ( i . getInterfaceType ( ) ) and
84+ pointerType .implements ( i ) and
7285 this = pointerType .getBaseType ( ) and
7386 this .getName ( ) .toLowerCase ( ) = i .getName ( ) .toLowerCase ( ) + [ "protobuf" , "json" ] + "client"
7487 )
@@ -81,7 +94,7 @@ module Twirp {
8194 class ServiceServer extends NamedType {
8295 ServiceServer ( ) {
8396 exists ( ServiceInterface i |
84- this .implements ( i . getInterfaceType ( ) ) and
97+ this .implements ( i ) and
8598 this .getName ( ) .toLowerCase ( ) = i .getName ( ) .toLowerCase ( ) + "server"
8699 )
87100 }
@@ -106,9 +119,9 @@ module Twirp {
106119 */
107120 class ServerConstructor extends Function {
108121 ServerConstructor ( ) {
109- exists ( ServiceServer c |
122+ exists ( ServiceServer c , ServiceInterface i |
110123 this .getName ( ) .toLowerCase ( ) = "new" + c .getName ( ) .toLowerCase ( ) and
111- this .getParameter ( 0 ) .getType ( ) instanceof ServiceInterface
124+ this .getParameter ( 0 ) .getType ( ) = i . getNamedType ( )
112125 )
113126 }
114127 }
@@ -139,10 +152,10 @@ module Twirp {
139152 exists ( DataFlow:: CallNode call , Type handlerType , ServiceInterface i |
140153 call .getTarget ( ) instanceof ServerConstructor and
141154 call .getArgument ( 0 ) .getType ( ) = handlerType and
142- handlerType .implements ( i . getInterfaceType ( ) ) and
155+ handlerType .implements ( i ) and
143156 this = handlerType .getMethod ( _) and
144157 this .implements ( m ) and
145- i .getMethod ( _) = m
158+ i .getNamedType ( ) . getMethod ( _) = m
146159 )
147160 }
148161 }
0 commit comments