refactor(cookie): use rawurlencoding for base64

This commit is contained in:
Trong Huu Nguyen
2023-02-13 20:15:12 +01:00
parent 1b2234f875
commit ce2698f2bb
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -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)
}
+1 -1
View File
@@ -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)