Skip to content

Commit

Permalink
config/security: Add HOME to default exec env var whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Dec 22, 2021
1 parent f11b8df commit 36779b6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
6 changes: 1 addition & 5 deletions config/security/securityConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var DefaultConfig = Config{
),
// These have been tested to work with Hugo's external programs
// on Windows, Linux and MacOS.
OsEnv: NewWhitelist("(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$"),
OsEnv: NewWhitelist("(?i)^(PATH|PATHEXT|APPDATA|HOME|TMP|TEMP|TERM)$"),
},
Funcs: Funcs{
Getenv: NewWhitelist("^HUGO_"),
Expand Down Expand Up @@ -110,7 +110,6 @@ func (c Config) CheckAllowedExec(name string) error {
}
}
return nil

}

func (c Config) CheckAllowedGetEnv(name string) error {
Expand Down Expand Up @@ -159,7 +158,6 @@ func (c Config) ToSecurityMap() map[string]interface{} {
"security": m,
}
return sec

}

// DecodeConfig creates a privacy Config from a given Hugo configuration.
Expand Down Expand Up @@ -189,7 +187,6 @@ func DecodeConfig(cfg config.Provider) (Config, error) {
}

return sc, nil

}

func stringSliceToWhitelistHook() mapstructure.DecodeHookFuncType {
Expand All @@ -205,7 +202,6 @@ func stringSliceToWhitelistHook() mapstructure.DecodeHookFuncType {
wl := types.ToStringSlicePreserveString(data)

return NewWhitelist(wl...), nil

}
}

Expand Down
7 changes: 1 addition & 6 deletions config/security/securityonfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ getEnv=["a", "b"]
c.Assert(pc.Exec.OsEnv.Accept("e"), qt.IsFalse)
c.Assert(pc.Funcs.Getenv.Accept("a"), qt.IsTrue)
c.Assert(pc.Funcs.Getenv.Accept("c"), qt.IsFalse)

})

c.Run("String whitelist", func(c *qt.C) {
Expand All @@ -80,7 +79,6 @@ osEnv="b"
c.Assert(pc.Exec.Allow.Accept("d"), qt.IsFalse)
c.Assert(pc.Exec.OsEnv.Accept("b"), qt.IsTrue)
c.Assert(pc.Exec.OsEnv.Accept("e"), qt.IsFalse)

})

c.Run("Default exec.osEnv", func(c *qt.C) {
Expand All @@ -105,7 +103,6 @@ allow="a"
c.Assert(pc.Exec.Allow.Accept("a"), qt.IsTrue)
c.Assert(pc.Exec.OsEnv.Accept("PATH"), qt.IsTrue)
c.Assert(pc.Exec.OsEnv.Accept("e"), qt.IsFalse)

})

c.Run("Enable inline shortcodes, legacy", func(c *qt.C) {
Expand All @@ -129,9 +126,7 @@ osEnv="b"
pc, err := DecodeConfig(cfg)
c.Assert(err, qt.IsNil)
c.Assert(pc.EnableInlineShortcodes, qt.IsTrue)

})

}

func TestToTOML(t *testing.T) {
Expand All @@ -140,7 +135,7 @@ func TestToTOML(t *testing.T) {
got := DefaultConfig.ToTOML()

c.Assert(got, qt.Equals,
"[security]\n enableInlineShortcodes = false\n [security.exec]\n allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$']\n osEnv = ['(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$']\n\n [security.funcs]\n getenv = ['^HUGO_']\n\n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['.*']",
"[security]\n enableInlineShortcodes = false\n [security.exec]\n allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$']\n osEnv = ['(?i)^(PATH|PATHEXT|APPDATA|HOME|TMP|TEMP|TERM)$']\n\n [security.funcs]\n getenv = ['^HUGO_']\n\n [security.http]\n methods = ['(?i)GET|POST']\n urls = ['.*']",
)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/data/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@
"^postcss$"
],
"osEnv": [
"(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$"
"(?i)^(PATH|PATHEXT|APPDATA|HOME|TMP|TEMP|TERM)$"
]
},
"funcs": {
Expand Down

0 comments on commit 36779b6

Please sign in to comment.