Skip to content

Commit 0d33966

Browse files
authored
fix: corrects JWE and JWT session codecs init (#104)
1 parent 1080d09 commit 0d33966

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Provides a SAML SP authentication proxy for backend web services
5050
-sign-requests
5151
If set, enables SAML request signing (env SAML_PROXY_SIGN_REQUESTS)
5252
-encrypt-jwt
53-
If set, JWTs will be encrypted as JWE (env SAML_ENCRYPT_JWT)
53+
If set, JWTs will be encrypted as JWE (env SAML_PROXY_ENCRYPT_JWT)
5454
-sp-cert-path path
5555
The path to the X509 public certificate PEM file for this SP (env SAML_PROXY_SP_CERT_PATH) (default "saml-auth-proxy.cert")
5656
-sp-key-path path

server/server.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,12 @@ func Start(ctx context.Context, listener net.Listener, logger *zap.Logger, cfg *
9999
cookieSessionProvider.Name = cfg.CookieName
100100
cookieSessionProvider.Domain = cookieDomain
101101
cookieSessionProvider.MaxAge = cfg.CookieMaxAge
102-
103-
// default session provider uses JWT, so we can safely cast it
104-
jwtSessionCodec, ok := cookieSessionProvider.Codec.(*samlsp.JWTSessionCodec)
105-
if !ok {
106-
return fmt.Errorf("session provider codec isn't a JWT session codec")
107-
}
108-
jwtSessionCodec.MaxAge = cfg.CookieMaxAge
102+
codec := samlsp.DefaultSessionCodec(samlOpts)
103+
codec.MaxAge = cfg.CookieMaxAge
104+
cookieSessionProvider.Codec = codec
109105

110106
if cfg.EncryptJWT {
111-
jweSessionCodec, err := NewJWESessionCodec(jwtSessionCodec)
107+
jweSessionCodec, err := NewJWESessionCodec(cookieSessionProvider.Codec)
112108
if err != nil {
113109
return fmt.Errorf("failed to create jwe session codec: %w", err)
114110
}

server/session_jwe.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ type JWESessionCodec struct {
1616
privateKey *rsa.PrivateKey
1717
}
1818

19-
func NewJWESessionCodec(codec *samlsp.JWTSessionCodec) (samlsp.SessionCodec, error) {
19+
func NewJWESessionCodec(sessionCodec samlsp.SessionCodec) (samlsp.SessionCodec, error) {
20+
codec, ok := sessionCodec.(samlsp.JWTSessionCodec)
21+
if !ok {
22+
return nil, fmt.Errorf("session codec isn't JWT session codec")
23+
}
24+
2025
// get the public and private key from the underlying codec to use for encryption
2126
publicKey := &codec.Key.PublicKey
2227
privateKey := codec.Key
@@ -27,7 +32,7 @@ func NewJWESessionCodec(codec *samlsp.JWTSessionCodec) (samlsp.SessionCodec, err
2732
return nil, fmt.Errorf("failed to create jwe encrypter: %w", err)
2833
}
2934

30-
return &JWESessionCodec{jwtSessionCodec: codec, encrypter: encrypter, privateKey: privateKey}, nil
35+
return &JWESessionCodec{jwtSessionCodec: &codec, encrypter: encrypter, privateKey: privateKey}, nil
3136
}
3237

3338
func (c *JWESessionCodec) New(assertion *saml.Assertion) (samlsp.Session, error) {

server/session_jwe_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestJWESessionCodec(t *testing.T) {
2424
jwtCodec := samlsp.DefaultSessionCodec(samlsp.Options{Key: key, URL: *baseURL})
2525

2626
// Create the JWESessionCodec
27-
jweCodec, err := NewJWESessionCodec(&jwtCodec)
27+
jweCodec, err := NewJWESessionCodec(jwtCodec)
2828
if err != nil {
2929
t.Fatalf("failed to create JWESessionCodec: %v", err)
3030
}

0 commit comments

Comments
 (0)