收紧证书与配置状态文件访问
Some checks are pending
Security Checks / security (push) Waiting to run

This commit is contained in:
smail 2026-09-22 03:35:32 +08:00
parent 2dd5156018
commit 200a399b4d
3 changed files with 20 additions and 4 deletions

View File

@ -7,6 +7,8 @@ import (
"path/filepath"
"strings"
securefile "git.pcux.cn/xuans/Smail/utils/file"
"git.pcux.cn/xuans/Smail/utils/runtimepath"
)
@ -146,7 +148,7 @@ func readExternalSSLFile(path string, privateKey bool) ([]byte, error) {
if privateKey && info.Mode().Perm()&0077 != 0 && runtimeSupportsPermissionCheck() {
return nil, ErrSSLPrivateKeyPermission
}
file, err := os.Open(path)
file, err := securefile.OpenRegularFile(path, os.O_RDONLY, 0)
if err != nil {
return nil, ErrSSLFileUnavailable
}

View File

@ -2,8 +2,21 @@
package config
import "os"
import (
"os"
"path/filepath"
)
func openSSLLease(path string) (*os.File, error) {
return os.OpenFile(path, os.O_RDWR, 0600)
absolute, err := filepath.Abs(filepath.Clean(path))
if err != nil {
return nil, err
}
root, err := os.OpenRoot(filepath.Dir(absolute))
if err != nil {
return nil, err
}
file, err := root.OpenFile(filepath.Base(absolute), os.O_RDWR, 0600)
_ = root.Close()
return file, err
}

View File

@ -9,6 +9,7 @@ import (
"time"
"git.pcux.cn/xuans/Smail/utils/atomicfile"
fileutil "git.pcux.cn/xuans/Smail/utils/file"
"git.pcux.cn/xuans/Smail/utils/runtimepath"
)
@ -31,7 +32,7 @@ func (s *TransactionStore) lockState() (func(), error) {
} else if err != nil && !os.IsNotExist(err) {
return nil, err
}
file, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0600)
file, err := fileutil.OpenRegularFile(filename, os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
return nil, err
}