Repository navigation
Description
Summary
Two low-severity robustness findings in the same text transform, both from the /edge-cases pass on #1979. Filed together because they share a root: the .env line is built as a regex replacement string and consumed by a parser that never reverses the escaping the writer applies.
1. A backslash in the token raises re.error mid-rotation
_patch_env_github_pat passes the formatted line to re.sub as the replacement, where \1, \g<…> and unknown letter-escapes are interpreted:
'ghp_a\g<1>b' -> re.error: invalid group reference 1 at position 20
'ghp_back\slash' -> re.error: bad escape \s at position 20
'ghp_with\1group' -> re.error: invalid group reference 1 at position 21
Impact is bounded and honest, not silent: _propagate_to_agent catches only httpx errors, so this escapes to the asyncio.gather(..., return_exceptions=True) in propagate_pat_to_all_agents, which records the agent as failed with the message and continues. The operator sees failures — they just say bad escape \s instead of "that is not a valid token". Real GitHub PATs (ghp_[A-Za-z0-9]{36}, github_pat_[A-Za-z0-9_]{82}) contain no backslashes, so this needs a malformed paste.
Fix: use a function replacement (lambda _: new_line) or re.sub's replacement escaping. Rejecting a token that doesn't match the PAT shape at the settings boundary would be better still.
tests/unit/test_pat_propagation_properties.py::TestKnownGaps::test_a_backslash_in_the_token_does_not_raise (xfail(strict=True), 3 params).
2. .env writer escapes ", reader never unescapes it
_format_pat_line escapes embedded double quotes (pat.replace('"', '\\"')), matching the agent-server's own .env writer. The agent-server's reader does value.strip().strip('"').strip("'") — it strips quote characters but never unescapes \". So any value containing a quote round-trips corrupted:
written : GITHUB_PAT="ghp_a\"b"
agent reads: 'ghp_a\\"b' (expected 'ghp_a"b')
This is a property of the .env parse contract, not of #1979 — it affects every credential written through that path, not just PATs. I deliberately kept that parser byte-faithful in #1999/#2010 rather than improving it inside a security fix, precisely because the ent#127 "is this credential set" predicate is defined as agreement with it and its source is spliced into an in-container probe. Fixing the asymmetry means changing both sides together, with test_ent127_predicate.py::TestExporterParity as the gate.
tests/unit/test_pat_propagation_properties.py::TestKnownGaps::test_a_quote_in_the_token_round_trips (xfail(strict=True)).
Acceptance criteria
- A token containing a backslash fails with a comprehensible message (or is rejected at the settings boundary), never as
re.error - If the
.envescaping asymmetry is fixed: writer and reader change together, with the ent#127 parity test updated in the same commit
Related
- fix(github-pat): make a global PAT rotation actually reach running agents (#1967) #1979 / bug: global GitHub PAT rotation never reaches agents — propagation skips agents without .env and never re-templates the git remote #1967 — the rotation path
- bug: credential injects mirror
.envinto the agent-server long-lived process env — a removed key keeps reaching every execution, invisible to /proc and docker exec #1999 — the.envparse contract and why it was deliberately left byte-faithful
Activity
dolho commentedon Aug 5, 2026
/claim
github-actions commentedon Aug 5, 2026
Claimed by @dolho. Label
status-in-progressadded.Next steps:
feature/2017-<short-slug>Fixes #2017Merge origin/dev into fix/2017-pat-escaping
test(2017): pin the callable replacement via the AST, not the source …
test(2018): retire the #2015 xfail — #2026 landed
test(edge-cases): audit hash chain + PAT propagation — edge/property …
fix(credentials): make the .env quote encoding reversible (#2023) (#2030
fix(github-pat): stop re.sub parsing the token as regex syntax (#2017)
test(2017): pin the callable replacement via the AST, not the source …
fix(tests): read back through the shipped reader, not a copy of it (#…
Merge pull request #2024 from Abilityai/fix/2017-pat-escaping
fix(tests): fix the OTHER two polluters — the first attempt did not fix
fix(tests): scope the #612 module stubs to the load that needs them (#…
fix(tests): derive time from the clock, not the calendar; retire four…
fix(tests): derive time from the clock, not the calendar; retire four…
fix(ci): make a wholly-red suite reportable, and detect calendar rot …