-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d122b6
commit 1920f9b
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
traefik: | ||
traefik --configfile=traefik.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
http: | ||
routers: | ||
graphql-server-entrypoint: | ||
service: graphql-server-service | ||
entrypoints: | ||
- graphql-server-entrypoint | ||
rule: Host(`localhost`) | ||
middlewares: | ||
- my-traefik-plugin-disable-graphql-introspection | ||
services: | ||
graphql-server-service: | ||
loadBalancer: | ||
servers: | ||
- url: http://localhost:16020/ | ||
middlewares: | ||
my-traefik-plugin-disable-graphql-introspection: | ||
plugin: | ||
traefik-plugin-disable-graphql-introspection: | ||
GraphQLPath: /v1/graphql |
6 changes: 6 additions & 0 deletions
6
...ocal/src/github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection/.traefik.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
displayName: Disable GraphQL Introspection Plugin | ||
type: middleware | ||
import: github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection | ||
summary: 'Disable GraphQL Introspection' | ||
testData: | ||
GraphQLPath: /graphql |
3 changes: 3 additions & 0 deletions
3
...gins-local/src/github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection/go.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection | ||
|
||
go 1.17 |
65 changes: 65 additions & 0 deletions
65
...ins-local/src/github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package traefik_plugin_disable_graphql_introspection | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
type Config struct { | ||
GraphQLPath string | ||
} | ||
|
||
func CreateConfig() *Config { | ||
return &Config{ | ||
GraphQLPath: "/graphql", | ||
} | ||
} | ||
|
||
type DisableGraphQLIntrospection struct { | ||
next http.Handler | ||
name string | ||
graphQLPath string | ||
} | ||
|
||
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) { | ||
return &DisableGraphQLIntrospection{ | ||
next: next, | ||
name: name, | ||
graphQLPath: config.GraphQLPath, | ||
}, nil | ||
} | ||
|
||
func (d *DisableGraphQLIntrospection) ServeHTTP(rw http.ResponseWriter, r *http.Request) { | ||
body, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
log.Printf("Error reading body: %v", err) | ||
rw.WriteHeader(http.StatusBadRequest) | ||
rw.Header().Set("Content-Type", "application/json") | ||
rw.Write([]byte(`{ | ||
"error": { | ||
"code": 400, | ||
"message": "Failed to read request body." | ||
} | ||
}`)) | ||
return | ||
} | ||
if r.Method == "POST" && r.URL.Path == d.graphQLPath { | ||
if strings.Contains(string(body), "__schema") || strings.Contains(string(body), "__type") { | ||
rw.Header().Set("Content-Type", "application/json") | ||
rw.Write([]byte(`{ | ||
"errors": [ | ||
{ | ||
"message": "GraphQL introspection is not allowed." | ||
} | ||
] | ||
}`)) | ||
return | ||
} | ||
} | ||
r.Body = ioutil.NopCloser(bytes.NewBuffer(body)) | ||
d.next.ServeHTTP(rw, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
entryPoints: | ||
graphql-server-entrypoint: | ||
address: :16022 | ||
api: | ||
insecure: true | ||
dashboard: true | ||
providers: | ||
file: | ||
filename: dynamic_conf.yaml | ||
log: | ||
level: DEBUG | ||
experimental: | ||
localPlugins: | ||
traefik-plugin-disable-graphql-introspection: | ||
modulename: github.com/Hongbo-Miao/traefik-plugin-disable-graphql-introspection |