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

fix: Panics when passing a malformed GitSession #3058

Merged
merged 5 commits into from
Mar 1, 2024
Merged

Conversation

bryanhuhta
Copy link
Contributor

@bryanhuhta bryanhuhta commented Feb 29, 2024

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.

@bryanhuhta bryanhuhta self-assigned this Feb 29, 2024
@bryanhuhta bryanhuhta requested a review from a team as a code owner February 29, 2024 01:54
Copy link
Collaborator

@kolesnikovae kolesnikovae left a 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 {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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?

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@simonswine simonswine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

pkg/querier/vcs/client/encryption.go Outdated Show resolved Hide resolved
@bryanhuhta bryanhuhta enabled auto-merge (squash) March 1, 2024 00:24
@bryanhuhta bryanhuhta merged commit bbb5f55 into main Mar 1, 2024
16 checks passed
@bryanhuhta bryanhuhta deleted the decode-panic branch March 1, 2024 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants