Skip to content

[Ignition] Butane template uses text/template with no YAML escaping — potential injection via SSH key comments #25

Description

@castrojo

Summary

The Butane YAML template in internal/ignition/ignition.go uses Go's text/template package, which performs zero escaping of interpolated values. User-supplied strings (hostnames, usernames, SSH keys, sysext names) are inserted directly into double-quoted YAML strings without any YAML-safe escaping.

While hostname and username validation prevents most dangerous characters, SSH key comments are not validated for content — only the key type prefix is checked. A crafted SSH key comment containing a double quote could break the YAML structure.

Example

An SSH public key with a crafted comment:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExample user"
      - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEvil injected@key

This is a valid SSH key format (passes validate.SSHPublicKey() since it starts with a valid type and has 2+ fields). When templated:

ssh_authorized_keys:
    - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExample user"
      - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEvil injected@key"

This could inject additional YAML content. While butane's --strict compilation may catch malformed YAML, the defense should be at the template layer, not relying on downstream validation.

Template Location

// internal/ignition/ignition.go line 74+
const butaneTemplate = `...
{{- range .SSHKeys}}
        - "{{.}}"    // ← raw interpolation, no escaping
{{- end}}

Suggested Fix

Either:

  1. Validate SSH key comments don't contain quotes/newlines in validate.SSHPublicKey()
  2. Use a YAML library to generate the config instead of string templating
  3. At minimum, escape double quotes in interpolated values

Severity

Medium — Requires a specifically crafted SSH key. Butane --strict may catch the broken YAML, but this is defense-in-depth. The SSH key validation should reject keys with double quotes in comments regardless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    1-triageNew work awaiting human triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions