-
Notifications
You must be signed in to change notification settings - Fork 629
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
fix: Panics when passing a malformed GitSession #3058
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IV size (nonce) size is determined in the oauth2-proxy (uses the standard size 12) and ideally should be verified at decryption inside the library (e.g., here), – it's very unlikely that it will change, so I think it's ok to do it on our side. OTOH, I'm not sure if we benefit from use of oauth2-proxy dependency
func decryptToken(encodedText string, key []byte) (*oauth2.Token, error) { | ||
encryptedData, err := base64.StdEncoding.DecodeString(encodedText) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(encryptedData) < gcmNonceSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we need to recover panic in this function or above too just in case ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should. Shouldn't all recoverable panics get caught by the grpc handler? Why doesn't this happen today?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Christian Simon <simon@swine.de>
If a carefully chosen
GitSession
is passed to the backend, it causes an out of range panic and crash. This isn't ideal as attackers will have a way to continually crash queriers.If
GitSession
is a valid base64 encoding which, when decoded, results in a cipher text less than the chose GCM Cipher nonce size, the decryption subroutine will try split the cipher text into two parts, a "nonce" part and a "rest" part. if the cipher text is shorter than the "nonce" part, it panics.See: https://github.com/oauth2-proxy/oauth2-proxy/blob/e3dc927e570700ae598425344cf07073965bd19c/pkg/encryption/cipher.go#L124-L125
As far as I can tell, the nonce size is always 12, though I don't know how reliably we can depend on this.