Merge pull request 'docs: design for optional client-side E2E encryption (issue #39)' (#75) from issue-39-e2e-design into main
CI / test (push) Successful in 20s
CI / docker (push) Skipped

This commit was merged in pull request #75.
This commit is contained in:
2026-09-09 14:26:02 +00:00
4 changed files with 270 additions and 3 deletions
+40
View File
@@ -183,6 +183,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) {
s := testServer(t)
h := s.routes()
+6 -2
View File
@@ -257,9 +257,13 @@ func (s *Store) GetPaste(idOrSlug string) (*PasteRow, error) {
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) {
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)
if err != nil {
return nil, 0, err
@@ -278,7 +282,7 @@ func (s *Store) ListPublic(limit, offset int) ([]PasteRow, int, error) {
out = append(out, r)
}
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
}