Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(auth): guard against missing org row in validateJWT

Jaydeep Pipaliya82d157abbde6
diff --git a/backend-go/internal/services/auth/apiauth/authenticator.go b/backend-go/internal/services/auth/apiauth/authenticator.go
index 54e4ed7024..0ce43ba9f7 100644
--- a/backend-go/internal/services/auth/apiauth/authenticator.go
+++ b/backend-go/internal/services/auth/apiauth/authenticator.go
@@ -214,6 +214,12 @@ func (a Authenticator) validateJWT(ctx context.Context, token string) (*auth.Ide
if err != nil {
return nil, errutil.DatabaseErr("Failed to find organization").WithErrf("validateJWT(orgId=%s): %w", claims.OrganizationID, err)
}
+ if org == nil {
+ // findOrgByID returns (nil, nil) on pgx.ErrNoRows. The org row can be
+ // missing if it was deleted between JWT issue and validation; without
+ // this guard `org.Name` below panics.
+ return nil, errutil.BadRequest("Organization %s not found", claims.OrganizationID).WithErrf("validateJWT(orgId=%s): organization not found", claims.OrganizationID)
+ }
orgMembership, err := a.findEffectiveOrgMembership(ctx, auth.ActorTypeUser, user.ID, claims.OrganizationID, "accepted")
if err != nil {