Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sso-proxy: avoid oversized cookies #95

Merged
merged 3 commits into from
Apr 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions internal/pkg/aead/aead.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package aead

import (
"bytes"
"compress/gzip"
"crypto/cipher"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"sync"

miscreant "github.com/miscreant/miscreant-go"
Expand Down Expand Up @@ -95,8 +98,14 @@ func (c *MiscreantCipher) Marshal(s interface{}) (string, error) {
return "", err
}

// gunzip the bytes
var jsonBuffer bytes.Buffer
w := gzip.NewWriter(&jsonBuffer)
w.Write(plaintext)
w.Close()

// encrypt the JSON
ciphertext, err := c.Encrypt(plaintext)
ciphertext, err := c.Encrypt(jsonBuffer.Bytes())
if err != nil {
return "", err
}
Expand All @@ -121,8 +130,16 @@ func (c *MiscreantCipher) Unmarshal(value string, s interface{}) error {
return err
}

// gzip the bytes
var jsonBuffer bytes.Buffer
r, err := gzip.NewReader(bytes.NewBuffer(plaintext))
if err != nil {
return err
}
io.Copy(&jsonBuffer, r)

// unmarshal bytes
err = json.Unmarshal(plaintext, s)
err = json.Unmarshal(jsonBuffer.Bytes(), s)
if err != nil {
return err
}
Expand Down