Skip to content

fix(auth): normalize whitespace in auth-config env-var/id references at store time#3691

Merged
mnriem merged 2 commits into
github:mainfrom
jawwad-ali:fix/auth-config-normalize-env-refs
Jul 24, 2026
Merged

fix(auth): normalize whitespace in auth-config env-var/id references at store time#3691
mnriem merged 2 commits into
github:mainfrom
jawwad-ali:fix/auth-config-normalize-env-refs

Conversation

@jawwad-ali

Copy link
Copy Markdown
Contributor

What

In load_auth_config, the fields token_env, client_secret_env, tenant_id, and client_id are validated on their .strip()ed form (proving they're non-empty ignoring surrounding whitespace) but then stored raw on the AuthConfigEntry.

So an accidentally padded value (e.g. "token_env": " GH_TOKEN ") passes validation, yet downstream:

  • base.pyos.environ.get(entry.token_env)
  • azure_devops.pyos.environ.get(entry.client_secret_env, ""), and tenant_id/client_id used verbatim in the OAuth URL/body

…all use the padded name literally, so the env var is never found. load_auth_config succeeds with no error, but resolve_token returns None and the request silently downgrades to unauthenticated (401/403 on private resources) with no diagnostic — the classic validate-normalized-but-store-original bug.

The hosts field in the same function already does it right (hosts = [h.strip().lower() for h in hosts]); these references were just never given the same normalization.

Fix

A module-level _norm helper strips whitespace-insignificant string references at store time (non-strings like None pass through). Applied to token_env, tenant_id, client_id, client_secret_env. token is left unchanged (already stripped at resolve time in base.py).

Tests

tests/test_authentication.py::TestLoadAuthConfig::test_padded_token_env_is_normalized_and_resolves — a " GH_TOKEN " config now stores "GH_TOKEN" and GitHubAuth().resolve_token(...) finds the token. Fails before the fix (resolve_token returns None). Full auth suite (140 tests) passes; ruff clean.


AI-assisted: authored with Claude Code. Verified the validate-vs-store asymmetry against the hosts sibling and confirmed fail-before/pass-after end-to-end through resolve_token.

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

Normalizes whitespace in authentication config references before downstream use.

Changes:

  • Adds _norm for string references.
  • Normalizes token and Azure credential references.
  • Adds end-to-end coverage for padded token_env.
Show a summary per file
File Description
src/specify_cli/authentication/config.py Normalizes stored authentication references.
tests/test_authentication.py Tests padded token environment resolution.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread src/specify_cli/authentication/config.py
@mnriem

mnriem commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

jawwad-ali and others added 2 commits July 24, 2026 13:28
…at store time

token_env, client_secret_env, tenant_id, and client_id were VALIDATED on
their .strip()ed form but STORED raw, so an accidentally padded value passed
validation yet silently broke the downstream verbatim os.environ.get(name) /
OAuth-URL lookups — load_auth_config succeeded but resolve_token returned
None and the request quietly downgraded to unauthenticated (401/403) with no
diagnostic.

Normalize these whitespace-insignificant string references with a _norm
helper at store time, mirroring how `hosts` is already normalized
(h.strip().lower()). `token` is unchanged (already stripped at resolve time).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Address review: the regression test only covered token_env, but the fix also
normalizes tenant_id, client_id, and client_secret_env. Add a padded
azure-ad entry asserting all three are stored stripped.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jawwad-ali
jawwad-ali force-pushed the fix/auth-config-normalize-env-refs branch from dea5ad8 to a910632 Compare July 24, 2026 08:28
@mnriem
mnriem requested a review from Copilot July 24, 2026 15:54

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.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@mnriem
mnriem merged commit 71e6201 into github:main Jul 24, 2026
14 checks passed
@mnriem

mnriem commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

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.

3 participants