docs: design for optional client-side E2E encryption (issue #39) #75

Merged
poslop merged 2 commits from issue-39-e2e-design into main 2026-09-09 14:26:02 +00:00
2 changed files with 46 additions and 2 deletions
Showing only changes of commit f6c4342468 - Show all commits
+40
View File
@@ -175,6 +175,46 @@ func TestListPublicExcludesUnlisted(t *testing.T) {
} }
} }
func TestListPublicExcludesPasswordAndUnlisted(t *testing.T) {
s := testServer(t)
h := s.routes()
bodies := []string{
`{"content":"open","visibility":"public"}`,
`{"content":"locked","visibility":"public","password":"hunter2"}`,
`{"content":"hidden","visibility":"unlisted"}`,
}
for _, body := range bodies {
req := httptest.NewRequest("POST", "/api/pastes", strings.NewReader(body))
rec := httptest.NewRecorder()
h.ServeHTTP(rec, req)
if rec.Code != 201 {
t.Fatalf("create %s: got %d", body, rec.Code)
}
}
req := httptest.NewRequest("GET", "/api/public", nil)
rec := httptest.NewRecorder()
h.ServeHTTP(rec, req)
if rec.Code != 200 {
t.Fatalf("list public: got %d", rec.Code)
}
var resp struct {
Total int `json:"total"`
Items []map[string]any `json:"items"`
}
json.Unmarshal(rec.Body.Bytes(), &resp)
if resp.Total != 1 || len(resp.Items) != 1 {
t.Fatalf("expected only the 1 public paste, got total=%d items=%d", resp.Total, len(resp.Items))
}
// password-protected and unlisted pastes must not appear (no metadata leak)
for _, secret := range []string{"hunter2", "locked", "hidden"} {
if strings.Contains(rec.Body.String(), secret) {
t.Fatalf("leaked %q in /api/public response", secret)
}
}
}
func TestSweepSoftDeletesAfterGrace(t *testing.T) { func TestSweepSoftDeletesAfterGrace(t *testing.T) {
s := testServer(t) s := testServer(t)
h := s.routes() h := s.routes()
+6 -2
View File
@@ -252,9 +252,13 @@ func (s *Store) GetPaste(idOrSlug string) (*PasteRow, error) {
return &r, err return &r, err
} }
// ListPublic backs /api/public and the public listing page. Visibility rules
// mirror the history page: only non-deleted, non-expired, non-can pastes are
// listed, and password-protected pastes are excluded at the query level
// (#65) so their metadata (title, slug, existence) never leaks.
func (s *Store) ListPublic(limit, offset int) ([]PasteRow, int, error) { func (s *Store) ListPublic(limit, offset int) ([]PasteRow, int, error) {
rows, err := s.db.Query(`SELECT id, custom_slug, content_type, language, title, visibility, created_at, view_count, LENGTH(content) FROM pastes rows, err := s.db.Query(`SELECT id, custom_slug, content_type, language, title, visibility, created_at, view_count, LENGTH(content) FROM pastes
WHERE visibility='public' AND deleted_at IS NULL AND can_id IS NULL AND (expires_at IS NULL OR expires_at > ?) WHERE visibility='public' AND deleted_at IS NULL AND can_id IS NULL AND password_hash IS NULL AND (expires_at IS NULL OR expires_at > ?)
ORDER BY created_at DESC LIMIT ? OFFSET ?`, time.Now().Unix(), limit, offset) ORDER BY created_at DESC LIMIT ? OFFSET ?`, time.Now().Unix(), limit, offset)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
@@ -273,7 +277,7 @@ func (s *Store) ListPublic(limit, offset int) ([]PasteRow, int, error) {
out = append(out, r) out = append(out, r)
} }
var total int var total int
s.db.QueryRow(`SELECT COUNT(*) FROM pastes WHERE visibility='public' AND deleted_at IS NULL AND can_id IS NULL AND (expires_at IS NULL OR expires_at > ?)`, time.Now().Unix()).Scan(&total) s.db.QueryRow(`SELECT COUNT(*) FROM pastes WHERE visibility='public' AND deleted_at IS NULL AND can_id IS NULL AND password_hash IS NULL AND (expires_at IS NULL OR expires_at > ?)`, time.Now().Unix()).Scan(&total)
return out, total, nil return out, total, nil
} }