Skip to content

Commit 8605fd9

Browse files
alnrclaude
andcommitted
fix: reject negative API key expiry
Previously a negative --api-key-expiry was silently treated as "no expiry", which could let callers create non-expiring keys by mistake. Return an error for negative durations instead. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9b0e299 commit 8605fd9

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

cmd/cloudx/client/api_key.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ import (
1515

1616
// CreateProjectAPIKey creates a project API key. If expiresIn is greater than
1717
// zero, the key is set to expire that duration from now so it is cleaned up
18-
// automatically on the server side even if local cleanup fails.
18+
// automatically on the server side even if local cleanup fails. An expiresIn of
19+
// zero creates a key without expiry; a negative value is rejected.
1920
func (h *CommandHelper) CreateProjectAPIKey(ctx context.Context, projectID, name string, expiresIn time.Duration) (*cloud.ProjectApiKey, error) {
21+
if expiresIn < 0 {
22+
return nil, errors.New("API key expiry must not be negative")
23+
}
24+
2025
c, err := h.newConsoleAPIClient(ctx)
2126
if err != nil {
2227
return nil, err

0 commit comments

Comments
 (0)