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

+7 -4
View File
@@ -203,12 +203,15 @@ func (s *Store) Publish(ctx context.Context, orgID string, id uuid.UUID, publish
return out[0], true, nil
}
// Versions returns a shared note's published versions, newest first.
func (s *Store) Versions(ctx context.Context, noteID uuid.UUID) ([]Version, error) {
// Versions returns a shared note's published versions, newest first. The note's
// own row is what says which organisation it belongs to, so the read joins it:
// a note id from another organisation then answers nothing.
func (s *Store) Versions(ctx context.Context, orgID string, noteID uuid.UUID) ([]Version, error) {
var out []Version
if err := s.db.SelectContext(ctx, &out, `
SELECT note_id, version, text, purpose, publisher_id, published_at
FROM memory.note_versions WHERE note_id = $1 ORDER BY version DESC`, noteID); err != nil {
SELECT v.note_id, v.version, v.text, v.purpose, v.publisher_id, v.published_at
FROM memory.note_versions v JOIN memory.notes n ON n.id = v.note_id
WHERE v.note_id = $1 AND n.org_id = $2 ORDER BY v.version DESC`, noteID, orgID); err != nil {
return nil, fmt.Errorf("list note versions: %w", err)
}
return out, nil