Skip to content

Commit

Permalink
fix(Security) using golang-jwt instead of jwt-go (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
Djangss authored Dec 5, 2024
1 parent 29fca04 commit e749213
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module AREA

require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-contrib/cors v1.7.2
github.com/gin-gonic/gin v1.10.0
github.com/gookit/config/v2 v2.2.5
Expand Down Expand Up @@ -30,6 +29,7 @@ require (
github.com/go-playground/validator/v10 v10.23.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gookit/goutil v0.6.17 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
github.com/goccy/go-yaml v1.11.2 h1:joq77SxuyIs9zzxEjgyLBugMQ9NEgTWxXfz2wVqwAaQ=
github.com/goccy/go-yaml v1.11.2/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down
12 changes: 6 additions & 6 deletions server/internal/utils/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package utils

import (
"errors"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v5"
"net/http"
"time"
"strings"
"time"
)

func NewToken(c *gin.Context, email string) string {
Expand All @@ -24,11 +24,11 @@ func NewToken(c *gin.Context, email string) string {
func VerifyToken(c *gin.Context) (string, error) {
authHeader := c.GetHeader("Authorization")

if !strings.HasPrefix(authHeader, "Bearer ") {
return "", errors.New("Bearer token is missing")
}
if !strings.HasPrefix(authHeader, "Bearer ") {
return "", errors.New("Bearer token is missing")
}

tokenString := strings.TrimPrefix(authHeader, "Bearer ")
tokenString := strings.TrimPrefix(authHeader, "Bearer ")

if tokenString == "" {
return "", errors.New("Authorization token is missing")
Expand Down

0 comments on commit e749213

Please sign in to comment.