Skip to content

Further restrict API names character set and prevent shell expansion#2827

Merged
tych0 merged 3 commits intolxc:mainfrom
stgraber:main
Jan 17, 2026
Merged

Further restrict API names character set and prevent shell expansion#2827
tych0 merged 3 commits intolxc:mainfrom
stgraber:main

Conversation

@stgraber
Copy link
Copy Markdown
Member

The LXC driver generates an LXC config file which includes some LXC hooks.
Those get run through a shell and may therefore get expanded if special characters are allowed.

Some care was taken around that by using strconv.Quote, but this only leads to double quoted rather than single quoted strings (equivalent to "%q" in fmt.Sprintf) when for something exposed to a shell, we really want single quoted strings.

To address potential issues, this branch:

  • Forbids the use of $ anywhere in the Incus API object names
  • Introduces a new util.SingleQuote function (sadly strconv doesn't provide this directly
  • Makes use of util.SingleQuote where strconv.Quote was previously used

This issue came out from security research work by @rmcnamara-snyk but as any exploitation of this requires full admin privileges on Incus, it didn't qualify as a security issue.

stgraber and others added 3 commits January 17, 2026 08:35
Since some of those names may be passed to a shell either on the client
or server side, let's avoid getting into potential variable expansions.

Signed-off-by: Stéphane Graber <[email protected]>
Reported-by:  Rory McNamara <[email protected]>
Signed-off-by: Stéphane Graber <[email protected]>
Suggested-by: Rory McNamara <[email protected]>
This avoids potential shell expansion of the strings should some special
characters manage to make it through.

Signed-off-by: Rory McNamara <[email protected]>
@tych0 tych0 merged commit da49137 into lxc:main Jan 17, 2026
158 of 160 checks passed
tomponline added a commit to canonical/lxd that referenced this pull request Feb 3, 2026
Based on lxc/incus#2827

Related to
https://github.com/lxc/incus/security/advisories/GHSA-8h3p-58qv-8p53

From @stgraber :

> The LXC driver generates an LXC config file which includes some LXC
hooks.
> Those get run through a shell and may therefore get expanded if
special characters are allowed.
> 
> Some care was taken around that by using strconv.Quote, but this only
leads to double quoted rather than single quoted strings (equivalent to
"%q" in fmt.Sprintf) when for something exposed to a shell, we really
want single quoted strings.
> 
> To address potential issues, this branch:
> 
> - Introduces a new util.SingleQuote function (sadly strconv doesn't
provide this directly)
> - Makes use of util.SingleQuote where strconv.Quote was previously
used
> 
> This issue came out from security research work by @rmcnamara-snyk but
as any exploitation of this requires full admin privileges on Incus, it
didn't qualify as a security issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants