fix(memory): refuse a credential written out in prose (#2069)

A note saying "the deploy token is 1234567890abcdef" was neither redacted nor
refused, because the credential check only recognised a value after a colon or
an equals sign. The copula now counts as the separator, so a credential written
out in a sentence is refused the way an assignment is.

The version read is scoped to the organisation as every other note read is, so a
note id from another organisation answers nothing, and the doc comments on
Forget and Revoke describe the order the code actually commits in. The
deletion-recording schema constant had no consumer and is removed.
This commit is contained in:
sam committed 2026-11-27 18:25:20 +11:00
1 parent 368d484410
commit aa3568dd52
7 files changed
+135 -31

No files matched your search

+10 -13
View File
@@ -23,11 +23,6 @@ const maxNotes = 200
// notesTable names the table a recorded deletion applies to.
const notesTable = "memory.notes"
// DeletionsRecordedSince is the schema version from which this binary records
// note deletions outside the database. A restore onto a database at or above it
// must find that record: without it, deleted notes come back.
const DeletionsRecordedSince int64 = 41
// Class is one of the four memory classes. Each is read, written and retained
// on its own terms: a working context belongs to a session, episodic history and
// enterprise retrieval to a collection, and a durable fact to a person or to the
@@ -193,7 +188,7 @@ type sharedStore interface {
Pending(ctx context.Context, orgID string, limit int) ([]store.Note, error)
Shared(ctx context.Context, orgID, class string, limit int) ([]store.Note, error)
Publish(ctx context.Context, orgID string, id uuid.UUID, publisher string) (store.Note, bool, error)
Versions(ctx context.Context, noteID uuid.UUID) ([]store.Version, error)
Versions(ctx context.Context, orgID string, noteID uuid.UUID) ([]store.Version, error)
Rollback(ctx context.Context, orgID string, id uuid.UUID, version int, publisher string) (store.Note, bool, error)
CommitSharedDeletion(ctx context.Context, orgID string, id uuid.UUID) (bool, error)
}
@@ -284,9 +279,10 @@ func (m *Module) Disable(ctx context.Context, owner string, id uuid.UUID, disabl
return m.notes.SetDisabled(ctx, m.orgID, strings.TrimSpace(owner), id, disabled)
}
// Forget deletes one of owner's own notes. The deletion is recorded outside the
// database before the row goes, so a failed recording leaves the note in place
// rather than removing one the next restore would bring back.
// Forget deletes one of owner's own notes. The deletion and its witness commit
// together, and the entry in the record outside the database is written after
// that; a record that cannot be written is reported as incomplete, and Reconcile
// completes it from the witness, so a restore never brings the note back.
func (m *Module) Forget(ctx context.Context, owner string, id uuid.UUID) (bool, error) {
owner = strings.TrimSpace(owner)
owns, err := m.notes.Owns(ctx, m.orgID, owner, id)
@@ -390,8 +386,8 @@ func (m *Module) Approve(ctx context.Context, publisher string, id uuid.UUID) (N
return noteOf(row), true, nil
}
// Revoke removes a shared note, published or pending. The deletion is recorded
// before the row goes, as in Forget.
// Revoke removes a shared note, published or pending. The deletion is committed
// and recorded as in Forget.
func (m *Module) Revoke(ctx context.Context, id uuid.UUID) (bool, error) {
exists, err := m.shared.SharedExists(ctx, m.orgID, id)
if err != nil || !exists {
@@ -404,9 +400,10 @@ func (m *Module) Revoke(ctx context.Context, id uuid.UUID) (bool, error) {
return true, m.recordDeletion(ctx, id)
}
// Versions returns every published version of a shared note, newest first.
// Versions returns every published version of a shared note in this
// organisation, newest first.
func (m *Module) Versions(ctx context.Context, id uuid.UUID) ([]Version, error) {
rows, err := m.shared.Versions(ctx, id)
rows, err := m.shared.Versions(ctx, m.orgID, id)
if err != nil {
return nil, err
}