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

Added check for empty issuer #37

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion internal/services/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ func (i *Impl) ValidateToken(shortSession string) (*entities.User, error) {
}

func (i *Impl) validateIssuer(jwtIssuer string, shortSession string) error {
if jwtIssuer == "" {
return newValidationError("Issuer is empty", shortSession, validationerror.CodeJWTIssuerEmpty)
}

// Compare to old Frontend API (without .cloud.) to make our Frontend API host name change downwards compatible
if jwtIssuer == fmt.Sprintf("https://%s.frontendapi.corbado.io", i.Config.ProjectID) {
return nil
Expand All @@ -149,7 +153,7 @@ func (i *Impl) validateIssuer(jwtIssuer string, shortSession string) error {
// Compare to configured issuer (from FrontendAPI), needed if you set a CNAME for example
if jwtIssuer != i.Config.JWTIssuer {
return newValidationError(
fmt.Sprintf("JWT issuer mismatch (configured trough FrontendAPI: '%s', JWT issuer: '%s')", i.Config.JWTIssuer, jwtIssuer),
fmt.Sprintf("Issuer mismatch (configured trough FrontendAPI: '%s', JWT issuer: '%s')", i.Config.JWTIssuer, jwtIssuer),
shortSession,
validationerror.CodeJWTIssuerMismatch,
)
Expand Down
1 change: 1 addition & 0 deletions pkg/validationerror/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ const (
CodeJWTInvalidSignature
CodeJWTBefore
CodeJWTExpired
CodeJWTIssuerEmpty
)
9 changes: 8 additions & 1 deletion tests/unit/session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ func TestValidateToken(t *testing.T) {
validationErrorCode: validationerror.CodeJWTExpired,
success: false,
},
{
name: "Empty issuer (iss)",
issuer: "https://pro-1.frontendapi.corbado.io",
shortSession: generateJWT("", time.Now().Add(100*time.Second).Unix(), time.Now().Unix(), validPrivateKey),
validationErrorCode: validationerror.CodeJWTIssuerEmpty,
success: false,
},
{
name: "Invalid issuer 1 (iss)",
issuer: "https://pro-1.frontendapi.corbado.io",
Expand All @@ -200,7 +207,7 @@ func TestValidateToken(t *testing.T) {
success: false,
},
{
name: "Invalid issuer 1 (iss)",
name: "Invalid issuer 2 (iss)",
issuer: "https://pro-1.frontendapi.cloud.corbado.io",
shortSession: generateJWT("https://pro-2.frontendapi.corbado.io", time.Now().Add(100*time.Second).Unix(), time.Now().Unix(), validPrivateKey),
validationErrorCode: validationerror.CodeJWTIssuerMismatch,
Expand Down
Loading