internal/instance: Prevent line breaks in environment variables

LXC doesn't currently have a syntax to hold a multi-line environment
variable in its configuration. The use of multi-line environment
variables leads to a corrupted configuration file and to a security
issue where additional lines may be added by an unprivileged user to
escalate their privileges.

This fixes CVE-2026-23953.

Reported-by: Rory McNamara <rory.mcnamara@snyk.io>
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
Stéphane Graber 2026-01-20 23:27:25 -05:00
parent 938fee4d0e
commit cdf037409f
No known key found for this signature in database
GPG Key ID: C638974D64792D67

View File

@ -1485,7 +1485,13 @@ func ConfigKeyChecker(key string, instanceType api.InstanceType) (func(value str
// liveupdate: yes
// shortdesc: Free-form environment key/value
if strings.HasPrefix(key, "environment.") {
return validate.IsAny, nil
return func(val string) error {
if strings.Contains(val, "\n") {
return errors.New("Environment variables cannot contain line breaks")
}
return nil
}, nil
}
// gendoc:generate(entity=instance, group=miscellaneous, key=user.*)