mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-12-01 09:24:46 +00:00
security: keep the SQLite database owner-only (0600)
SQLite creates agentbbs.db and its -wal/-shm files 0644, so any account on the host could read members' emails, DMs and login IPs; Caddy did, through a planted homepage symlink. Open now chmods all three to 0600. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fc8206d0e2
commit
94accaadf6
2 changed files with 51 additions and 0 deletions
33
internal/store/store_filemode_test.go
Normal file
33
internal/store/store_filemode_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The database holds members' emails, DMs and login IPs, so no other account
|
||||
// on the host may read it, including after a write creates the WAL file.
|
||||
func TestOpenMakesDatabaseOwnerOnly(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "t.db")
|
||||
st, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatalf("open: %v", err)
|
||||
}
|
||||
defer st.Close()
|
||||
if _, err := st.EnsureUser("alice", "member", "SHA256:a"); err != nil {
|
||||
t.Fatalf("write: %v", err)
|
||||
}
|
||||
for _, p := range []string{path, path + "-wal", path + "-shm"} {
|
||||
fi, err := os.Stat(p)
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("stat %s: %v", p, err)
|
||||
}
|
||||
if mode := fi.Mode().Perm(); mode&0o077 != 0 {
|
||||
t.Errorf("%s is %o, want no group/other access", filepath.Base(p), mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue