Skip to content

Commit

Permalink
Merge pull request #95 from Remitly/compress-cookie
Browse files Browse the repository at this point in the history
sso-proxy: avoid oversized cookies
  • Loading branch information
Shraya Ramani committed Apr 3, 2019
2 parents 0d3b27d + 0022728 commit 6ea74f2
Showing 1 changed file with 19 additions and 2 deletions.
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

0 comments on commit 6ea74f2

Please sign in to comment.