@@ -116,6 +116,56 @@ func StartServer(config *config.Config, manager *service_manager.ServiceManager,
116116 }
117117 })
118118
119+ // Add `authorized` & `username` key to the context
120+ echoServer .Use (func (next echo.HandlerFunc ) echo.HandlerFunc {
121+ return func (c echo.Context ) error {
122+ if strings .Compare (c .Request ().URL .Path , "/" ) == 0 ||
123+ strings .HasPrefix (c .Request ().URL .Path , "/healthcheck" ) ||
124+ strings .HasPrefix (c .Request ().URL .Path , "/.well-known" ) ||
125+ strings .HasPrefix (c .Request ().URL .Path , "/auth" ) ||
126+ strings .HasPrefix (c .Request ().URL .Path , "/webhook" ) ||
127+ strings .HasPrefix (c .Request ().URL .Path , "/dashboard" ) ||
128+ strings .HasPrefix (c .Request ().URL .Path , "/playground" ) {
129+ return next (c )
130+ }
131+ // check if a GET request at /graphql and a websocket upgrade request
132+ if strings .HasPrefix (c .Request ().URL .Path , "/graphql" ) &&
133+ strings .Compare (c .Request ().Method , http .MethodGet ) == 0 &&
134+ strings .Compare (c .Request ().URL .RawQuery , "" ) == 0 &&
135+ strings .Contains (strings .ToLower (c .Request ().Header .Get ("Connection" )), "upgrade" ) &&
136+ strings .Compare (strings .ToLower (c .Request ().Header .Get ("Upgrade" )), "websocket" ) == 0 {
137+ return next (c )
138+ }
139+
140+ // on console websocket connection allow without jwt, as auth will be handled by the console server
141+ if strings .HasPrefix (c .Request ().URL .Path , "/console/ws" ) &&
142+ strings .Compare (c .Request ().Method , http .MethodGet ) == 0 &&
143+ strings .Compare (c .Request ().URL .RawQuery , "" ) == 0 &&
144+ strings .Contains (strings .ToLower (c .Request ().Header .Get ("Connection" )), "upgrade" ) &&
145+ strings .Compare (strings .ToLower (c .Request ().Header .Get ("Upgrade" )), "websocket" ) == 0 {
146+ return next (c )
147+ }
148+
149+ // Whitelist console's HTML, JS, CSS
150+ if (strings .Compare (c .Request ().URL .Path , "/console" ) == 0 ||
151+ strings .Compare (c .Request ().URL .Path , "/console/main.js" ) == 0 ||
152+ strings .Compare (c .Request ().URL .Path , "/console/xterm.js" ) == 0 ||
153+ strings .Compare (c .Request ().URL .Path , "/console/xterm-addon-fit.js" ) == 0 ||
154+ strings .Compare (c .Request ().URL .Path , "/console/xterm.css" ) == 0 ) &&
155+ strings .Compare (c .Request ().Method , http .MethodGet ) == 0 {
156+ return next (c )
157+ }
158+
159+ // Authenticate request
160+
161+ c .Set ("authorized" , false )
162+ c .Set ("username" , "" )
163+ c .Set ("hostname" , "" )
164+
165+ return next (c )
166+ }
167+ })
168+
119169 // Create GraphQL Server
120170 graphqlServer := graphql.Server {
121171 EchoServer : echoServer ,
0 commit comments