Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/SnackLog/auth-lib
go 1.25.5

require (
github.com/SnackLog/service-config-lib v0.1.3
github.com/SnackLog/service-config-lib v0.2.0
github.com/gin-gonic/gin v1.11.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/SnackLog/service-config-lib v0.1.3 h1:cEsiUf8LK6uAlzclR3OplZUUOc/zIYCvjDIccvpU58U=
github.com/SnackLog/service-config-lib v0.1.3/go.mod h1:FekzUIjuiOjTfOisRBFt8sBS+fOW8nGrAxNPoxY7Yo0=
github.com/SnackLog/service-config-lib v0.2.0 h1:LebIe1sBFSK+uUgjHxLQ3qJDZUfTYXr4Rxsm2RBPjZI=
github.com/SnackLog/service-config-lib v0.2.0/go.mod h1:FekzUIjuiOjTfOisRBFt8sBS+fOW8nGrAxNPoxY7Yo0=
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=
github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=
Expand Down
11 changes: 11 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"

serviceconfig "github.com/SnackLog/service-config-lib"
Expand All @@ -14,7 +15,17 @@ type authServiceResponse struct {
Username string `json:"username"`
}

func bypassLogic(c *gin.Context) {
log.Println("\033[1;31mWARNING: DEBUG_BYPASS_AUTH_MIDDLEWARE is enabled, bypassing authentication and setting user to 'foo'!\033[0m")
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message is logged on every authenticated request when debug bypass is enabled. This could generate excessive log output and make debugging more difficult. Consider logging this warning only once at application startup or middleware initialization instead of on every request.

Copilot uses AI. Check for mistakes.
c.Set("username", "foo")
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bypassLogic function is missing a call to c.Next() at the end. Looking at the Authentication function at line 59, c.Next() is called after setting the username to continue the middleware chain. Without this call in bypassLogic, subsequent middleware and handlers in the chain will not be executed when the debug bypass is enabled, which will break the request flow.

Suggested change
c.Set("username", "foo")
c.Set("username", "foo")
c.Next()

Copilot uses AI. Check for mistakes.
c.Next()
}

func Authentication(c *gin.Context) {
if serviceconfig.GetConfig().DebugBypassAuthMiddleware {
bypassLogic(c)
return
}
authHeader := c.GetHeader("Authorization")
requestUrl := fmt.Sprintf("%s/%s", serviceconfig.GetConfig().ApiRootUrl, "auth/session")
request, err := http.NewRequest("GET", requestUrl, nil)
Expand Down