Visitar URL original
Check Env Files an Env File Includes When read_env_value Reads It by ptr727 · Pull Request #4164 · ptr727/ProjectTemplate · GitHub
Skip to content

Check Env Files an Env File Includes When read_env_value Reads It - #4164

Merged
ptr727 merged 2 commits into
developfrom
burndown/env-include-check
Nov 13, 2026
Merged

ptr727 merged 2 commits into
developfrom
burndown/env-include-check

Conversation

@ptr727

@ptr727 ptr727 commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Summary

read_env_value sources an env file in a fresh child bash, where require_secret was not defined. An env file that includes a second file behind declare -F require_secret therefore skipped the guard, and the include was sourced with no mode or line-ending check.

  • The child can check an include. read_env_value ships require_secret and every helper it calls into the child as declare -f text. A guarded include now finds require_secret defined, and a loose mode or CRLF endings refuse the read.
  • Fails closed. A helper missing from the calling shell fails the read with an error before the env file runs. An example is an elevated shell that was shipped too few functions.
  • The env file's own check stays with the caller. A caller still checks the env file before the read, with require_secret or secret_verdict with shared, as GOVERNANCE.md states. So GOVERNANCE.md is unchanged, and its host-secrets wording still matches the reader.
  • Contract comment. The comment on read_env_value says that a guarded include is checked and an unguarded one is not. The library header names the functions read_env_value needs when it is shipped by declare -f.

Tests

tests/test_secrets_sh.py ReadEnvValue gains four cases. Three of them fail against the library before this change.

  • A guarded include with mode 666 is refused, naming the include.
  • A guarded include with CRLF endings is refused, naming the include.
  • A missing helper fails the read before the env file runs.
  • A guarded include that passes is read. This case passes before and after the change.

shellcheck and shfmt -d are clean on lib/sh/secrets.sh, and ruff check and ruff format --check are clean on the test file.

Local review

  • Fixed: checking the env file inside the child refused a file a caller checks with shared. The child no longer checks it.
  • Fixed: the comment said the caller owes the include guard, when the env file's author writes it.
  • Declined: shipping read_env_value alone into an elevated shell now fails the read. The failure is loud and fails closed, which is the point of the change, and the library header names the functions it needs. Neither known downstream caller ships it that way.

The change adds code comments, so it carries the comments label.

Closes on promotion: #3912

🤖 Generated with Claude Code

ptr727 and others added 2 commits November 13, 2026 10:02
read_env_value's child bash now defines require_secret and its helpers from
declare -f text, runs require_secret on the env file before sourcing it, and so
checks an include guarded by `declare -F require_secret` for mode and CRLF.
A helper missing from the calling shell fails the read before the file runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The child no longer runs require_secret on the env file itself, since a caller
may check it with secret_verdict shared instead. It still defines require_secret
so a guarded include is checked, and the comment says an unguarded one is not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings November 13, 2026 18:06
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ptr727

ptr727 commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 3cf6baa1263b47ea39c92220dc23672bc471cd52, the content this pull request carries at that commit against develop, and it recorded 0 findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active issues are identified, and the change addresses guarded-include validation with fail-closed handling for unavailable helpers.

No open issues 🎉

What changed in this PR

This pull request closes a secret-validation gap in read_env_value by validating guarded includes inside the child Bash process while leaving top-level env-file checks to callers.

Changes:

  • Ships require_secret and its dependencies into the child process.
  • Fails closed when a required validation helper is unavailable.
  • Adds coverage for valid includes, unsafe permissions, CRLF endings, and missing helpers.
  • The missing-helper test should quote the temporary marker path to remain reliable when TMPDIR contains spaces.
File Description
tests/​test_secrets_sh.py Adds tests for guarded include validation, unsafe file conditions, and fail-closed behavior when a helper is missing.
lib/​sh/​secrets.sh Passes secret-validation functions into the child process before reading env files and documents the required dependencies.

Review effort: Lite

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.75%. Comparing base (b38e084) to head (3cf6baa).
⚠️ Report is 193 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4164      +/-   ##
===========================================
- Coverage    81.60%   76.75%   -4.86%     
===========================================
  Files           26       41      +15     
  Lines         9070    14279    +5209     
===========================================
+ Hits          7402    10960    +3558     
- Misses        1668     3319    +1651     
Flag Coverage Δ
python-3.13 76.75% <ø> (-4.86%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727

ptr727 commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ptr727
ptr727 merged commit da917cd into develop Nov 13, 2026
13 of 14 checks passed
@ptr727
ptr727 deleted the burndown/env-include-check branch November 13, 2026 18:19
ptr727 added a commit that referenced this pull request Nov 13, 2026
… Rules (#4189)

## Summary

Promotes the backlog-burndown rounds and changes from other hub sessions
from `develop` to `main`.

- Hooks and the prose gate: #4132, #4134, #4136, #4145, #4152, #4184.
The Husky hook reads its path list once and diffs a merge against
`MERGE_HEAD`. Interrupts re-raise their signal, a Markdown code span
reads as quoted data, and the gate picks a commit's diff base and
recognizes a conflicted promotion's branch cut from `main`.
- Procedures and carried rules: #4133, #4139, #4141, #4149, #4166,
#4177, #4179, #4183, #4185. Resync, audit and check-this-repo procedure
gaps, code style and shell interrupt rules, review-loop gaps across four
skills, the context and delegation section of `AGENTS.md`, question
rules in governance, the promotion line in pull request bodies,
closing-keyword behavior on promotion, and the history-rewrite premise.
- Review and cleanup tooling: #4138, #4148, #4154, #4156, #4157, #4163,
#4164, #4168, #4174, #4180. Cleanliness reads, parked handoffs, the
backlog report's JSON output, exact inline script pins, trusted inputs,
env-file includes, the bounded review wait, side-reviewer matching, and
a Copilot billing-failure notice read as a refusal.
- Workflow and runbook contract: #4153, #4155, #4169, #4171, #4178,
#4182. The runtime-secrets check, a registry entry and spec references,
the Copilot runbook pointers, credential-free checkout steps, and the
deploy-key and runner wording.
- From other hub sessions: #4159 (a repository's own .NET line under a
fleet default), #4161 (the 1Password CLI as an optional host tool),
#4162 (Codex's Windows installer and one managed opencode copy). These
carry no promotion line.

#4182 carries no promotion line by design, and #4175 holds the split-out
part of #4057's scope. Both #1448 and #4175 stay open.

Fixes #1071
Fixes #1154
Fixes #1391
Fixes #1471
Fixes #1594
Fixes #1620
Fixes #1627
Fixes #1650
Fixes #1801
Fixes #2853
Fixes #3620
Fixes #3668
Fixes #3697
Fixes #3766
Fixes #3787
Fixes #3837
Fixes #3840
Fixes #3842
Fixes #3844
Fixes #3865
Fixes #3882
Fixes #3890
Fixes #3894
Fixes #3912
Fixes #3916
Fixes #3954
Fixes #4014
Fixes #4015
Fixes #4016
Fixes #4043
Fixes #4050
Fixes #4057
Fixes #4058
Fixes #4062
Fixes #4084
Fixes #4097
Fixes #4098
Fixes #4099
Fixes #4104
Fixes #4108
Fixes #4114
Fixes #4115
Fixes #4117
Fixes #4118
Fixes #4119
Fixes #4121
Fixes #4122
Fixes #4123
Fixes #4131
Fixes #4135
Fixes #4140
Fixes #4142
Fixes #4143
Fixes #4144
Fixes #4151

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants