Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit 01b4092

Browse files
committed
Fix session JWT expiration validation
1 parent 0159b8c commit 01b4092

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

internal/crypto/sessionjwt/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (m *Manager) Verify(raw string) (*core.SessionClaims, error) {
8282
}, nil
8383
}
8484

85-
func (c *claims) Valid() error {
85+
func (c *claims) Validate() error {
8686
if c.ExpiresAt == nil {
8787
return fmt.Errorf("%w: missing exp", core.ErrUnauthorized)
8888
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package sessionjwt
2+
3+
import (
4+
"crypto/ed25519"
5+
"errors"
6+
"strings"
7+
"testing"
8+
9+
"github.com/evalops/asb/internal/core"
10+
"github.com/golang-jwt/jwt/v5"
11+
)
12+
13+
func TestManager_VerifyRejectsTokenWithoutExpiration(t *testing.T) {
14+
t.Parallel()
15+
16+
_, privateKey, err := ed25519.GenerateKey(nil)
17+
if err != nil {
18+
t.Fatalf("GenerateKey() error = %v", err)
19+
}
20+
21+
manager, err := NewManager(privateKey)
22+
if err != nil {
23+
t.Fatalf("NewManager() error = %v", err)
24+
}
25+
26+
token := jwt.NewWithClaims(jwt.SigningMethodEdDSA, jwt.MapClaims{
27+
"sid": "sess_123",
28+
"tenant_id": "t_acme",
29+
"agent_id": "agent_123",
30+
"run_id": "run_123",
31+
"tool_context": []string{
32+
"github",
33+
},
34+
"workload_hash": "sha256:test",
35+
})
36+
raw, err := token.SignedString(privateKey)
37+
if err != nil {
38+
t.Fatalf("SignedString() error = %v", err)
39+
}
40+
41+
if _, err := manager.Verify(raw); err == nil {
42+
t.Fatal("Verify() error = nil, want non-nil")
43+
} else if !errors.Is(err, core.ErrUnauthorized) {
44+
t.Fatalf("Verify() error = %v, want unauthorized", err)
45+
} else if !strings.Contains(err.Error(), "missing exp") {
46+
t.Fatalf("Verify() error = %v, want missing exp", err)
47+
}
48+
}

0 commit comments

Comments
 (0)