protondrive: distrust files and folders beneath a folder with a forged key

A server could put a folder with a key of its own making into a real
folder and serve anonymous files beneath it whose every signature
checked out against that key, so they were read without an error.
A key checked against an unverified folder key is now unverified too,
all the way down: reading such a file, or creating, uploading, moving
or copying anything into such a folder, fails unless
ignore_signature_errors is set. Listing it still works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Opus 5.5 committed 2026-11-11 18:48:11 +01:00
1 parent f4105adfc1
commit 88654eb04d
8 files changed
+176 -35

No files matched your search

+1
View File
@@ -330,6 +330,7 @@ type nodeKeys struct {
keyRing *crypto.KeyRing
passphrase []byte // base64 text locking the key
passphraseSessionKey *crypto.SessionKey // session key of the encrypted passphrase
unverified error // why the key may not be its owner's; nil if its signature verified
}
// generateNodeKeys returns a new node key, armored and locked with a
+4 -5
View File
@@ -166,12 +166,11 @@ func blockAt(sizes []int64, pos int64) (index int, offset int64) {
// contentKey returns the content session key of file n, checking its
// signature as the SDK's decryptContentKeyPacket does.
//
// A node passphrase signature which failed is errIntegrity too: a key
// someone else made could decrypt any content they chose.
// An unverified node key is errIntegrity too: a key someone else made
// could decrypt any content they chose.
func (c *client) contentKey(n *node) (*crypto.SessionKey, error) {
if n.keyErr != nil && !c.opt.IgnoreSignatureErrors {
// decryptNode has logged it.
return nil, fmt.Errorf("node key: %w: %w: %s", errIntegrity, n.keyErr, signatureHint)
if n.keys.unverified != nil && !c.opt.IgnoreSignatureErrors {
return nil, fmt.Errorf("node key: %w: %w: %s", errIntegrity, n.keys.unverified, signatureHint)
}
f := n.link.File
now := c.s.serverTime()
+35 -20
View File
@@ -116,7 +116,6 @@ type node struct {
keys *nodeKeys
hashKey []byte // folders only; nil if it can't be decrypted
keyVerifyKR *crypto.KeyRing // verifies the node's key and content key signatures
keyErr error // why the node passphrase signature failed; nil if it verified
link *api.LinkDetails // the encrypted metadata
}
@@ -337,9 +336,10 @@ func (c *client) bootstrap(ctx context.Context) error {
}
c.shareKeys = shareKeys
if verifyErr != nil {
shareKeys.unverified = verifyErr
fs.Errorf(nil, "protondrive: share %s: signature check of the share key failed: %v", my.Share.ShareID, verifyErr)
}
root, unreadable, err := c.decryptNode(ctx, &my.Link, shareKeys.keyRing)
root, unreadable, err := c.decryptNode(ctx, &my.Link, shareKeys)
if err == nil && unreadable == nil && !root.IsFolder {
unreadable = errors.New("not a folder")
}
@@ -430,17 +430,23 @@ func annotate(what string, err error) error {
return fmt.Errorf("%s: %w", what, err)
}
// decryptNode decrypts the metadata d of a node whose parent's key is
// parentKR, choosing the keys which verify each signature as the
// decryptNode decrypts the metadata d of a node whose parent's keys
// are parent, choosing the keys which verify each signature as the
// 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.
//
// It returns unreadable, and no node, if the node's name or key can't
// be decrypted, its name isn't valid or its type is unknown. err is
// set only if the verification keys can't be had. Failed signature
// checks, and extended attributes or hash key which can't be
// decrypted, are logged once per node.
func (c *client) decryptNode(ctx context.Context, d *api.LinkDetails, parentKR *crypto.KeyRing) (n *node, unreadable, err error) {
func (c *client) decryptNode(ctx context.Context, d *api.LinkDetails, parent *nodeKeys) (n *node, unreadable, err error) {
l := &d.Link
parentKR := parent.keyRing
now := c.s.serverTime()
// An anonymous node is signed with its parent's key, which a root
@@ -476,6 +482,10 @@ func (c *client) decryptNode(ctx context.Context, d *api.LinkDetails, parentKR *
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)
}
n = &node{
ID: l.LinkID,
ParentID: l.ParentLinkID,
@@ -485,7 +495,6 @@ func (c *client) decryptNode(ctx context.Context, d *api.LinkDetails, parentKR *
ServerModTime: time.Unix(l.ModifyTime, 0),
keys: keys,
keyVerifyKR: keyVerifyKR,
keyErr: keyVerifyErr,
link: d,
}
verifyErrs := []error{annotate("name", nameVerifyErr), annotate("node key", keyVerifyErr)}
@@ -577,13 +586,13 @@ func (c *client) rememberKeys(n *node) {
c.folderKeys[n.ID] = n.keys
}
// folderKeyRing returns the node key of folder id.
func (c *client) folderKeyRing(ctx context.Context, id string) (*crypto.KeyRing, error) {
// folderKeysOf returns the node keys of folder id.
func (c *client) folderKeysOf(ctx context.Context, id string) (*nodeKeys, error) {
c.mu.Lock()
keys := c.folderKeys[id]
c.mu.Unlock()
if keys != nil {
return keys.keyRing, nil
return keys, nil
}
n, err := c.getNode(ctx, id)
if err != nil {
@@ -592,7 +601,7 @@ func (c *client) folderKeyRing(ctx context.Context, id string) (*crypto.KeyRing,
if !n.IsFolder {
return nil, fmt.Errorf("node %s is not a folder", id)
}
return n.keys.keyRing, nil
return n.keys, nil
}
// fetchLinks returns the metadata of the nodes ids, at most
@@ -633,11 +642,11 @@ func (c *client) fetchNode(ctx context.Context, id string) (*node, error) {
if d.Link.ParentLinkID == "" {
return nil, fmt.Errorf("get node %s: not in the drive", id)
}
parentKR, err := c.folderKeyRing(ctx, d.Link.ParentLinkID)
parent, err := c.folderKeysOf(ctx, d.Link.ParentLinkID)
if err != nil {
return nil, fmt.Errorf("get node %s: %w", id, err)
}
n, unreadable, err := c.decryptNode(ctx, &d, parentKR)
n, unreadable, err := c.decryptNode(ctx, &d, parent)
if err == nil {
err = unreadable
}
@@ -692,7 +701,7 @@ func (c *client) listChildren(ctx context.Context, parentID string, fn func([]*n
}
return fn(nodes)
}
parentKR, err := c.folderKeyRing(ctx, parentID)
parent, err := c.folderKeysOf(ctx, parentID)
if err != nil {
return fmt.Errorf("list %s: %w", parentID, err)
}
@@ -705,7 +714,7 @@ func (c *client) listChildren(ctx context.Context, parentID string, fn func([]*n
)
fetch := func(ids []string) {
g.Go(func() error {
nodes, err := c.decryptChildren(gCtx, parentID, parentKR, ids)
nodes, err := c.decryptChildren(gCtx, parentID, parent, ids)
if err != nil {
return err
}
@@ -765,9 +774,9 @@ func (c *client) listChildren(ctx context.Context, parentID string, fn func([]*n
}
// decryptChildren fetches and decrypts the children ids of folder
// parentID, whose key is parentKR, leaving out those which are not
// parentID, whose keys are parent, leaving out those which are not
// listed.
func (c *client) decryptChildren(ctx context.Context, parentID string, parentKR *crypto.KeyRing, ids []string) ([]*node, error) {
func (c *client) decryptChildren(ctx context.Context, parentID string, parent *nodeKeys, ids []string) ([]*node, error) {
links, err := c.fetchLinks(ctx, ids)
if err != nil {
return nil, err
@@ -777,7 +786,7 @@ func (c *client) decryptChildren(ctx context.Context, parentID string, parentKR
if !c.listable(&d, parentID) {
continue
}
n, unreadable, err := c.decryptNode(ctx, &d, parentKR)
n, unreadable, err := c.decryptNode(ctx, &d, parent)
if err != nil {
return nil, err
}
@@ -853,8 +862,9 @@ func mutationError(what string, err error) error {
return fmt.Errorf("%s: %w", what, err)
}
// targetFolder returns folder id to put a node in, which must have a
// readable hash key.
// targetFolder returns folder id to put or name a node in, which must
// have a readable hash key, and a verified key unless
// IgnoreSignatureErrors is set.
func (c *client) targetFolder(ctx context.Context, id string) (*node, error) {
n, err := c.getNode(ctx, id)
switch {
@@ -864,6 +874,10 @@ func (c *client) targetFolder(ctx context.Context, id string) (*node, error) {
return nil, fmt.Errorf("node %s is not a folder", id)
case n.hashKey == nil:
return nil, fmt.Errorf("folder %s has no readable hash key", id)
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 n, nil
}
@@ -1050,10 +1064,11 @@ 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) {
oldParentKR, err := c.folderKeyRing(ctx, n.ParentID)
oldParent, err := c.folderKeysOf(ctx, n.ParentID)
if err != nil {
return nil, err
}
oldParentKR := oldParent.keyRing
signKR, err := c.addr.signingKeyRing()
if err != nil {
return nil, err
+28 -4
View File
@@ -501,19 +501,43 @@ type seedSpec struct {
// the SDK would, and returns its ID.
func (u *User) SeedFolder(parentID, name string) (id string) {
v := u.view()
return u.seedFolder(v, parentID, name, v.addrKey, v.email)
}
// SeedAnonymousFolder is SeedFolder as an anonymous uploader to a
// public link would: no signature emails, and the name and node
// passphrase signed by the parent's node key.
func (u *User) SeedAnonymousFolder(parentID, name string) (id string) {
v := u.view()
parentKey, _ := v.folderKeys(parentID)
return u.seedFolder(v, parentID, name, parentKey, "")
}
// SeedForgedFolder creates folder name in parentID as a hostile server
// could: with a node key of its own making whose passphrase is
// encrypted to the parent's key, and the name and passphrase signed by
// a key of its own, with no signature emails. Anonymous children seeded
// into it verify against that key.
func (u *User) SeedForgedFolder(parentID, name string) (id string) {
return u.seedFolder(u.view(), parentID, name, generateKey("impostor", "impostor@proton.test"), "")
}
// seedFolder creates folder name in parentID with its name and node
// passphrase signed by signer as email, and returns its ID.
func (u *User) seedFolder(v *driveView, parentID, name string, signer *crypto.Key, email string) string {
parentKey, parentHashKey := v.folderKeys(parentID)
node := newDriveKey(false)
u.srv.rememberKey(node)
pass := sealPassphrase(node.passphrase, parentKey, v.addrKey)
pass := sealPassphrase(node.passphrase, parentKey, signer)
_, hashKey := newHashKey(node.key)
return u.insertLink(parentID, &link{
typ: linkTypeFolder,
name: encryptArmored([]byte(name), parentKey, v.addrKey, false),
name: encryptArmored([]byte(name), parentKey, signer, false),
nameHash: lookupHash(parentHashKey, name),
nodeKey: node.armored,
nodePass: pass,
signatureEmail: v.email,
nameSignatureEmail: v.email,
signatureEmail: email,
nameSignatureEmail: email,
hashKey: hashKey,
})
}
@@ -591,6 +591,26 @@ func TestSeedRevision(t *testing.T) {
}
}
func TestSeedForgedFolder(t *testing.T) {
s := New(t)
u := s.AddUser("user", "pass")
forged := u.SeedForgedFolder(u.RootID(), "forged")
nested := u.SeedAnonymousFolder(forged, "nested")
file := u.SeedAnonymousFile(nested, "file", []byte("forged content"), time.Now())
for _, n := range u.Dump() {
switch n.ID {
case forged:
assert.Error(t, n.Err, "the forged key's signature verifies")
case nested, file:
assert.NoError(t, n.Err, n.Path)
}
if n.ID == file {
assert.Equal(t, "forged/nested/file", n.Path)
assert.Equal(t, "forged content", string(n.Content))
}
}
}
func TestNodeSecrets(t *testing.T) {
s := New(t)
u := s.AddUser("user", "pass")
+62 -6
View File
@@ -73,9 +73,10 @@ func requireCopyFails(ctx context.Context, t *testing.T, src fs.Fs, remote strin
// hostileContent is a file whose content a hostile server tampers with.
type hostileContent struct {
name string
path string // of the file; victim.bin if empty
content []byte
// prepare seeds the file in u's root and tampers with it,
// returning its ID.
// prepare seeds the file at path and tampers with it, returning
// its ID.
prepare func(u *protontest.User, content []byte) string
// signatureOnly is set if only a signature check catches the
// tampering, which ignore_signature_errors turns off.
@@ -146,6 +147,24 @@ var hostileContents = []hostileContent{{
content: patternedContent(100, 10),
prepare: seedCorrupted("passphrase-signature"),
signatureOnly: true,
}, {
name: "anonymous file in a folder with a forged key",
path: "forged/victim.bin",
content: patternedContent(100, 11),
prepare: func(u *protontest.User, content []byte) string {
forged := u.SeedForgedFolder(u.RootID(), "forged")
return u.SeedAnonymousFile(forged, "victim.bin", content, time.Now())
},
signatureOnly: true,
}, {
name: "anonymous file nested in a folder with a forged key",
path: "forged/nested/victim.bin",
content: patternedContent(100, 12),
prepare: func(u *protontest.User, content []byte) string {
nested := u.SeedAnonymousFolder(u.SeedForgedFolder(u.RootID(), "forged"), "nested")
return u.SeedAnonymousFile(nested, "victim.bin", content, time.Now())
},
signatureOnly: true,
}}
// hostileNames are names a hostile server gives nodes, each of which
@@ -161,20 +180,24 @@ func TestHostileServer(t *testing.T) {
ctx := context.Background()
remote, _, u := setupFakeRemote(t)
tc.prepare(u, tc.content)
path := tc.path
if path == "" {
path = "victim.bin"
}
f := newFakeFs(t, remote, "")
o, err := f.NewObject(ctx, "victim.bin")
o, err := f.NewObject(ctx, path)
require.NoError(t, err, "the file is listed")
got, err := readAll(ctx, o)
require.Error(t, err, "read without error")
assert.LessOrEqual(t, len(got), tc.released, "bytes released before the error")
assert.False(t, bytes.Equal(got, tc.content), "the content was returned")
requireCopyFails(ctx, t, f, "victim.bin")
requireCopyFails(ctx, t, f, path)
// Turning signature checks off leaves the integrity
// checks, and the hash check of a copy.
f = newFakeFs(t, strings.TrimSuffix(remote, ":")+",ignore_signature_errors=true:", "")
o, err = f.NewObject(ctx, "victim.bin")
o, err = f.NewObject(ctx, path)
require.NoError(t, err)
got, err = readAll(ctx, o)
if !tc.signatureOnly {
@@ -186,10 +209,43 @@ func TestHostileServer(t *testing.T) {
// is the file's.
return
}
requireCopyFails(ctx, t, f, "victim.bin")
requireCopyFails(ctx, t, f, path)
})
}
t.Run("writing into a folder with a forged key", func(t *testing.T) {
ctx := context.Background()
remote, _, u := setupFakeRemote(t)
nested := u.SeedAnonymousFolder(u.SeedForgedFolder(u.RootID(), "forged"), "nested")
u.SeedAnonymousFile(nested, "existing.bin", []byte("forged"), time.Now())
u.SeedFile(u.RootID(), "mine.txt", []byte("mine"), time.Now())
before := len(u.Dump())
f := newFakeFs(t, remote, "")
for _, dir := range []string{"forged", "forged/nested"} {
src := object.NewMemoryObject(dir+"/new.txt", time.Now(), []byte("secret"))
_, err := operations.Copy(ctx, f, nil, src.Remote(), src)
require.Error(t, err, "uploaded into %s", dir)
assert.Contains(t, err.Error(), "ignore_signature_errors")
assert.Error(t, f.Mkdir(ctx, dir+"/sub"), "made a folder in %s", dir)
mine, err := f.NewObject(ctx, "mine.txt")
require.NoError(t, err)
_, err = operations.Copy(ctx, f, nil, dir+"/copied.txt", mine)
assert.Error(t, err, "copied into %s", dir)
_, err = operations.Move(ctx, f, nil, dir+"/moved.txt", mine)
assert.Error(t, err, "moved into %s", dir)
}
existing, err := f.NewObject(ctx, "forged/nested/existing.bin")
require.NoError(t, err)
assert.Error(t, existing.Update(ctx, bytes.NewReader([]byte("secret")), object.NewStaticObjectInfo("forged/nested/existing.bin", time.Now(), 6, true, nil, nil)), "updated a file there")
assert.Len(t, u.Dump(), before, "something was written")
f = newFakeFs(t, strings.TrimSuffix(remote, ":")+",ignore_signature_errors=true:", "")
src := object.NewMemoryObject("forged/new.txt", time.Now(), []byte("allowed"))
_, err = operations.Copy(ctx, f, nil, src.Remote(), src)
require.NoError(t, err, "upload with signature checks off")
})
t.Run("names", func(t *testing.T) {
// Its own stats, so the sync sees only its own errors.
ctx := accounting.WithStatsGroup(context.Background(), "hostile names")
+21
View File
@@ -5,6 +5,27 @@ 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 distrusts what a forged folder key vouches for
**Status:** accepted
**Context:** An anonymous node's passphrase, name and content signatures
are checked against its parent folder's key. A server can make a folder
key of its own, seal it to the real parent and sign everything beneath
it, so a refusal based only on each node's own signature check is
bypassed (Task 16 review).
**Decision:** A node key is unverified if its own passphrase signature
fails, or if it was checked against an unverified parent key; this
passes down the tree. Reading a file with an unverified key, and
creating, uploading, renaming, moving or copying into a folder with
one, fail unless `ignore_signature_errors` is set. Listing such a folder
still works, with one ERROR for the folder itself.
**Alternatives:** Leaving the folder's children to their own checks
(bypassable); refusing to list the folder (a sync would delete its
destination copy).
**Consequences:** Builds on the 2026-11-11 entry "Proton Drive refuses a
file whose node key signature fails". Files in a public-link upload
folder whose key fails to verify need `ignore_signature_errors`.
## 2026-11-11 - Proton Drive refuses a file whose node key signature fails
**Status:** accepted
+5
View File
@@ -580,6 +580,11 @@ library what must stay readable.
`func (s *Server) IssuedSecrets() []string` (every access and refresh
token, fork selector and block upload or download token issued) and
`func (u *User) NodeSecrets(id string) (passphrase, sessionKey []byte)`.
- Hostile folder keys (Task 16 fix round):
`func (u *User) SeedForgedFolder(parentID, name string) (id string)`
(a server-made node key sealed to the real parent, signed by a key of
the server's) and
`func (u *User) SeedAnonymousFolder(parentID, name string) (id string)`.
- `func (u *User) Dump() []DumpedNode` - decrypted tree for assertions
(`ID`, `Path`, `IsFolder`, `Content`, `ModTime`, `SHA1`, `State`, and
`Err` joining every decryption, signature, block-hash, manifest and