fix(store): chmod SQLite DB files to 0600 on open
CI / test (pull_request) Successful in 1m57s
CI / lint (pull_request) Successful in 1m26s
CI / vulncheck (pull_request) Successful in 1m2s

Bare-metal installs created the DB with process umask (often 022),
making uptop.db, -wal, and -shm world-readable. These files contain
alert credentials and config. Now chmod 0600 after open. Missing
WAL/SHM siblings (not yet created) are silently skipped. Docker
installs were already mitigated by the non-root UID.
This commit was merged in pull request #119.
This commit is contained in:
2026-06-12 09:51:11 -04:00
parent 6cf0efed9b
commit c3eac80e14
+8
View File
@@ -4,6 +4,7 @@ import (
"database/sql"
"fmt"
"log/slog"
"os"
_ "modernc.org/sqlite"
)
@@ -25,6 +26,13 @@ func NewSQLiteStore(path string) (*SQLStore, error) {
if err != nil {
return nil, err
}
if path != ":memory:" {
for _, suffix := range []string{"", "-wal", "-shm"} {
if err := os.Chmod(path+suffix, 0600); err != nil && !os.IsNotExist(err) {
slog.Warn("failed to chmod database file", "path", path+suffix, "err", err)
}
}
}
return s, nil
}