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) (#180)
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
1655e7617f
commit
537d96d5a8
2 changed files with 51 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
|
@ -403,9 +404,26 @@ func Open(path string) (Store, error) {
|
|||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
if err := restrictFileMode(path); err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
return &sqliteStore{db: db}, nil
|
||||
}
|
||||
|
||||
// restrictFileMode makes the database and its WAL/SHM files owner-only.
|
||||
// SQLite creates them 0644, which let any account on the host (Caddy
|
||||
// included) read every member's email, DMs and login IPs (2026-11 incident).
|
||||
// SQLite gives later -wal/-shm files the main file's mode, so this sticks.
|
||||
func restrictFileMode(path string) error {
|
||||
for _, p := range []string{path, path + "-wal", path + "-shm"} {
|
||||
if err := os.Chmod(p, 0o600); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return fmt.Errorf("chmod %s: %w", p, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// migrate applies additive schema changes that must not fail on existing
|
||||
// databases. New columns live here (not in schema) so there is one code path.
|
||||
func migrate(db *sql.DB) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue