Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions hack/bats/tests/list.bats
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,13 @@ local_setup() {
run -0 limactl ls --quiet --yq 'select(.name == "foo")'
assert_output "foo"
}

@test '--yq cannot access environment variables' {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can allow --yq to access env, as long as the upstream yq continues to allow accessing env by default.

The proposed --filter should be restrictive though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is best to restrict it everywhere, except for limactl yq itself.

What is the use case for limactl list --yq or limactl info --yq to use env variables or load from files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I continue to think that having just a single flavour of YQ expressions throughout Lima is preferable, especially since there are no known use-cases for the prohibited operations. Otherwise you have to document the kind of expression allowed separately for each option that takes a YQ expression.

And you can still do this if you really want to:

limactl list --json | limactl yq '...'

Because the yq command itself is not limited, only any expression used in Lima internally.

run_e -1 limactl ls --yq 'env(HOME)'
assert_fatal "env operations have been disabled"
}

@test '--yq cannot load files' {
run_e -1 limactl ls --yq "load(\"${BASH_SOURCE[0]}\")"
assert_fatal "file operations have been disabled"
}
4 changes: 4 additions & 0 deletions pkg/yqutil/yqutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func EvaluateExpressionWithEncoder(expression, content string, encoder yqlib.Enc
logging.SetBackend(backend)
yqlib.InitExpressionParser()

// Disable access to environment variables and file loading functions
yqlib.ConfiguredSecurityPreferences.DisableEnvOps = true
yqlib.ConfiguredSecurityPreferences.DisableFileOps = true

decoder := yqlib.NewYamlDecoder(yqlib.ConfiguredYamlPreferences)
out, err := yqlib.NewStringEvaluator().EvaluateAll(expression, content, encoder, decoder)
if err != nil {
Expand Down