diff --git a/backend/protondrive/account_internal_test.go b/backend/protondrive/account_internal_test.go index 37b68d12c..ad38fd606 100644 --- a/backend/protondrive/account_internal_test.go +++ b/backend/protondrive/account_internal_test.go @@ -2,9 +2,9 @@ package protondrive import ( "context" + "strings" "sync" "sync/atomic" - "strings" "testing" "time" diff --git a/backend/protondrive/download.go b/backend/protondrive/download.go index 940ce6410..799199a09 100644 --- a/backend/protondrive/download.go +++ b/backend/protondrive/download.go @@ -180,8 +180,11 @@ func blockAt(sizes []int64, pos int64) (index int, offset int64) { // 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.keys.unverified != nil && !c.opt.IgnoreSignatureErrors { - return nil, fmt.Errorf("node key: %w: %w: %s", errIntegrity, n.keys.unverified, signatureHint) + if n.keys.unverified != nil { + if !c.opt.IgnoreSignatureErrors { + return nil, fmt.Errorf("node key: %w: %w: %s", errIntegrity, n.keys.unverified, signatureHint) + } + c.reportUnverified("reading", n, "") } f := n.link.File now := c.s.serverTime() diff --git a/backend/protondrive/nodes.go b/backend/protondrive/nodes.go index 24ea2c810..1cd417dee 100644 --- a/backend/protondrive/nodes.go +++ b/backend/protondrive/nodes.go @@ -903,10 +903,25 @@ func (c *client) targetFolder(ctx context.Context, id string) (*node, error) { // 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 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) + case n.keys.unverified != nil: + c.reportUnverified("writing into", n, "whoever made its key can read what is written") } return n, nil } +// reportUnverified logs, once per op and node, that op goes ahead on +// node n although its key is unverified, as IgnoreSignatureErrors +// allows, with the consequence if not empty. +func (c *client) reportUnverified(op string, n *node, consequence string) { + c.reportOnce("unverified "+op, n.ID, func() { + msg := fmt.Sprintf("protondrive: %s %q (ID %s) although its key isn't verified", op, n.Name, n.ID) + if consequence != "" { + msg += ", so " + consequence + } + fs.Errorf(nil, "%s: %v", msg, n.keys.unverified) + }) +} + // forget drops node id and the listings of parentIDs from the cache. func (c *client) forget(id string, parentIDs ...string) { c.cache.invalidate(id) @@ -1041,7 +1056,7 @@ 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 { + if err := c.checkVerified("renaming", n); err != nil { return fmt.Errorf("%s: %w", what, err) } parent, err := c.targetFolder(ctx, n.ParentID) @@ -1077,10 +1092,14 @@ func (c *client) rename(ctx context.Context, n *node, newName string) error { } // 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 { +// unverified, for op, an operation which would vouch for n. If +// IgnoreSignatureErrors is set it logs that instead. +func (c *client) checkVerified(op string, n *node) error { + switch { + case n.keys.unverified == nil: + return nil + case c.opt.IgnoreSignatureErrors: + c.reportUnverified(op, n, "it is trusted from now on") return nil } return fmt.Errorf("%w: %v: set ignore_signature_errors to change it anyway", errIntegrity, n.keys.unverified) @@ -1102,10 +1121,10 @@ type newParentCrypto struct { // encryptForNewParent returns the name newName and the passphrase of n // encrypted to folder newParent and signed by the client's address, // 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) { +// does, for op, a move or copy. +func (c *client) encryptForNewParent(ctx context.Context, op string, 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 { + if err := c.checkVerified(op, n); err != nil { return nil, err } oldParent, err := c.folderKeysOf(ctx, n.ParentID) @@ -1152,7 +1171,7 @@ func (c *client) move(ctx context.Context, n *node, newParentID, newName string) if err != nil { return fmt.Errorf("%s: %w", what, err) } - enc, err := c.encryptForNewParent(ctx, n, newParent, newName) + enc, err := c.encryptForNewParent(ctx, "moving", n, newParent, newName) if err != nil { return fmt.Errorf("%s: %w", what, err) } @@ -1193,7 +1212,7 @@ func (c *client) copyNode(ctx context.Context, n *node, newParentID, newName str if err != nil { return nil, fmt.Errorf("%s: %w", what, err) } - enc, err := c.encryptForNewParent(ctx, n, newParent, newName) + enc, err := c.encryptForNewParent(ctx, "copying", n, newParent, newName) if err != nil { return nil, fmt.Errorf("%s: %w", what, err) } diff --git a/backend/protondrive/security_test.go b/backend/protondrive/security_test.go index c583bca0c..4330d4602 100644 --- a/backend/protondrive/security_test.go +++ b/backend/protondrive/security_test.go @@ -447,6 +447,58 @@ func TestHostileServer(t *testing.T) { assert.Zero(t, srv.Requests()["GET /core/v4/keys/all"], "the server was asked for the user's own keys") }) + t.Run("what signature checks off let through on unverified nodes is logged", func(t *testing.T) { + ctx := context.Background() + remote, _, u := setupFakeRemote(t) + forged := u.SeedForgedFolder(u.RootID(), "forged") + victimID := u.SeedAnonymousFile(forged, "victim.bin", []byte("forged"), time.Now()) + u.SeedAnonymousFile(forged, "other.bin", []byte("forged"), time.Now()) + u.SeedFolder(u.RootID(), "real") + mineID := u.SeedFile(u.RootID(), "mine.txt", []byte("mine"), time.Now()) + f := newFakeFs(t, strings.TrimSuffix(remote, ":")+",ignore_signature_errors=true:", "") + capture := captureLog(t, 0) + + for range 2 { + o, err := f.NewObject(ctx, "forged/victim.bin") + require.NoError(t, err) + _, err = readAll(ctx, o) + require.NoError(t, err) + } + for _, name := range []string{"a.txt", "b.txt"} { + src := object.NewMemoryObject("forged/"+name, time.Now(), []byte("x")) + _, err := operations.Copy(ctx, f, nil, src.Remote(), src) + require.NoError(t, err) + } + other, err := f.NewObject(ctx, "forged/other.bin") + require.NoError(t, err) + _, err = operations.Copy(ctx, f, nil, "real/other.bin", other) + require.NoError(t, err) + victim, err := f.NewObject(ctx, "forged/victim.bin") + require.NoError(t, err) + _, err = operations.Move(ctx, f, nil, "real/victim.bin", victim) + require.NoError(t, err) + mine, err := f.NewObject(ctx, "mine.txt") + require.NoError(t, err) + _, err = readAll(ctx, mine) + require.NoError(t, err) + _, err = operations.Copy(ctx, f, nil, "real/mine.txt", mine) + require.NoError(t, err) + + log := capture.String() + const unverified = "although its key isn't verified" + for _, want := range []string{ + `ERROR : protondrive: reading "victim.bin" (ID ` + victimID + `) ` + unverified, + `ERROR : protondrive: writing into "forged" (ID ` + forged + `) ` + unverified, + `ERROR : protondrive: copying "other.bin"`, + `ERROR : protondrive: moving "victim.bin" (ID ` + victimID + `) ` + unverified, + } { + assert.Equal(t, 1, strings.Count(log, want), "%q logged other than once in:\n%s", want, log) + } + assert.Contains(t, log, "trusted from now on") + assert.NotContains(t, log, mineID, "a verified file was reported") + assert.Equal(t, 4, strings.Count(log, unverified), log) + }) + 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 3c9212854..d5ac110c4 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -5,6 +5,23 @@ 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 logs what ignore_signature_errors lets through + +**Status:** accepted +**Context:** With `ignore_signature_errors` set, reads, writes, moves, +copies and renames of nodes whose keys are unverified went ahead +silently, although spec 6.4 promises a logged ERROR (Task 16 re-review +2). +**Decision:** Each such operation logs one ERROR per node and kind of +operation for the life of the `Fs`, naming the node, its ID, the +operation and why its key is unverified. Completes "Proton Drive won't +vouch for a node it couldn't verify". +**Alternatives:** Logging every call (floods a sync); a NOTICE (too +easily missed for something permanent). +**Consequences:** With the option set, moving or copying a node out of +an unverified folder re-signs or re-homes it as the user's, so it is +trusted from then on; the ERROR says so. + ## 2026-11-11 - Proton Drive matches email addresses by ASCII case only **Status:** accepted