Skip to content

fix: bounds check before slicing decrypted AES-CBC data#103

Open
travis-barnett wants to merge 1 commit intobrowserutils:masterfrom
travis-barnett:fix/aescbc-slice-bounds-check
Open

fix: bounds check before slicing decrypted AES-CBC data#103
travis-barnett wants to merge 1 commit intobrowserutils:masterfrom
travis-barnett:fix/aescbc-slice-bounds-check

Conversation

@travis-barnett
Copy link

Summary

For Chrome db version >= 24, decryptAESCBC strips 32 bytes of prefix padding from the decrypted data. If the decrypted value is shorter than the prefix padding (e.g. empty or very short cookie values), this causes a panic:

panic: runtime error: slice bounds out of range [32:23]

goroutine 1830 [running]:
github.com/browserutils/kooky/internal/chrome.decryptAESCBC(...)
    internal/chrome/chrome.go:356 +0x404

This adds a bounds check to return an error instead of panicking, allowing the iterator to skip the bad cookie gracefully.

Change

Added a check before the final slice in decryptAESCBC():

if len(decrypted)-paddingLen < prefixPaddingLen {
    return nil, fmt.Errorf("decrypted data too short (%d bytes) for prefix padding (%d bytes)", len(decrypted)-paddingLen, prefixPaddingLen)
}

This is a follow-up to commit 00fc21c which fixed the similar crypto/cipher: input not full blocks panic.

🤖 Generated with Claude Code

For Chrome db version >= 24, decryptAESCBC strips 32 bytes of prefix
padding from the decrypted data. If the decrypted value is shorter than
the prefix padding (e.g. empty or very short cookie values), this causes
a panic: slice bounds out of range [32:N] where N < 32.

Add a bounds check to return an error instead of panicking, allowing the
iterator to skip the bad cookie gracefully.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@daboyuka
Copy link

This is a secondary edge case bug in the fix for #92 .

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.

2 participants