Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GraphQl): Panic fix when subscription expiry is not present in jwt. #6129

Merged
merged 5 commits into from
Aug 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions graphql/web/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import (
"compress/gzip"
"context"
"encoding/json"
"strconv"
"time"

"github.com/dgrijalva/jwt-go/v4"
"google.golang.org/grpc/metadata"
"strconv"
"time"

"io"
"io/ioutil"
Expand Down Expand Up @@ -127,13 +126,11 @@ func (gs *graphqlSubscription) Subscribe(

// library (graphql-transport-ws) passes the headers which are part of the INIT payload to us in the context.
// And we are extracting the Auth JWT from those and passing them along.

header, _ := ctx.Value("Header").(json.RawMessage)
customClaims := &authorization.CustomClaims{
StandardClaims: jwt.StandardClaims{
ExpiresAt: jwt.At(time.Time{}),
},
StandardClaims: jwt.StandardClaims{},
}
header, _ := ctx.Value("Header").(json.RawMessage)

if len(header) > 0 {
payload := make(map[string]interface{})
if err := json.Unmarshal(header, &payload); err != nil {
Expand All @@ -156,6 +153,9 @@ func (gs *graphqlSubscription) Subscribe(
}
}

if len(header) == 0 || customClaims.StandardClaims.ExpiresAt == nil {
customClaims.StandardClaims.ExpiresAt = jwt.At(time.Time{})
}
req := &schema.Request{
OperationName: operationName,
Query: document,
Expand Down