Skip to content

Environment variables in {{include}}d files are never substituted, so they stay literal (including in shipped examples) #165

Closed

Description

@jrosskopf

What

{{env.NAME}} inside a file pulled in with {{include ...}} is never substituted, and never checked against the whitelist. ExtendedYamlParser::loadYamlFile is just YAML::Load(ReadConfigFile(path)) (src/extended_yaml_parser.cpp, used at both include sites), so included content skips the substitution the including file gets.

Reproduced (whitelist lists only FLAPI_INC_LISTED, both variables set; the shared file is outside the templates directory so it is only ever reached through the include):

# shared/auth.yaml
auth:
  users:
    - username: alice
      password: '{{env.FLAPI_INC_LISTED}}'      # listed   -> stays literal
    - username: bob
      password: '{{env.FLAPI_INC_UNLISTED}}'    # unlisted -> stays literal, NO error

flapi --validate-config passes. It is not a confidentiality problem (a value is never read), but it is exactly the silent-literal failure the whitelist enforcement in #164 exists to prevent: a password that is the text {{env.DB_PASSWORD}}.

Pre-existing: identical on main. Found by two independent reviewers of #164.

It affects the shipped examples

examples/sqls/customers/customers-rest.yaml and customers-mcp-tool.yaml include auth from customer-common.yaml, which has twelve {{env.CUSTOMER_API_*}} references. So those endpoints' auth users carry literal names such as {{env.CUSTOMER_API_READ_USER}} today.

Why this is not a one-line fix

Simply substituting included content is what the docs promise ("anywhere in your YAML") — but an unset variable substitutes as an empty string, so the shipped auth users would become empty usernames and passwords. Someone needs to decide what an empty credential does on those endpoints before this is changed, and the fix must also keep the whitelist error from being swallowed by the include site's generic "Could not resolve include path" catch.

Suggested

  1. Substitute and enforce included content under the same policy, with a dedicated exception type so the whitelist error reaches the operator.
  2. Treat an unset-but-whitelisted variable in a credential field as an error rather than an empty string (see also test_jwt_empty_secret.py, which already worries about this for jwt-secret).
  3. Add tests for listed and unlisted references inside an included file, and fix the example whitelists to match.

Until then the docs say {{env.NAME}} is checked in the main config and endpoint files, and not in included content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions