From 787bb3b3fa9792102d20a70cda4aa6691275c5dc Mon Sep 17 00:00:00 2001 From: Lucas Winther Date: Wed, 11 Nov 2026 19:57:18 +0100 Subject: [PATCH] protondrive: refuse to move or copy a file or folder whose key isn't verified Moving or copying a file or folder out of a folder with a forged key had rclone sign the server's key as the user's, after which it read without error. Moving, copying or renaming a node whose key isn't verified now fails unless ignore_signature_errors is set, and anything beneath such a folder, including what rclone writes there with the option set, stays unverified. Co-Authored-By: Claude Opus 5.5 --- backend/protondrive/nodes.go | 34 ++++++++++--- backend/protondrive/nodes_internal_test.go | 19 +++++++ backend/protondrive/protontest/drive.go | 43 ++++++++++++++++ backend/protondrive/security_test.go | 58 ++++++++++++++++++++++ docs/DECISIONS.md | 22 ++++++++ 5 files changed, 169 insertions(+), 7 deletions(-) diff --git a/backend/protondrive/nodes.go b/backend/protondrive/nodes.go index f345e2561..fbbfed600 100644 --- a/backend/protondrive/nodes.go +++ b/backend/protondrive/nodes.go @@ -435,9 +435,8 @@ func annotate(what string, err error) error { // SDK's decryptNode does. // // The node's key is unverified if its passphrase signature fails, or -// if it was checked against parent's key, as for an anonymous node, -// and parent's key is unverified: whoever made that key could have -// made this one too. +// if parent's key is unverified: whoever made that key can decrypt +// this one's passphrase, and, for an anonymous node, sign it. // // It returns unreadable, and no node, if the node has no ID, its name // or key can't be decrypted, its name isn't valid, its type is unknown @@ -486,9 +485,11 @@ func (c *client) decryptNode(ctx context.Context, d *api.LinkDetails, parent *no if err != nil { return nil, fmt.Errorf("%q: %w", truncateName(name), err), nil } - keys.unverified = keyVerifyErr - if keyVerifyErr == nil && parentVerifyKR != nil && l.SignatureEmail == "" && parent.unverified != nil { - keys.unverified = fmt.Errorf("signed with its folder's key, which is unverified: %w", parent.unverified) + switch { + case parent.unverified != nil: + keys.unverified = parent.unverified + case keyVerifyErr != nil: + keys.unverified = fmt.Errorf("the key of %q isn't signed by its owner: %w", truncateName(name), keyVerifyErr) } n = &node{ ID: l.LinkID, @@ -884,7 +885,7 @@ func (c *client) targetFolder(ctx context.Context, id string) (*node, error) { case n.keys.unverified != nil && !c.opt.IgnoreSignatureErrors: // Names and keys written into it would be encrypted to a key // the server may have made. - return nil, fmt.Errorf("folder %q: %w: its key isn't signed by its owner, so whoever made it could read what is written into it: %v: set ignore_signature_errors to write anyway", n.Name, errIntegrity, n.keys.unverified) + return nil, fmt.Errorf("folder %q: %w: its key isn't verified, so whoever made it could read what is written into it: %v: set ignore_signature_errors to write anyway", n.Name, errIntegrity, n.keys.unverified) } return n, nil } @@ -970,6 +971,8 @@ func (c *client) createFolder(ctx context.Context, parentID, name string, modTim } created = true + // Whoever holds the parent's key can decrypt the new one. + keys.unverified = parent.keys.unverified t := now if t.IsZero() { t = time.Now() @@ -1021,6 +1024,9 @@ func (c *client) rename(ctx context.Context, n *node, newName string) error { if err := validateName(newName); err != nil { return fmt.Errorf("%s: %w", what, err) } + if err := c.checkVerified(n); err != nil { + return fmt.Errorf("%s: %w", what, err) + } parent, err := c.targetFolder(ctx, n.ParentID) if err != nil { return fmt.Errorf("%s: %w", what, err) @@ -1053,6 +1059,16 @@ func (c *client) rename(ctx context.Context, n *node, newName string) error { return nil } +// checkVerified returns an error wrapping errIntegrity if n's key is +// unverified, unless IgnoreSignatureErrors is set, for an operation +// which would vouch for n. +func (c *client) checkVerified(n *node) error { + if n.keys.unverified == nil || c.opt.IgnoreSignatureErrors { + return nil + } + return fmt.Errorf("%w: %v: set ignore_signature_errors to change it anyway", errIntegrity, n.keys.unverified) +} + // newParentCrypto is a node's name and passphrase encrypted to a new // parent, for a move or copy. type newParentCrypto struct { @@ -1071,6 +1087,10 @@ type newParentCrypto struct { // reusing their session keys as the SDK's encryptNodeWithNewParent // does. func (c *client) encryptForNewParent(ctx context.Context, n *node, newParent *node, newName string) (*newParentCrypto, error) { + // An anonymous node's passphrase is signed anew as the client's. + if err := c.checkVerified(n); err != nil { + return nil, err + } oldParent, err := c.folderKeysOf(ctx, n.ParentID) if err != nil { return nil, err diff --git a/backend/protondrive/nodes_internal_test.go b/backend/protondrive/nodes_internal_test.go index a848cb3ff..b06066749 100644 --- a/backend/protondrive/nodes_internal_test.go +++ b/backend/protondrive/nodes_internal_test.go @@ -1143,3 +1143,22 @@ func TestDecryptNodeRefusesHostileValues(t *testing.T) { }) } } + +func TestCreatedUnderUnverifiedFolderStaysUnverified(t *testing.T) { + t.Parallel() + srv := protontest.New(t) + u := srv.AddUser("user", "pass") + forged := u.SeedForgedFolder(u.RootID(), "forged") + c := newTestClientFor(t, srv, u, clientOptions{EnableCaching: true, IgnoreSignatureErrors: true}) + ctx := context.Background() + + made, err := c.createFolder(ctx, forged, "made", time.Time{}) + require.NoError(t, err) + assert.Error(t, made.keys.unverified, "made in cache") + listed := listAll(t, c, forged) + require.Contains(t, listed, "made") + assert.Error(t, listed["made"].keys.unverified, "made in the cached listing") + fresh, err := c.fetchNode(ctx, made.ID) + require.NoError(t, err) + assert.Error(t, fresh.keys.unverified, "made read afresh") +} diff --git a/backend/protondrive/protontest/drive.go b/backend/protondrive/protontest/drive.go index 066203c72..6c1993195 100644 --- a/backend/protondrive/protontest/drive.go +++ b/backend/protondrive/protontest/drive.go @@ -754,6 +754,49 @@ func (u *User) SeedRevision(id string, content []byte, modTime time.Time) (revis return rev.id } +// ForgeShareCreator makes u's main share look created by signer, +// another user, as a hostile server could serve it: the creator email +// is signer's primary address and the share passphrase is signed by +// signer's key. It still decrypts with u's address key. +func (u *User) ForgeShareCreator(signer *User) { + v := u.view() + passphrase, err := decryptArmored(v.d.sharePass.armored, v.addrKey, nil, v.now) + mustCrypto("decrypt share passphrase", err) + signKey, email := signer.primaryAddressKey() + sig := signArmored(passphrase, signKey) + u.srv.mu.Lock() + defer u.srv.mu.Unlock() + d := u.mustDriveLocked() + d.creatorEmail = email + d.sharePass.signature = sig +} + +// ForgeRootSigner makes u's root folder look made by signer, another +// user, as a hostile server could serve it: its signature emails are +// signer's primary address and its name and node passphrase are signed +// by signer's key. +func (u *User) ForgeRootSigner(signer *User) { + v := u.view() + root := v.d.links[v.d.rootID] + shareKey, err := v.unlockShare() + if shareKey == nil { + mustCrypto("unlock share key", err) + } + passphrase, err := decryptArmored(root.nodePass.armored, shareKey, nil, v.now) + mustCrypto("decrypt root passphrase", err) + name, err := decryptArmored(root.name, shareKey, nil, v.now) + mustCrypto("decrypt root name", err) + signKey, email := signer.primaryAddressKey() + sig := signArmored(passphrase, signKey) + encName := encryptArmored(name, shareKey, signKey, false) + u.srv.mu.Lock() + defer u.srv.mu.Unlock() + l := u.mustDriveLocked().links[v.d.rootID] + l.signatureEmail, l.nameSignatureEmail = email, email + l.nodePass.signature = sig + l.name = encName +} + // insertLink adds an active link l under parentID and returns its new // ID, created now unless l has a creation time. It panics if parentID // has an active or draft child with the same name hash, which a seeding diff --git a/backend/protondrive/security_test.go b/backend/protondrive/security_test.go index ae635e312..404051102 100644 --- a/backend/protondrive/security_test.go +++ b/backend/protondrive/security_test.go @@ -247,6 +247,64 @@ func TestHostileServer(t *testing.T) { require.NoError(t, err, "upload with signature checks off") }) + t.Run("moving or copying out of a folder with a forged key", func(t *testing.T) { + ctx := context.Background() + remote, _, u := setupFakeRemote(t) + forged := u.SeedForgedFolder(u.RootID(), "forged") + u.SeedAnonymousFile(forged, "victim.bin", []byte("forged"), time.Now()) + nested := u.SeedAnonymousFolder(forged, "nested") + u.SeedAnonymousFile(nested, "deep.bin", []byte("forged"), time.Now()) + u.SeedFolder(u.RootID(), "real") + signed := u.SeedFile(u.RootID(), "signed.bin", []byte("forged"), time.Now()) + u.Corrupt(signed, "passphrase-signature") + + f := newFakeFs(t, remote, "") + victim, err := f.NewObject(ctx, "forged/victim.bin") + require.NoError(t, err) + _, err = operations.Move(ctx, f, nil, "real/victim.bin", victim) + require.Error(t, err, "moved out") + assert.Contains(t, err.Error(), "ignore_signature_errors") + _, err = operations.Copy(ctx, f, nil, "real/copied.bin", victim) + assert.Error(t, err, "copied out") + assert.Error(t, f.Features().DirMove(ctx, f, "forged/nested", "real/nested"), "folder moved out") + assert.Error(t, f.Features().DirMove(ctx, f, "forged", "real/forged"), "forged folder moved") + o, err := f.NewObject(ctx, "signed.bin") + require.NoError(t, err) + _, err = operations.Move(ctx, f, nil, "renamed.bin", o) + assert.Error(t, err, "renamed") + + f = newFakeFs(t, remote, "") + assert.Empty(t, mustList(ctx, t, f, "real"), "something reached real") + for _, path := range []string{"forged/victim.bin", "forged/nested/deep.bin", "signed.bin"} { + o, err := f.NewObject(ctx, path) + require.NoError(t, err, path) + _, err = readAll(ctx, o) + assert.Error(t, err, "%s became readable", path) + } + }) + + t.Run("what is written into a folder with a forged key stays unverified", func(t *testing.T) { + ctx := context.Background() + remote, _, u := setupFakeRemote(t) + u.SeedForgedFolder(u.RootID(), "forged") + ignoring := newFakeFs(t, strings.TrimSuffix(remote, ":")+",ignore_signature_errors=true:", "") + require.NoError(t, ignoring.Mkdir(ctx, "forged/made")) + src := object.NewMemoryObject("forged/made/file.txt", time.Now(), []byte("written")) + _, err := operations.Copy(ctx, ignoring, nil, src.Remote(), src) + require.NoError(t, err) + + // Whoever made the folder's key can read the keys of what is in + // it, however it is signed. + f := newFakeFs(t, remote, "") + o, err := f.NewObject(ctx, "forged/made/file.txt") + require.NoError(t, err) + _, err = readAll(ctx, o) + assert.Error(t, err, "read") + src = object.NewMemoryObject("forged/made/more.txt", time.Now(), []byte("secret")) + _, err = operations.Copy(ctx, f, nil, src.Remote(), src) + assert.Error(t, err, "uploaded") + }) + t.Run("updating a file with an attacker-signed passphrase", func(t *testing.T) { ctx := context.Background() remote, _, u := setupFakeRemote(t) diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index d500fe308..8399a5b1a 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -5,6 +5,28 @@ it with a new one that links back. One entry per decision a future maintainer would otherwise have to reverse-engineer. No index: `grep -n '^## ' docs/DECISIONS.md` lists every entry. +## 2026-11-11 - Proton Drive won't vouch for a node it couldn't verify + +**Status:** accepted +**Context:** Refusing writes into a folder with an unverified key left +the other direction open: moving or copying an anonymous node out of it +has rclone sign its server-made passphrase as the user's, after which it +and everything beneath it verified (Task 16 re-review). And a node made +under such a folder with `ignore_signature_errors` set was signed by the +user, so verified later, although whoever made the folder's key can +decrypt its passphrase. +**Decision:** Supersedes the inheritance rule of "Proton Drive distrusts +what a forged folder key vouches for": every node beneath a folder with +an unverified key is unverified, however it is signed, and so is a +folder rclone makes there. Moving, copying, directory-moving or +renaming a node whose key is unverified fails unless +`ignore_signature_errors` is set. +**Alternatives:** Inheriting only into anonymous nodes (leaves the +user-signed children of a forged folder trusted). +**Consequences:** A genuine folder whose key fails to verify, as one +signed by a since-deleted address, makes its whole subtree unreadable +and unwritable without `ignore_signature_errors`. + ## 2026-11-11 - Proton Drive verifies the manifest before releasing a full read **Status:** accepted