Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-12-12 14:11:11 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-12-16 11:40:22 +0300
commitf4389e48ce0a70807362772d66c12ab5cd9e15f8 (patch)
tree1334516a199dcdf4133758e3664348287e73e88b /helpers
parent803f572e66c5e22213ddcc994c41b3e80e9c1f35 (diff)
Add some basic security policies with sensible defaults
This ommmit contains some security hardening measures for the Hugo build runtime. There are some rarely used features in Hugo that would be good to have disabled by default. One example would be the "external helpers". For `asciidoctor` and some others we use Go's `os/exec` package to start a new process. These are a predefined set of binary names, all loaded from `PATH` and with a predefined set of arguments. Still, if you don't use `asciidoctor` in your project, you might as well have it turned off. You can configure your own in the new `security` configuration section, but the defaults are configured to create a minimal amount of site breakage. And if that do happen, you will get clear instructions in the loa about what to do. The default configuration is listed below. Note that almost all of these options are regular expression _whitelists_ (a string or a slice); the value `none` will block all. ```toml [security] enableInlineShortcodes = false [security.exec] allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$'] osEnv = ['(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$'] [security.funcs] getenv = ['^HUGO_'] [security.http] methods = ['(?i)GET|POST'] urls = ['.*'] ```
Diffstat (limited to 'helpers')
-rw-r--r--helpers/content.go4
-rw-r--r--helpers/content_test.go2
-rw-r--r--helpers/general_test.go2
-rw-r--r--helpers/testhelpers_test.go2
4 files changed, 6 insertions, 4 deletions
diff --git a/helpers/content.go b/helpers/content.go
index 161b14e76..2d26a0c48 100644
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -24,6 +24,7 @@ import (
"unicode"
"unicode/utf8"
+ "github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/loggers"
"github.com/spf13/afero"
@@ -64,7 +65,7 @@ type ContentSpec struct {
// NewContentSpec returns a ContentSpec initialized
// with the appropriate fields from the given config.Provider.
-func NewContentSpec(cfg config.Provider, logger loggers.Logger, contentFs afero.Fs) (*ContentSpec, error) {
+func NewContentSpec(cfg config.Provider, logger loggers.Logger, contentFs afero.Fs, ex *hexec.Exec) (*ContentSpec, error) {
spec := &ContentSpec{
summaryLength: cfg.GetInt("summaryLength"),
BuildFuture: cfg.GetBool("buildFuture"),
@@ -78,6 +79,7 @@ func NewContentSpec(cfg config.Provider, logger loggers.Logger, contentFs afero.
Cfg: cfg,
ContentFs: contentFs,
Logger: logger,
+ Exec: ex,
})
if err != nil {
return nil, err
diff --git a/helpers/content_test.go b/helpers/content_test.go
index 515b788f1..c1ff5c1d2 100644
--- a/helpers/content_test.go
+++ b/helpers/content_test.go
@@ -110,7 +110,7 @@ func TestNewContentSpec(t *testing.T) {
cfg.Set("buildExpired", true)
cfg.Set("buildDrafts", true)
- spec, err := NewContentSpec(cfg, loggers.NewErrorLogger(), afero.NewMemMapFs())
+ spec, err := NewContentSpec(cfg, loggers.NewErrorLogger(), afero.NewMemMapFs(), nil)
c.Assert(err, qt.IsNil)
c.Assert(spec.summaryLength, qt.Equals, 32)
diff --git a/helpers/general_test.go b/helpers/general_test.go
index bfabcbef4..db8cb30a8 100644
--- a/helpers/general_test.go
+++ b/helpers/general_test.go
@@ -30,7 +30,7 @@ import (
func TestResolveMarkup(t *testing.T) {
c := qt.New(t)
cfg := config.New()
- spec, err := NewContentSpec(cfg, loggers.NewErrorLogger(), afero.NewMemMapFs())
+ spec, err := NewContentSpec(cfg, loggers.NewErrorLogger(), afero.NewMemMapFs(), nil)
c.Assert(err, qt.IsNil)
for i, this := range []struct {
diff --git a/helpers/testhelpers_test.go b/helpers/testhelpers_test.go
index 7d63e4d88..e9502acc0 100644
--- a/helpers/testhelpers_test.go
+++ b/helpers/testhelpers_test.go
@@ -50,7 +50,7 @@ func newTestCfg() config.Provider {
func newTestContentSpec() *ContentSpec {
v := config.New()
- spec, err := NewContentSpec(v, loggers.NewErrorLogger(), afero.NewMemMapFs())
+ spec, err := NewContentSpec(v, loggers.NewErrorLogger(), afero.NewMemMapFs(), nil)
if err != nil {
panic(err)
}