Skip to content

fix(deps): preserve inherited git config when injecting auth headers - #2382

Merged
Daniel Meppiel (danielmeppiel) merged 9 commits into
microsoft:mainfrom
edenfunf:fix/2368-git-config-count-append
Jul 30, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 9 commits into
microsoft:mainfrom
edenfunf:fix/2368-git-config-count-append

Conversation

@edenfunf

@edenfunf Eden (edenfunf) commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

build_authorization_header_git_env() / build_ado_bearer_git_env() return an overlay whose GIT_CONFIG_COUNT is hardcoded to "1". Dict-merging that onto a base env that already carries indexed git config entries (GIT_CONFIG_COUNT=N, keys 0..N-1) resets the count and overwrites index 0, silently dropping inherited hardening such as safe.bareRepository=explicit, credential.interactive=never, or a corporate http.sslCAInfo pin.

The issue names two call sites and says the same defect was already fixed elsewhere via an append helper. That helper is not in the tree or in history — the other sites still dict-merge the overlay. An audit of every consumer of the overlay found five:

  • deps/clone_engine.py — ADO bearer in-attempt retry (named in the issue)
  • deps/download_strategies.py — GitHub sparse-git file fetch (named in the issue)
  • core/auth.py _build_git_env — the bearer branch overwrote the very entries _clear_git_auth_env had just retained and re-indexed
  • marketplace/ref_resolver.py — _git_url_and_env (bearer + ADO basic) and the ls-remote bearer retry
  • deps/github_downloader_validation.py — validation attempt env construction

Fixes #2368

Approach

set_authorization_header_git_env / set_ado_bearer_git_env rewrite the indexed set in place: existing auth-channel entries are removed so layered callers cannot stack duplicate Authorization headers, every other entry is preserved and re-indexed, orphaned GIT_CONFIG_KEY_/VALUE_ entries at or beyond the count are dropped so no stale credential lingers in the child-process env table, and the new header is appended last.

Because the header no longer sits at a fixed index, marketplace/client.py's _ado_auth_header — which sniffed GIT_CONFIG_VALUE_0 to tell an AAD bearer from a PAT — now scans the indexed set, bounded by GIT_CONFIG_COUNT because that is all git itself reads. Two tests that hardcoded the header at index 0 locate it instead; they previously passed only in environments without ambient GIT_CONFIG_* entries.

The build_* helpers remain for fresh-overlay construction, with a docstring warning against dict-merging them onto a populated env.

Considered and not done here

The retain/re-index policy in the new setter mirrors AuthResolver._clear_git_auth_env. Extracting it into a shared primitive (utils/git_env.py would be the right home) is the better end state, but it means editing a security-critical function this bug does not otherwise touch, inside a fix that needs to stay reviewable. The two are cross-referenced in the docstrings; happy to do the extraction as a follow-up if preferred.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Helper unit tests cover preservation, replacement of an inherited stale header, layering idempotence, orphan cleanup, and blank/invalid counts. Per-site regression tests cover all five call sites plus the _ado_auth_header sniff, and each was verified to fail against the pre-fix code.

The touched suites also pass with GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=safe.bareRepository GIT_CONFIG_VALUE_0=explicit exported in the shell — the environment this fix is about.

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

…ted entries (microsoft#2368)

The bearer fallback in CloneEngine.execute and the sparse-git file fetch in
download_strategies dict-merged build_ado_bearer_git_env() /
build_authorization_header_git_env() over a base env. The overlay hardcodes
GIT_CONFIG_COUNT=1, so when the base env already carries indexed git config
entries (e.g. retained hardening like safe.bareRepository=explicit or
credential.interactive=never), the merge reset the count and overwrote the
entry at index 0.

Add append_authorization_header_git_env / append_ado_bearer_git_env, which
append the Authorization http.extraheader at the next free index, and switch
both call sites to the append idiom. Regression tests cover both call sites
and the helper edge cases (empty base, blank/invalid count).
…site (microsoft#2368)

Audit of all build_authorization_header_git_env / build_ado_bearer_git_env
consumers found the same GIT_CONFIG_COUNT clobber at three more sites beyond
the two named in microsoft#2368: AuthResolver._build_git_env (bearer branch overwrote
the entries _clear_git_auth_env had just retained), RefResolver
_git_url_and_env / the ls-remote bearer retry, and the validation-attempt
env in github_downloader_validation.

Promote the helper to set semantics: existing auth-channel entries (same
policy as _clear_git_auth_env) are removed so layered callers cannot stack
duplicate Authorization headers, non-auth entries are preserved and
re-indexed, orphaned indexed entries are dropped, and the header is appended
last. Rename append_* to set_* accordingly and switch all five call sites.

build_* helpers remain for fresh-overlay construction with a warning
against dict-merging them onto a populated env.

Regression tests cover each call site plus helper edge cases (replacement,
layering idempotence, orphan cleanup, blank/invalid count).
… sniff (microsoft#2368)

_ado_auth_header distinguished AAD-bearer from ADO-PAT by inspecting
GIT_CONFIG_VALUE_0 only. Now that the Authorization header is appended after
retained non-auth entries, a bearer env with inherited git config (e.g.
http.sslCAInfo) carries the header at a later index, so the sniff missed it
and sent the AAD JWT as HTTP Basic to the ADO items API. Scan every value
slot instead.

Also make the two tests that hardcoded the header at index 0 locate it by
scanning (they only passed in environments without ambient GIT_CONFIG
entries), and drop a build_ado_bearer_git_env mock that no longer
intercepts anything.

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.

Pull request overview

This PR fixes a class of auth-env construction bugs where dict-merging build_*_git_env() overlays (with GIT_CONFIG_COUNT="1") onto an existing env silently clobbered inherited indexed git config entries (e.g., safe.bareRepository=explicit, credential.interactive=never, http.sslCAInfo), as described in #2368. It introduces in-place helpers to preserve and reindex retained entries while ensuring only one Authorization header is present, and updates all identified call sites plus regression tests.

Changes:

  • Add set_authorization_header_git_env() / set_ado_bearer_git_env() to rewrite GIT_CONFIG_{COUNT,KEY_N,VALUE_N} in-place (preserve non-auth entries, remove existing auth-channel entries, drop orphans, append new header).
  • Migrate all known affected call sites (deps, auth resolver, marketplace resolver, downloader validation) from dict-merge overlays to the in-place setters.
  • Expand unit/integration test coverage to validate retention, replacement/idempotence, orphan cleanup, and header-index-independence.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/apm_cli/utils/github_host.py Adds in-place git-env setters and warns against dict-merging the overlay helpers onto populated envs.
src/apm_cli/core/auth.py Switches ADO bearer env injection to in-place setter to preserve retained config from _clear_git_auth_env.
src/apm_cli/deps/clone_engine.py Fixes ADO bearer retry env construction to preserve inherited indexed git config.
src/apm_cli/deps/download_strategies.py Fixes sparse-git GitHub file fetch env construction to avoid clobbering inherited config.
src/apm_cli/deps/github_downloader_validation.py Fixes validation attempt env construction to mutate a copy and append header safely.
src/apm_cli/marketplace/ref_resolver.py Updates marketplace git env construction and bearer retry to use in-place setters.
src/apm_cli/marketplace/client.py Updates _ado_auth_header to detect bearer header when it may not be at index 0.
tests/unit/test_github_host.py Adds focused unit tests for the new in-place setters (preserve, replace, idempotence, orphan cleanup, bad counts).
tests/unit/test_auth.py Adds regression ensuring bearer env preserves retained config entries across _build_git_env.
tests/unit/marketplace/test_ref_resolver.py Updates header assertions to be index-independent; adds retained-config regression coverage for _git_url_and_env.
tests/unit/marketplace/test_client_ado.py Adds regression ensuring _ado_auth_header detects bearer at any config index.
tests/unit/deps/test_shared_clone_cache.py Removes now-obsolete patching of the old overlay helper for bearer env construction.
tests/unit/deps/test_github_throttle_fallback.py Adds regression that throttle fallback appends header after retained git config.
tests/unit/deps/test_github_downloader_input_validation.py Adds regression for retained git config preservation in validation attempt env construction.
tests/unit/deps/test_clone_engine_bearer_env.py Adds focused contract test for CloneEngine bearer retry env preservation.
tests/integration/test_ado_marketplace_check_auth.py Makes integration assertion index-independent for Authorization header placement.

Comment thread src/apm_cli/marketplace/client.py Resolved
…rosoft#2368)

_ado_auth_header scanned every GIT_CONFIG_VALUE_ key in the env. Git reads only indices below GIT_CONFIG_COUNT, so a slot above it is a leftover from an env this process did not build, or an injected one -- and honouring it sends an ADO PAT under the Bearer scheme, which the server rejects. Read the same range git does, with the tolerant int parse used elsewhere.

The pre-existing fixtures paired a value slot with no count, a shape no env APM builds; they now carry the count alongside it.

Also annotate the two setters as dict[str, str] and drop the append-era names from tests the helper outgrew.
The two new test files added by this PR (test_clone_engine_bearer_env.py
and test_github_throttle_fallback.py) were saved with a leading UTF-8
BOM (EF BB BF), which CPython's ast.parse (used by the repository's
architecture-ratchet inventory in tests/quality/repository_python_inventory.py)
rejects with SyntaxError: invalid non-printable character U+FEFF. ruff
format --check also flagged both files as needing reformatting for the
same reason. Stripping the BOM fixes both the Lint and the Test
Architecture Ratchets CI jobs with no behavioral change.

Addresses CI failures on PR microsoft#2382 (Lint job, Test Architecture Ratchets
job) surfaced by the shepherd-driver CI-recovery pass.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f1d182b1-b222-463e-8beb-e3f1334c61e1
…authority debt

apm-review-panel follow-ups (python-architect, auth-expert,
supply-chain-security-expert; all independently converged on the
same signal):

- Tighten the auth-channel-entry filter in
  set_authorization_header_git_env from a broad 'authorization' in
  value.lower() substring match to value.strip().lower().startswith(
  'authorization:'), matching what an actual Authorization: header
  value looks like. The broad match could false-positive-strip a
  retained non-auth entry whose value merely contains the substring
  (e.g. a corporate http.proxy pointed at an 'authorization-proxy'
  host). Regression test added and mutation-break verified: reverting
  the predicate makes the new false-positive test fail.
- Add a CRLF rejection guard on scheme/credential before they are
  interpolated into the appended git-config value. Defense-in-depth
  against a caller (now or in the future) smuggling a second
  git-config entry via an embedded newline; no current call site can
  trigger this (all pass hardcoded scheme literals and JWT/base64
  tokens), but the new setter is a security-sensitive surface worth
  hardening at its introduction. Regression test added and
  mutation-break verified: removing the guard makes the new CRLF
  tests fail with DID NOT RAISE.
- Document (via a TODO(microsoft#2398) cross-reference) that the retain/reindex
  predicate in this new setter intentionally mirrors the pre-existing,
  untouched AuthResolver._clear_git_auth_env rather than delegating to
  a shared primitive. Two panelists independently flagged this as a
  split-authority per .apm/instructions/architecture.instructions.md;
  the PR itself already explained why extracting a shared helper
  belongs in a dedicated follow-up rather than this fix (it would mean
  editing a security-critical function this bug does not otherwise
  touch). Filed microsoft#2398 to track that extraction so the
  debt does not silently rot.

Addresses apm-review-panel follow-ups on PR microsoft#2382.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f1d182b1-b222-463e-8beb-e3f1334c61e1
…ead with the symptom

apm-review-panel follow-ups (doc-writer, devx-ux-expert):

- Move the microsoft#2368 entry from ### Fixed to ### Security. CHANGELOG.md
  already uses a Security heading for cases where a security-relevant
  guarantee was silently broken and then restored (see the Artifactory
  safe-extraction and runtime-setup digest-verification entries); this
  fix restores dropped git hardening (SSL CA pin, bare-repository
  protection) the same way and should be filed under the same
  category for consistency.
- Reword the entry to lead with the user-visible symptom (corporate
  git security settings being silently dropped) before the
  GIT_CONFIG_* mechanism explanation, so a reader scanning the
  changelog for security-relevant changes can self-identify relevance
  without needing to know the internal env-var plumbing.

Addresses apm-review-panel follow-ups on PR microsoft#2382.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f1d182b1-b222-463e-8beb-e3f1334c61e1
…n authority

This PR is a split-authority repair per .apm/instructions/architecture.
instructions.md: the same decision (how to inject an Authorization
header into a git-subprocess env without clobbering inherited
GIT_CONFIG_* entries) was independently implemented at 5 call sites,
each with the same microsoft#2368 clobber bug. The fix collapses all 5 into one
owner (set_authorization_header_git_env / set_ado_bearer_git_env in
utils/github_host.py). Per the architecture doc, a split-authority
repair is not done until the split cannot silently return -- this adds
the missing static-guard half of that dual guardrail (the behavioral
regression tests already exist, one per call site, verified by the
author to fail pre-fix):

- AC19 in scripts/lint-architecture-boundaries.sh: greps for the
  dict-merge anti-pattern (.update(build_authorization_header_git_env(
  or {**env, **build_ado_bearer_git_env(...)}) across src/apm_cli/,
  excluding comment-only references (the two existing SECURITY comments
  in install/pipeline.py and install/validation.py that already warn
  against this exact pattern) and the standard
  architecture-authority-exempt: marker.
- tests/integration/test_architecture_authorities.py: a same-shape pair
  of tests as the existing AC17 (GitHub throttle) guard --
  test_git_auth_header_injection_has_single_owner (doc/guard
  consistency) and test_git_auth_header_owner_guard_rejects_dictmerge_
  reintroduction (sandbox-mutation test proving AC19 actually fires on
  a re-introduced clobber site).

Mutation-break verified: removing the AC19 block made both new
architecture tests fail (guard returncode 0 instead of 1); restored
and re-verified green.

Addresses the canonical-owner gate (shepherd-driver Step X.2.5) for
PR microsoft#2382, which touches src/apm_cli/core/auth.py (a call site this
split-authority repair covers).

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: f1d182b1-b222-463e-8beb-e3f1334c61e1
@danielmeppiel

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_now

Community fix for inherited git-config loss during auth-header injection is fully converged -- zero open findings, all 455 tests green, ship now.

cc Eden (@edenfunf) Daniel Meppiel (@danielmeppiel) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

This PR completes a clean arc from community bug report (#2368) through first-time contributor fix to production-ready merge candidate. The core change -- consolidating a duplicated, buggy git-subprocess auth-header injection pattern into two canonical owners (set_authorization_header_git_env / set_ado_bearer_git_env) that preserve the caller's inherited git config -- is architecturally sound and directly aligned with APM's secure-by-default principle. The shepherd-driver folded all five follow-ups from the first synthesis (CRLF injection guard, tightened startswith filter, CHANGELOG reframing, TODO(#2398) for split-authority debt, and an AC19 static boundary guard) across three commits, and every panelist confirmed correct resolution with zero new findings.

The security surface is materially improved: the CRLF guard now rejects before mutating state, the startswith('authorization:') filter eliminates a substring false-positive class (e.g. a corporate http.proxy value that merely contains the word "authorization" is no longer mis-stripped), and the strip-then-append pattern is idempotent -- all verified by six new tests with mutation-break evidence. The architecture-authority dual guardrail (behavioral regression test + AC19 owner guard + architecture test) ensures the consolidated ownership cannot silently drift back to the prior scattered pattern. Tracking issue #2398 is already filed to address the remaining structural duplication between this new setter and AuthResolver._clear_git_auth_env in a future, dedicated security-reviewed refactor; that work is intentionally out of scope for this bug-fix PR and does not block shipment.

No specialist disagreements remain. The performance-expert confirmed the new guards are O(1) relative to the existing O(env_size) scan and run once per git subprocess, not per dependency. The doc-writer's earlier claim that the CHANGELOG entry needed an ADO-only scope qualifier was independently verified by the orchestrator to be factually incorrect (the fix also covers GitHub and GitLab auth paths) and was correctly excluded from folding. The growth-hacker notes no external narrative beat but flags the contributor for a release-notes shout-out -- a small gesture that reinforces APM's community-first positioning.

Aligned with: Secure by default -- CRLF injection guard, tightened env-var filter, and consolidated auth-header ownership materially reduce the attack surface for credential leakage through git subprocess environment manipulation, all default-on with no opt-out needed. OSS community-driven -- first-time contributor (edenfunf) delivered a production-quality fix with test coverage that exceeded the bar set by several internal PRs; the shepherd preserved full authorship via commit trailers; tracking issue #2398 was filed transparently.

Growth signal. First-time external contributor delivered a security-hardening fix that consolidated a scattered internal pattern into a clean, guarded ownership boundary -- worth a release-notes shout-out to signal that APM treats community contributors as first-class maintainers, not second-tier patch submitters.

Panel summary

Persona B R N Takeaway
Python Architect 0 0 0 All three prior findings addressed: TODO(#2398) documents split-authority debt, AC19 dual guardrail prevents dict-merge reintroduction, no new issues in fold commits
CLI Logging Expert 0 0 0 No CLI output surface touched; ValueError guard in github_host.py is an internal exception, not user-facing. Clean pass.
DevX UX Expert 0 0 0 CHANGELOG entry now leads with user-visible symptom and is filed under Security; previous nit resolved, no new issues.
Supply Chain Security Expert 0 0 0 Both prior nits (CRLF guard reject-before-mutate + tightened startswith filter) verified correct; no credential leak, no false-negative gap.
OSS Growth Hacker 0 0 0 No external growth surface touched; internal hardening and lint-guard work has no marketing beat to extract.
Auth Expert 0 0 0 Fold verified: TODO(#2398) tracks duplication, CRLF guard rejects before mutate, tightened filter has no false negatives, strip-then-append is idempotent, 202/202 tests pass, no credential leak or precedence change
Doc Writer 0 0 0 Confirmed: #2368 entry now under Security, leads with symptom, Keep-a-Changelog format intact; no docs pages reference the fix, no staleness introduced.
Test Coverage Expert 0 0 0 All 402 tests pass (400 unit + 2 arch-authority). Six new tests are genuine non-tautological assertions on CRLF injection, substring false-positive, and AC19 owner guard. No regressions. Ship.
Performance Expert 0 0 0 CRLF guard and tightened startswith filter are both O(1) relative to the existing O(env_size) scan; function runs once per git subprocess, not per-dep. No measurable regression.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Architecture

classDiagram
    direction LR
    class AuthResolver {
      <<Strategy>>
      +resolve_for_dep(dep) AuthContext
      +_build_git_env(token, scheme, host_kind) dict
      +_clear_git_auth_env(env) None
    }
    class set_authorization_header_git_env {
      <<Mutator>>
      +__call__(env, scheme, credential) None
    }
    class set_ado_bearer_git_env {
      <<Mutator>>
      +__call__(env, bearer_token) None
    }
    class build_authorization_header_git_env {
      <<OverlayBuilder>>
      +__call__(scheme, credential) dict
    }
    class CloneEngine {
      +execute(repo, target, dep_ref, clone_action)
    }
    class DownloadDelegate {
      +_download_github_file_via_git(dep_ref, file_path, ref)
    }
    class RefResolver {
      +_build_env(owner_repo, bearer, use_ssh)
      +list_remote_refs(owner_repo)
    }
    class _ado_auth_header {
      <<Pure>>
      +__call__(token, git_env) dict
    }
    class _build_validation_attempts {
      <<Pure>>
      +__call__(downloader, dep_ref, dep_token) list
    }
    note for AuthResolver "Chain of Responsibility:\ntoken -> env -> az-cli-bearer"
    note for set_authorization_header_git_env "Retain/reindex policy mirrors\n_clear_git_auth_env (tracked: #2398)"
    AuthResolver ..> set_ado_bearer_git_env : delegates in _build_git_env
    set_ado_bearer_git_env ..> set_authorization_header_git_env : delegates
    CloneEngine ..> set_ado_bearer_git_env : bearer retry
    DownloadDelegate ..> set_authorization_header_git_env : header injection
    RefResolver ..> set_ado_bearer_git_env : bearer path
    RefResolver ..> set_authorization_header_git_env : basic path
    _build_validation_attempts ..> set_authorization_header_git_env : all schemes
    _ado_auth_header ..> _ado_auth_header : scans GIT_CONFIG_VALUE_i
    class set_authorization_header_git_env:::touched
    class set_ado_bearer_git_env:::touched
    class AuthResolver:::touched
    class CloneEngine:::touched
    class DownloadDelegate:::touched
    class RefResolver:::touched
    class _ado_auth_header:::touched
    class _build_validation_attempts:::touched
    classDef touched fill:#fff3b0,stroke:#d47600
Loading
flowchart TD
    A["apm install / apm run"] --> B["AuthResolver._build_git_env\nsrc/apm_cli/core/auth.py:937"]
    B --> C["[I/O] AuthResolver._clear_git_auth_env\nauth.py:962 -- strip auth channels, retain non-auth"]
    C --> D{"scheme == bearer\nAND host_kind == ado?"}
    D -- yes --> E["set_ado_bearer_git_env(env, token)\ngithub_host.py"]
    D -- no --> F["env GIT_TOKEN = token"]
    E --> G["set_authorization_header_git_env\ngithub_host.py"]
    G --> G0["reject if scheme/credential contains CR or LF"]
    G0 --> G1["parse GIT_CONFIG_COUNT"]
    G1 --> G2["filter: drop extraheader key or value startswith authorization:"]
    G2 --> G3["pop all GIT_CONFIG_KEY_/VALUE_ orphans"]
    G3 --> G4["append http.extraheader = Authorization header"]
    G4 --> G5["reindex retained + new entry"]
    G5 --> H["[EXEC] git clone / git ls-remote\nsubprocess with env"]
    F --> H
    I["CloneEngine.execute\nclone_engine.py"] --> J{"ADO auth failure\n+ bearer eligible?"}
    J -- yes --> K["bearer_env = dict(host.git_env)"]
    K --> E
    J -- no --> L["raise / next attempt"]
    M["DownloadDelegate._download_github_file_via_git\ndownload_strategies.py"] --> N["git_env = dict(auth_ctx.git_env)"]
    N --> O["set_authorization_header_git_env(git_env, Bearer, token)"]
    O --> P["git_env.pop GIT_TOKEN"]
    P --> H
    Q["_ado_auth_header\nclient.py"] --> R["parse GIT_CONFIG_COUNT from git_env"]
    R --> S{"any VALUE_i startswith\nauthorization: bearer?"}
    S -- yes --> T["return Authorization header"]
    S -- no --> U["return Authorization: Basic b64(:token)"]
    V["RefResolver._build_env\nref_resolver.py"] --> W{"bearer + token?"}
    W -- yes --> X["set_ado_bearer_git_env(env, token)"]
    W -- no ado_host --> Y["set_authorization_header_git_env(env, Basic, cred)"]
    X --> H
    Y --> H
Loading

Full per-persona findings

Python Architect

No findings.

CLI Logging Expert

No findings.

DevX UX Expert

No findings.

Supply Chain Security Expert

No findings.

OSS Growth Hacker

No findings.

Auth Expert

No findings.

Doc Writer

No findings.

Test Coverage Expert

No findings.

Performance Expert

No findings.

This panel is advisory. It does not block merge. Re-apply the panel-review label after addressing feedback to re-run.


Shepherd-driver convergence report

Folded in this run

  • (panel) Add TODO(Extract shared retain/reindex predicate for git auth-config entries (follow-up to #2368) #2398) cross-reference and file a tracking issue for extracting the shared retain/reindex predicate into utils/git_env.py (python-architect + auth-expert convergent finding) -- resolved in 36f38adb3d.
  • (panel) Tighten the auth-channel value filter from a broad 'authorization' substring match to startswith('authorization:') to avoid false-positive-stripping a retained non-auth entry (supply-chain-security-expert) -- resolved in 36f38adb3d.
  • (panel) Add a CRLF rejection guard on scheme/credential before appending the git-config value, defense-in-depth against header/config smuggling (supply-chain-security-expert) -- resolved in 36f38adb3d.
  • (panel) Reclassify the CHANGELOG #2368 entry from Fixed to Security, matching this project's own precedent for silently-dropped-hardening restorations (doc-writer) -- resolved in 381a2169de.
  • (panel) Reword the CHANGELOG entry to lead with the user-visible symptom before the GIT_CONFIG_* mechanism explanation (devx-ux-expert) -- resolved in 381a2169de.

Also folded (shepherd CI-recovery and canonical-owner gate, not panel/Copilot follow-ups):

  • Stripped a stray UTF-8 BOM from two new test files that broke both the Lint (ruff format) and Test Architecture Ratchets (ast.parse SyntaxError: invalid non-printable character U+FEFF) CI jobs -- resolved in 509a98ae27.
  • Added an AC19 static boundary guard (scripts/lint-architecture-boundaries.sh) and matching tests/integration/test_architecture_authorities.py assertions for the split-authority repair this PR performs -- resolved in f6dc00288f.

Copilot signals reviewed

  • (PR-level review, no inline comments) -- NOT-LEGIT: the only Copilot signal across 2 fetch rounds is a review-level summary/overview comment (state=COMMENTED) describing the diff file-by-file; it contains zero inline actionable comments. Nothing to fold or defer.

Regression-trap evidence (mutation-break gate)

  • tests/unit/test_github_host.py::test_set_authorization_header_rejects_crlf_in_scheme_or_credential -- deleted the CRLF rejection guard; test FAILED as expected (DID NOT RAISE <class 'ValueError'>); guard restored.
  • tests/unit/test_github_host.py::test_set_authorization_header_does_not_false_positive_on_substring_authorization -- reverted the tightened filter to the old broad substring match; test FAILED as expected (assert '1' == '2'); tightened filter restored.
  • tests/integration/test_architecture_authorities.py::test_git_auth_header_injection_has_single_owner and test_git_auth_header_owner_guard_rejects_dictmerge_reintroduction -- deleted the AC19 guard block; both tests FAILED as expected (guard returncode 0 instead of 1); AC19 restored.

Lint contract

uv run --extra dev ruff check src/ tests/ and uv run --extra dev ruff format --check src/ tests/ both silent. uv run --extra dev python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ rated 10.00/10. bash scripts/lint-auth-signals.sh and bash scripts/lint-architecture-boundaries.sh (including the new AC19 rule) both clean. All run silent on exact head f6dc00288fb9d9149a648c57f829c2340b62a362.

CI

All 15 required checks green on head f6dc00288fb9d9149a648c57f829c2340b62a362 (after approving the fork-workflow action_required gate for a first-time contributor): APM Self-Check, Analyze (actions), Analyze (python), Build & Test Shard 1/2 (Linux), CodeQL, Coverage Combine (Linux), Lifecycle Smoke (Linux), Lint, NOTICE Drift Check, PR Binary Smoke (Linux), Spec conformance gate, Test Architecture Ratchets, Windows Compatibility Gate, gate, license/cla (after 0 CI-recovery iterations on this push -- the two pre-push failures seen on the prior head, both caused by the stray BOM, were fixed locally before pushing and never recurred).

Mergeability status

Captured from gh pr view 2382 --repo microsoft/apm --json mergeable,mergeStateStatus,statusCheckRollup immediately after the last push of this run.

PR head SHA CEO stance iters folds defers Copilot rounds CI mergeable mergeStateStatus notes
#2382 f6dc00288f ship_now 1 5 0 2 green MERGEABLE BLOCKED pending required review

Convergence

1 outer iteration(s); 2 Copilot round(s) (drained, zero actionable comments). Final panel verdict: ship_now.

Ready for maintainer review.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 229b302 into microsoft:main Jul 30, 2026
16 checks passed
Sergio Sisternes (sergio-sisternes-epam) pushed a commit that referenced this pull request Jul 30, 2026
Adopt main's canonical git-auth setters and repair regressions the
strangler-fig split had silently introduced.

Auth (6 conflicts, all in the GIT_CONFIG overlap):
- Main landed #2382, its own fix for the GIT_CONFIG clobber this branch
  had fixed bespoke and filed as #2368. Main's
  set_authorization_header_git_env / set_ado_bearer_git_env are strictly
  better (they also strip stale auth entries, drop orphans beyond COUNT,
  and validate CR/LF), so adopt them wholesale.
- Delete the now-dead bespoke _append_git_config_entry from
  marketplace/ref_resolver.py -- AC19 requires a single owner.
- _auth_support._build_git_env now delegates to set_ado_bearer_git_env.
- _client_ado._ado_auth_header takes main's verbatim, GIT_CONFIG_COUNT-
  bounded scheme sniff; the branch's version scanned unbounded.
- download_strategies_ops.py was NOT conflicted but carried the same
  clobber -- silent collateral of the relocation. Fixed in place.

File-length gate:
- utils/github_host.py grew past this PR's own 800-line MAX_LINES (829).
  Extract the ADO-URL family into utils/_github_host_ado_urls.py (734
  now). The auth helpers stay put: test_architecture_authorities.py is
  path-keyed to github_host.py for them.

Regressions restored in deps/download_strategies_ops.py (5, each
verified against main):
- _build_download_http_error / _build_download_network_error had zero
  callers -- all 4 call sites were lost in the split. Reconnected.
- The raw-URL path swallowed non-200/non-404 and RequestException
  instead of raising.
- _gh_auth_failed_msg lost the `if is_github_host:` nesting, dropping
  the whole "No APM-managed token was sent" generic-host guidance and
  the trailing verbose hint.
- download_github_file called auth_resolver.resolve() directly rather
  than the _resolve_dep_auth_ctx boundary, attaching managed PATs to
  generic hosts. Security fix.

Verification: all 8 CI gates green; tests/unit 19061 passed;
tests/test_github_downloader.py at exact parity with main
(7 failed / 112 passed, identical names -- pre-existing).

Co-authored-by: Copilot App <[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.

GIT_CONFIG_COUNT clobber in clone/download paths drops inherited git hardening settings

3 participants