Skip to content

Commit a4e47ed

Browse files
authored
Merge pull request #4405 from jandubois/yqlib-security
Disable env access and file load operations in yqlib
2 parents 5231d77 + 43df949 commit a4e47ed

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

hack/bats/tests/list.bats

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,13 @@ local_setup() {
264264
run -0 limactl ls --quiet --yq 'select(.name == "foo")'
265265
assert_output "foo"
266266
}
267+
268+
@test '--yq cannot access environment variables' {
269+
run_e -1 limactl ls --yq 'env(HOME)'
270+
assert_fatal "env operations have been disabled"
271+
}
272+
273+
@test '--yq cannot load files' {
274+
run_e -1 limactl ls --yq "load(\"${BASH_SOURCE[0]}\")"
275+
assert_fatal "file operations have been disabled"
276+
}

hack/bats/tests/yq.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ load "../helpers/load"
3535
run -0 "$YQ" -n -o json -I 0 .foo=42
3636
assert_output '{"foo":42}'
3737
}
38+
39+
@test 'yq multi-call command has support for env access' {
40+
export FOO=bar
41+
run -0 limactl yq -n 'env(FOO)'
42+
assert_output "bar"
43+
}
44+
45+
@test 'yq multi-call command has support for --security-disable-env-ops' {
46+
export FOO=bar
47+
run_e -1 limactl yq -n --security-disable-env-ops 'env(FOO)'
48+
assert_stderr "Error: env operations have been disabled"
49+
}

pkg/yqutil/yqutil.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func EvaluateExpressionWithEncoder(expression, content string, encoder yqlib.Enc
5050
logging.SetBackend(backend)
5151
yqlib.InitExpressionParser()
5252

53+
// Disable access to environment variables and file loading functions
54+
yqlib.ConfiguredSecurityPreferences.DisableEnvOps = true
55+
yqlib.ConfiguredSecurityPreferences.DisableFileOps = true
56+
5357
decoder := yqlib.NewYamlDecoder(yqlib.ConfiguredYamlPreferences)
5458
out, err := yqlib.NewStringEvaluator().EvaluateAll(expression, content, encoder, decoder)
5559
if err != nil {

0 commit comments

Comments
 (0)