mirror of
https://github.com/ddworken/hishtory.git
synced 2025-03-12 06:08:22 +01:00
Add validation to block absolute paths (#277)
This commit is contained in:
parent
0953e1ccca
commit
2ff52a8d66
@ -12,6 +12,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ddworken/hishtory/shared"
|
||||
@ -160,7 +161,20 @@ func DecryptHistoryEntry(userSecret string, entry shared.EncHistoryEntry) (Histo
|
||||
return decryptedEntry, nil
|
||||
}
|
||||
|
||||
func ValidateHishtoryPath() error {
|
||||
hishtoryPath := os.Getenv("HISHTORY_PATH")
|
||||
if strings.HasPrefix(hishtoryPath, "/") {
|
||||
return fmt.Errorf("HISHTORY_PATH must be a relative path")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetHishtoryPath() string {
|
||||
err := ValidateHishtoryPath()
|
||||
if err != nil {
|
||||
// This panic() can only trigger if the env variable is changed after process startup
|
||||
panic(err)
|
||||
}
|
||||
hishtoryPath := os.Getenv("HISHTORY_PATH")
|
||||
if hishtoryPath != "" {
|
||||
return hishtoryPath
|
||||
|
@ -2,9 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/ddworken/hishtory/client/cmd"
|
||||
"github.com/ddworken/hishtory/client/data"
|
||||
"github.com/ddworken/hishtory/client/lib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
lib.CheckFatalError(data.ValidateHishtoryPath())
|
||||
cmd.Execute()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user