protondrive: refuse oversized encrypted names before decrypting them
An uncompressed encrypted name, passphrase, hash key or extended attributes far larger than the limit for its kind was decrypted into memory in full before being refused; one of 10 MiB took about 230 MiB to list. It is now refused by its size first. Also wrap the error for folders nested too deep once rather than at every level, where a hostile server could make it about 88 KB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a066fa3e39
commit
c1aa97fe34
5 files changed
+24
-5
No files matched your search
@@ -214,8 +214,14 @@ const (
|
||||
// verifyKR alone, and any failure returned as verifyErr; a nil verifyKR
|
||||
// checks it against no key, so verifyErr is set. A compressed message
|
||||
// which expands to more than maxSize bytes, counting the packet headers
|
||||
// and signatures inside it, is an error.
|
||||
// and signatures inside it, is an error, and so is an armored message
|
||||
// too large to hold at most maxSize bytes uncompressed.
|
||||
func decryptMessage(armored string, decKR, verifyKR *crypto.KeyRing, now time.Time, maxSize int64) (res *crypto.VerifiedDataResult, sk *crypto.SessionKey, verifyErr, err error) {
|
||||
// Armor takes 4/3 of the binary size and line breaks; the rest is
|
||||
// room for the key packets.
|
||||
if maxArmored := 2*maxSize + 64<<10; int64(len(armored)) > maxArmored {
|
||||
return nil, nil, nil, fmt.Errorf("message is larger than %d bytes", maxArmored)
|
||||
}
|
||||
msg, err := crypto.NewPGPMessageFromArmored(armored)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
|
||||
@@ -895,6 +895,13 @@ func TestDecryptedSizeBounded(t *testing.T) {
|
||||
assert.Equal(t, int64(7), x.Size)
|
||||
_, _, err = decryptXAttrs(compressed(padded(`{"Common":{"Size":7}}`, maxXAttrsSize+1)), parent, signerPub, now)
|
||||
assert.Error(t, err)
|
||||
|
||||
// An uncompressed message far over the limit is refused before it
|
||||
// is decrypted into memory.
|
||||
huge, err := encryptArmored(padded("name", 4*maxSmallMessageSize), nil, parent, signer, false, now)
|
||||
require.NoError(t, err)
|
||||
_, _, err = decryptName(huge, parent, signerPub, now)
|
||||
assert.ErrorContains(t, err, "larger than")
|
||||
}
|
||||
|
||||
func TestServerTimeUsedForSignatures(t *testing.T) {
|
||||
|
||||
@@ -744,6 +744,12 @@ func (c *client) fetchNodeIn(ctx context.Context, id string, below []string) (*n
|
||||
}
|
||||
parent, err := c.folderKeysIn(ctx, d.Link.ParentLinkID, append(below[:len(below):len(below)], id))
|
||||
if err != nil {
|
||||
if len(below) > 0 {
|
||||
// Wrapped once, by the node asked for: at every level
|
||||
// of a chain a server can make 2048 deep, it would
|
||||
// grow without bound.
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("get node %s: %w", id, err)
|
||||
}
|
||||
n, unreadable, err := c.decryptNode(ctx, &d, parent)
|
||||
|
||||
@@ -1318,6 +1318,10 @@ func TestFolderDepthLimit(t *testing.T) {
|
||||
_, err := c.getNode(context.Background(), ids[5])
|
||||
require.ErrorIs(t, err, errIntegrity)
|
||||
assert.Contains(t, err.Error(), "more than 4 deep")
|
||||
// The error names the node asked for and the one too deep, not
|
||||
// every folder between, which a hostile server could make 2048.
|
||||
assert.Equal(t, 2, strings.Count(err.Error(), "get node"), err.Error())
|
||||
assert.True(t, strings.HasPrefix(err.Error(), "get node "+ids[5]+": "), err.Error())
|
||||
// Within the limit is fine.
|
||||
c = newTestClientFor(t, srv, u, clientOptions{})
|
||||
c.maxFolderDepth = 6
|
||||
|
||||
@@ -111,10 +111,6 @@ Small, specific, independently actionable. Remove only when actually done.
|
||||
read with only an `ERROR` logged (spec 6.2, the SDK's behaviour), and
|
||||
names aren't bound to their node, so a server can swap the encrypted
|
||||
names of two files in one folder undetected. Raise with Proton.
|
||||
- [ ] protondrive: a hostile 10 MiB name is decrypted in full before
|
||||
`validateName` rejects it (about 230 MiB allocated listing it, the
|
||||
fake included). Consider refusing an encrypted name over a few KiB
|
||||
before decrypting it.
|
||||
|
||||
- [ ] lib/pacer: `TokenDispenser.Get` takes no context, so a cancelled
|
||||
protondrive block download still waits for a download token (held by
|
||||
|
||||
Reference in new issue
Block a user