Skip to content

Commit 21136ba

Browse files
authored
chore: Remove oauth2-proxy (#4345)
The use of oauth2-proxy just for nonce handling is total overkill. Given there is a critical vulnerablility in oauth2-proxy, that will be flagged I rather remove it at this point.
1 parent 0380053 commit 21136ba

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ require (
5454
github.com/mattn/go-isatty v0.0.20
5555
github.com/minio/minio-go/v7 v7.0.88
5656
github.com/mitchellh/go-wordwrap v1.0.1
57-
github.com/oauth2-proxy/oauth2-proxy/v7 v7.5.1
5857
github.com/oklog/ulid/v2 v2.1.1
5958
github.com/olekukonko/tablewriter v0.0.5
6059
github.com/onsi/ginkgo/v2 v2.21.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
590590
github.com/ncw/swift v1.0.53 h1:luHjjTNtekIEvHg5KdAFIBaH7bWfNkefwFnpDffSIks=
591591
github.com/ncw/swift v1.0.53/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
592592
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
593-
github.com/oauth2-proxy/oauth2-proxy/v7 v7.5.1 h1:zu+o5Zk0MJxeZTAKhgybBVm6GZwI6D8CD0WzCR8sESQ=
594-
github.com/oauth2-proxy/oauth2-proxy/v7 v7.5.1/go.mod h1:9TIUszoaT174lwycQ2XmG4h5KVEfgqmVL1SISuIqu04=
595593
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
596594
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
597595
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=

go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQ
608608
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
609609
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
610610
github.com/bazelbuild/rules_go v0.49.0/go.mod h1:Dhcz716Kqg1RHNWos+N6MlXNkjNP2EwZQ0LukRKJfMs=
611+
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
611612
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
612613
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
613614
github.com/benmathews/bench v0.0.0-20210120214102-f7c75b9ef6e7 h1:nYTgFk9sOL3rmNew6rR2anUWWCzmSYPMJiSmowV8Yls=
@@ -1021,6 +1022,7 @@ github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0b
10211022
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
10221023
github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo=
10231024
github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
1025+
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
10241026
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
10251027
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
10261028
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=

pkg/frontend/vcs/encryption.go

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,76 @@
11
package vcs
22

33
import (
4+
"crypto/aes"
5+
"crypto/cipher"
6+
"crypto/rand"
47
"encoding/base64"
58
"encoding/json"
69
"errors"
10+
"io"
711

8-
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/encryption"
912
"golang.org/x/oauth2"
1013
)
1114

12-
const gcmNonceSize = 12
13-
1415
func encryptToken(token *oauth2.Token, key []byte) (string, error) {
15-
cipher, err := encryption.NewGCMCipher(key)
16+
plaintext, err := json.Marshal(token)
1617
if err != nil {
1718
return "", err
1819
}
19-
textBytes, err := json.Marshal(token)
20+
21+
block, err := aes.NewCipher(key)
2022
if err != nil {
2123
return "", err
2224
}
23-
enc, err := cipher.Encrypt(textBytes)
25+
26+
gcm, err := cipher.NewGCM(block)
2427
if err != nil {
2528
return "", err
2629
}
27-
return base64.StdEncoding.EncodeToString(enc), nil
30+
31+
nonce := make([]byte, gcm.NonceSize())
32+
if _, err = io.ReadFull(rand.Reader, nonce); err != nil {
33+
return "", err
34+
}
35+
36+
// Using nonce as Seal's dst argument results in it being the first
37+
// chunk of bytes in the ciphertext. Decrypt retrieves the nonce/IV from this.
38+
ciphertext := gcm.Seal(nonce, nonce, plaintext, nil)
39+
40+
return base64.StdEncoding.EncodeToString(ciphertext), nil
2841
}
2942

30-
func decryptToken(encodedText string, key []byte) (*oauth2.Token, error) {
31-
encryptedData, err := base64.StdEncoding.DecodeString(encodedText)
43+
func decryptToken(ciphertextBase64 string, key []byte) (*oauth2.Token, error) {
44+
ciphertext, err := base64.StdEncoding.DecodeString(ciphertextBase64)
3245
if err != nil {
3346
return nil, err
3447
}
3548

36-
if len(encryptedData) < gcmNonceSize {
37-
return nil, errors.New("malformed token")
49+
block, err := aes.NewCipher(key)
50+
if err != nil {
51+
return nil, err
3852
}
3953

40-
cipher, err := encryption.NewGCMCipher(key)
54+
gcm, err := cipher.NewGCM(block)
4155
if err != nil {
4256
return nil, err
4357
}
4458

45-
plaintext, err := cipher.Decrypt(encryptedData)
59+
nonceSize := gcm.NonceSize()
60+
if len(ciphertext) < nonceSize {
61+
return nil, errors.New("malformed token")
62+
}
63+
nonce, ciphertext := ciphertext[:nonceSize], ciphertext[nonceSize:]
64+
65+
plaintext, err := gcm.Open(nil, nonce, ciphertext, nil)
4666
if err != nil {
4767
return nil, err
4868
}
4969

5070
var token oauth2.Token
51-
err = json.Unmarshal(plaintext, &token)
52-
return &token, err
71+
if err = json.Unmarshal(plaintext, &token); err != nil {
72+
return nil, err
73+
}
74+
75+
return &token, nil
5376
}

0 commit comments

Comments
 (0)