Skip to content

Commit 0b52894

Browse files
authored
security: disable lua scripting by default (#3830)
There is a weakness that can be abused by a default skipper installation such that you can read arbitrary files as skipper process. It depends on the custom installation and environment if this is actually exploitable by untrusted people. Since 2022 we provide a detailed Lua [config guide](https://opensource.zalando.com/skipper/reference/scripts/#enable-and-disable-lua-sources) such that operators can choose how to use Lua even in less trusted environments. For example you can use -lua-sources=file and only operators that can provide a file accessible to the skipper process are able to reference lua sources and execute provided scripts. Thanks defang bo providing us a detailed report how to exploit this vulnerability that is available by default in skipper versions <v0.23 Signed-off-by: Sandor Szücs <[email protected]>
1 parent 1ca00f7 commit 0b52894

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.22
1+
v0.23

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ type Config struct {
315315

316316
ClusterRatelimitMaxGroupShards int `yaml:"cluster-ratelimit-max-group-shards"`
317317

318+
EnableLua bool `yaml:"enable-lua"`
318319
LuaModules *listFlag `yaml:"lua-modules"`
319320
LuaSources *listFlag `yaml:"lua-sources"`
320321

@@ -654,6 +655,7 @@ func NewConfig() *Config {
654655

655656
flag.IntVar(&cfg.ClusterRatelimitMaxGroupShards, "cluster-ratelimit-max-group-shards", 1, "sets the maximum number of group shards for the clusterRatelimit filter")
656657

658+
flag.BoolVar(&cfg.EnableLua, "enable-lua", false, "enable the Lua scripting engine to be able to use the lua() filter")
657659
flag.Var(cfg.LuaModules, "lua-modules", "comma separated list of lua filter modules. Use <module>.<symbol> to selectively enable module symbols, for example: package,base._G,base.print,json")
658660
flag.Var(cfg.LuaSources, "lua-sources", `comma separated list of lua input types for the lua() filter. Valid sources "", "file", "inline", "file,inline" and "none". Use "file" to only allow lua file references in lua filter. Default "" is the same as "file","inline". Use "none" to disable lua filters.`)
659661

@@ -1054,6 +1056,7 @@ func (c *Config) ToOptions() skipper.Options {
10541056

10551057
ClusterRatelimitMaxGroupShards: c.ClusterRatelimitMaxGroupShards,
10561058

1059+
EnableLua: c.EnableLua,
10571060
LuaModules: c.LuaModules.values,
10581061
LuaSources: c.LuaSources.values,
10591062

config/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func defaultConfig(with func(*Config)) *Config {
169169
ClusterRatelimitMaxGroupShards: 1,
170170
ValidateQuery: true,
171171
ValidateQueryLog: true,
172+
EnableLua: false,
172173
LuaModules: commaListFlag(),
173174
LuaSources: commaListFlag(),
174175
OpenPolicyAgentCleanerInterval: openpolicyagent.DefaultCleanIdlePeriod,

skipper.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,11 @@ type Options struct {
990990
// KubernetesEnableTLS enables kubernetes to use resources to terminate tls
991991
KubernetesEnableTLS bool
992992

993+
// EnableLua allows to use lua() filters, if not enabled
994+
// skipper does not support Lua, because of security
995+
// considerations.
996+
EnableLua bool
997+
993998
// LuaModules that are allowed to be used.
994999
//
9951000
// Use <module>.<symbol> to selectively enable module symbols,
@@ -2045,15 +2050,17 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
20452050
o.CustomFilters = append(o.CustomFilters, compress)
20462051
}
20472052

2048-
lua, err := script.NewLuaScriptWithOptions(script.LuaOptions{
2049-
Modules: o.LuaModules,
2050-
Sources: o.LuaSources,
2051-
})
2052-
if err != nil {
2053-
log.Errorf("Failed to create lua filter: %v.", err)
2054-
return err
2053+
if o.EnableLua {
2054+
lua, err := script.NewLuaScriptWithOptions(script.LuaOptions{
2055+
Modules: o.LuaModules,
2056+
Sources: o.LuaSources,
2057+
})
2058+
if err != nil {
2059+
log.Errorf("Failed to create lua filter: %v.", err)
2060+
return err
2061+
}
2062+
o.CustomFilters = append(o.CustomFilters, lua)
20552063
}
2056-
o.CustomFilters = append(o.CustomFilters, lua)
20572064

20582065
// create routing
20592066
// create the proxy instance

0 commit comments

Comments
 (0)