Skip to content

Commit 228913c

Browse files
committed
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 a64a25d commit 228913c

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ require (
5252
github.com/mattn/go-isatty v0.0.20
5353
github.com/minio/minio-go/v7 v7.0.88
5454
github.com/mitchellh/go-wordwrap v1.0.1
55-
github.com/oauth2-proxy/oauth2-proxy/v7 v7.5.1
5655
github.com/oklog/ulid v1.3.1
5756
github.com/olekukonko/tablewriter v0.0.5
5857
github.com/onsi/ginkgo/v2 v2.19.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRW
575575
github.com/ncw/swift v1.0.53 h1:luHjjTNtekIEvHg5KdAFIBaH7bWfNkefwFnpDffSIks=
576576
github.com/ncw/swift v1.0.53/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
577577
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
578-
github.com/oauth2-proxy/oauth2-proxy/v7 v7.5.1 h1:zu+o5Zk0MJxeZTAKhgybBVm6GZwI6D8CD0WzCR8sESQ=
579-
github.com/oauth2-proxy/oauth2-proxy/v7 v7.5.1/go.mod h1:9TIUszoaT174lwycQ2XmG4h5KVEfgqmVL1SISuIqu04=
580578
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
581579
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
582580
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=

go.work.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
281281
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
282282
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA=
283283
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f/go.mod h1:AuiFmCCPBSrqvVMvuqFuk0qogytodnVFVSN5CeJB8Gc=
284+
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
284285
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
285286
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
286287
github.com/benmathews/bench v0.0.0-20210120214102-f7c75b9ef6e7 h1:nYTgFk9sOL3rmNew6rR2anUWWCzmSYPMJiSmowV8Yls=
@@ -336,6 +337,8 @@ github.com/envoyproxy/go-control-plane/ratelimit v0.1.0/go.mod h1:Wk+tMFAFbCXaJP
336337
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
337338
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
338339
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90 h1:WXb3TSNmHp2vHoCroCIB1foO/yQ36swABL8aOVeDpgg=
340+
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
341+
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
339342
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew=
340343
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
341344
github.com/go-fonts/stix v0.2.2 h1:v9krocr13J1llaOHLEol1eaHsv8S43UuFX/1bFgEJJ4=
@@ -478,6 +481,8 @@ github.com/shurcooL/vfsgen v0.0.0-20230704071429-0000e147ea92 h1:OfRzdxCzDhp+rsK
478481
github.com/shurcooL/vfsgen v0.0.0-20230704071429-0000e147ea92/go.mod h1:7/OT02F6S6I7v6WXb+IjhMuZEYfH/RJ5RwEWnEo5BMg=
479482
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
480483
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
484+
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
485+
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
481486
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
482487
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
483488
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=

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)