Skip to content

Check Env Files an Env File Includes When read_env_value Reads It #3912

Closed

Description

@ptr727

The gap

read_env_value in lib/sh/secrets.sh sources the env file in a child bash, bash -Eeuo pipefail -c '... source "$1" ...'. Its contract says it checks nothing about the file, so a caller runs require_secret on it first. That covers the file named in $1. It does not cover a file that env file includes.

An env file can include a second one behind a guard, so that the second file is checked wherever the checker is loaded:

# app.env, mode 600, passes the caller's require_secret
APP_NAME=example
if declare -F require_secret >/dev/null; then
    require_secret "${BASH_SOURCE%/*}/extra.env"
fi
. "${BASH_SOURCE%/*}/extra.env"

read_env_value's child bash is started fresh, and no require_secret is defined in it. So declare -F fails, the guard is skipped, and extra.env is sourced without its mode or line-ending check. That happens even where extra.env is world-writable or carries CRLF line endings. The caller cannot check it either, because only the child sees the include.

How a downstream repository closed it

ptr727/HomeAutomation-Config hit this with its docker.env, which includes mail.env (#890 phase 2a there). It added:

  • A loader: load_env_file <path> runs require_secret on the file, then sources it.
  • Helper text: a helper prints load_env_file and every function it calls as declare -f text.
  • The child: read_env_value's child bash evaluates that text before it reads. So the child runs load_env_file "$1", and the include's guard then finds require_secret defined.

That follows the shipping convention the downstream paths.sh already used for functions a child bash needs.

Done looks like

  • A file included behind declare -F require_secret is checked when it is read through read_env_value.
  • A test case proves it, by refusing an included file with a loose mode or CRLF line endings.
  • The comment on read_env_value says what the function checks, and what the caller still owes.
  • GOVERNANCE.md's host-secrets wording still matches the reader.

Found during a backlog burndown review in ptr727/HomeAutomation-Config, and filed on the maintainer's go-ahead.

Activity

  1. ptr727 commented on Nov 13, 2026

    @ptr727
    OwnerAuthor

    Backlog burndown claim (round 5, group 3, away mode): branch burndown/env-include-check.

    Issue: #3912.

    Predicted file set:

    • lib/sh/secrets.sh
    • tests/test_secrets_sh.py
    • GOVERNANCE.md, for the host-secrets reader wording only where the reader's contract changes

    spec/project-types.json is held by another branch and is not claimed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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