From ce2698f2bb54629c28bf0b32577e33dbc87fe865 Mon Sep 17 00:00:00 2001 From: Trong Huu Nguyen Date: Mon, 13 Feb 2023 20:15:12 +0100 Subject: [PATCH] refactor(cookie): use rawurlencoding for base64 --- pkg/cookie/cookie.go | 4 ++-- pkg/handler/logout_frontchannel_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/cookie/cookie.go b/pkg/cookie/cookie.go index 19c9f89..6e286b5 100644 --- a/pkg/cookie/cookie.go +++ b/pkg/cookie/cookie.go @@ -35,13 +35,13 @@ func (in *Cookie) Encrypt(crypter crypto.Crypter) (*Cookie, error) { return nil, fmt.Errorf("unable to encrypt cookie '%s': %w", in.Cookie.Name, err) } - value := base64.StdEncoding.EncodeToString(ciphertext) + value := base64.RawURLEncoding.EncodeToString(ciphertext) in.Cookie.Value = value return in, nil } func (in *Cookie) Decrypt(crypter crypto.Crypter) (string, error) { - ciphertext, err := base64.StdEncoding.DecodeString(in.Value) + ciphertext, err := base64.RawURLEncoding.DecodeString(in.Value) if err != nil { return "", fmt.Errorf("%w: named '%s': %+v", ErrInvalidValue, in.Name, err) } diff --git a/pkg/handler/logout_frontchannel_test.go b/pkg/handler/logout_frontchannel_test.go index 8b90ebc..87af617 100644 --- a/pkg/handler/logout_frontchannel_test.go +++ b/pkg/handler/logout_frontchannel_test.go @@ -22,7 +22,7 @@ func TestFrontChannelLogout(t *testing.T) { // Trigger front-channel logout sid := func(r *http.Request) string { - ciphertext, err := base64.StdEncoding.DecodeString(sessionCookie.Value) + ciphertext, err := base64.RawURLEncoding.DecodeString(sessionCookie.Value) assert.NoError(t, err) sessionKey, err := idp.RelyingPartyHandler.GetCrypter().Decrypt(ciphertext)