Skip to content

fix(check): read environment names one per line, and address them encoded - #879

Merged
max-sixty merged 2 commits into
mainfrom
fix/env-name-spaces
Aug 8, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/env-name-spaces

Conversation

@tend-agent

@tend-agent tend-agent commented Aug 7, 2026 •

Copy link
Copy Markdown
Collaborator

check_credential_environments read the environment list with listed.stdout.split() and interpolated each name straight into the API path. GitHub admits both a space and a / in an environment name, and the list endpoint returns one name per line — so an environment called staging deploy became two names, staging and deploy, that exist nowhere, and one called a/b addressed repos/<r>/environments/a/b/secrets, a path that names no environment either.

Both shapes 404. The first 404 is the secrets is None or secrets.returncode != 0 branch, which returns the whole check as skipped:

SKIP  credential-environments — Could not list secrets in 'staging' (requires admin access)

So the check that backs the security model's "a run the bot can cause reaches no credential" claim stops verifying, and the message blames the token rather than naming the real cause. The genuine environment is never examined either — if it holds an ungated credential, nothing reports it. One such environment costs the repo the check entirely, including for its other environments.

splitlines() fixes the read. _env_path — quote(name, safe="") — fixes the way back out: gh api percent-encodes a space itself but passes a / through as a path separator, and it does not re-encode the escapes it is handed, so encoding the whole name as one segment covers both shapes with one rule.

Verification

Confirmed against live GitHub on tend-agent/tend-integration, with both probe environments deleted afterwards:

$ gh api -X PUT "repos/$R/environments/zz%20probe" --jq '.name'
zz probe
$ gh api -X PUT "repos/$R/environments/zz%2Fprobe" --jq '.name'
zz/probe

$ gh api --paginate "repos/$R/environments" --jq '.environments[].name'
tend
zz probe
zz/probe

$ gh api "repos/$R/environments/zz/probe/secrets"          # raw slash
gh: Not Found (HTTP 404)
$ gh api "repos/$R/environments/zz%2Fprobe/secrets" --jq '.total_count'
0
$ gh api "repos/$R/environments/zz%2Fprobe" --jq '.name'
zz/probe
$ gh api "repos/$R/environments/zz%2Fprobe/deployment-branch-policies"
{"total_count":0,"branch_policies":[]}

The escapes survive the PUT, which is what shows gh passes them through rather than re-encoding the %. %2F then resolves on the detail, secrets, and deployment-branch-policies endpoints alike, where the raw / 404s. The last of those was read with custom_branch_policies enabled — that endpoint 404s on an environment with a null deployment_branch_policy regardless of encoding, which is the case _policy_gate returns on before it ever calls _branch_policies.

Tests

test_credential_environments_reads_a_name_containing_a_space and test_credential_environments_reads_a_name_containing_a_slash both fail with the symptom above when the fix is reverted:

FAILED ...::test_credential_environments_reads_a_name_containing_a_space
AssertionError: Could not list secrets in 'staging' (requires admin access)
assert None is False
FAILED ...::test_credential_environments_reads_a_name_containing_a_slash
AssertionError: Could not list secrets in 'a/b' (requires admin access)
assert None is False

The shared _credential_env_gh fake now matches the percent-encoded segment, as GitHub answers, so a caller that interpolates a name raw stops matching and falls to the same skipped-for-want-of-admin return. Full generator suite: 353 passed.

Scope

Deliberately narrow. The other .split() calls in this file are safe on their inputs — _tags_admin_gated splits numeric ruleset ids, and secret names are [A-Z0-9_] — so they are left alone rather than swept. Every other environment name reaching an API path in this file is the TEND_ENVIRONMENT constant.

Found by the nightly survey (bucket 8/28, generator/src/tend/checks.py). Independent of the other two open checks.py PRs (#825, #826), which both concern _bypass_actors_above_bot.

A name is one path segment, and GitHub admits `/` in one. The three URLs
that interpolated the name raw addressed a path that 404s, which is the
same `returncode != 0` the split above produced — the whole credential
check returns skipped-for-want-of-admin, for every environment.

So splitlines() alone only fixed half of it: the name now survives the
read and is lost on the way back out. Verified on a live repo: an
environment named `a/b probe` lists under that name, its `/secrets` path
interpolated raw exits 1 with 404, and the percent-encoded path resolves.
@tend-agent tend-agent changed the title fix(check): read environment names one per line, not per whitespace token fix(check): read environment names one per line, and address them encoded Aug 7, 2026
@max-sixty
max-sixty merged commit fef82e9 into main Aug 8, 2026
5 checks passed
@max-sixty
max-sixty deleted the fix/env-name-spaces branch August 8, 2026 16:04
max-sixty pushed a commit to max-sixty/worktrunk that referenced this pull request Aug 13, 2026
Automated nightly regeneration of tend's workflow files.

**tend version:** 0.1.14 → 0.1.15

**Notable changes**

- **Rate-limit handling**: a maintainer can approve past the spike limit
(max-sixty/tend#874), and `tend-mention` now skips comments on
`tend-rate-limit`-labelled issues as well as `tend-outage` ones — the
same self-trigger loop guard, widened to every issue tend files about
its own health.
- **Review flow**: a push is queued behind an examined-HEAD gate instead
of cancelling the in-flight review (max-sixty/tend#903), the review is
submitted before a fix is pushed (max-sixty/tend#834), a force-push
triggers a re-review rather than trusting the re-anchored SHA
(max-sixty/tend#884), and the `/code-review` second pass is
unconditional (max-sixty/tend#937).
- **CI monitoring**: both the check poll and the `gh run rerun --failed`
poll now end terminally when the cap is hit instead of reading as done
(max-sixty/tend#876, max-sixty/tend#951), and a failed GitHub-status
probe no longer reads as "no incident" (max-sixty/tend#913).
- **Nightly**: conflicted bot PRs are test-merged locally instead of
filtered on the lazy `mergeable` field (max-sixty/tend#898), and mention
runs skip the bot's own review and a third party's content-free approval
(max-sixty/tend#916, max-sixty/tend#955).
- **`tend check`**: an unreadable ruleset bypass list is reported as
unknown rather than ungated (max-sixty/tend#825), environment names are
read one per line and addressed encoded (max-sixty/tend#879), and
`credential-environments` no longer points at the setting it rejects
(max-sixty/tend#900) — this repo currently `SKIP`s that check, so its
wording should improve here.

Full comparison:
max-sixty/tend@0.1.14...0.1.15

Co-authored-by: worktrunk-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants