Skip to content

Commit b0f1566

Browse files
committed
fix(api): add timeout and validation to license handshake
- Add 5 second timeout to license fetch to prevent indefinite blocking - Validate license response is not empty before setting - Gracefully handles timeout and empty response errors
1 parent 1b95720 commit b0f1566

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

descope/api/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,9 @@ func (c *Client) FetchLicense(ctx context.Context) (string, error) {
18221822
if err != nil {
18231823
return "", err
18241824
}
1825+
if resp.LicenseType == "" {
1826+
return "", fmt.Errorf("empty license type returned from server")
1827+
}
18251828
return resp.LicenseType, nil
18261829
}
18271830

descope/client/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package client
22

33
import (
44
"context"
5+
"time"
56

67
"github.com/descope/go-sdk/descope"
78
"github.com/descope/go-sdk/descope/api"
@@ -90,7 +91,9 @@ func NewWithConfig(config *Config) (*DescopeClient, error) {
9091
})
9192

9293
if config.ManagementKey != "" {
93-
if license, err := mgmtClient.FetchLicense(context.Background()); err != nil {
94+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
95+
defer cancel()
96+
if license, err := mgmtClient.FetchLicense(ctx); err != nil {
9497
logger.LogInfo("License handshake failed, continuing without header: %v", err)
9598
} else {
9699
mgmtClient.SetLicenseType(license)

0 commit comments

Comments
 (0)