Skip to content

Stop leaking an OIDC session on every client-credentials token refresh - #2257

Merged
dirkkul merged 1 commit into
mainfrom
fix_oidc_session_settings
Nov 16, 2026
Merged

dirkkul merged 1 commit into
mainfrom
fix_oidc_session_settings

Conversation

@dirkkul

@dirkkul dirkkul commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Each refresh of a client-credentials token built a new OAuth2Client, requested two tokens on it and never closed it. Every round left behind a connection pool and its SSL context, plus one transport per configured proxy now that the session follows the connection's proxies.

The refresher now calls fetch_token() on the client's own session, which already holds the client id, secret, scope and token endpoint. A round sends one token request and builds nothing.

A sync close() that lands while a refresh is in flight no longer warns that the token issuer could not be reached.

Copilot AI balanced review requested due to automatic review settings November 13, 2026 13:01

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

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 review issues are reported for the OAuth2 session-reuse changes.

No open issues 🎉

What changed in this PR

Fixes OIDC session leaks during client-credentials token refresh by reusing the connection’s existing OAuth2 session instead of creating a new one each time.

Changes:

  • Uses the existing session for both sync and async refreshes, reducing each refresh to one token request.
  • Suppresses refresh-failure warnings when synchronous shutdown is already underway.
  • Adds regression coverage for credential-based refreshes, session leaks, and bearer tokens without refresh tokens.
File Description
weaviate/​connect/​v4.py Reuses OAuth2 sessions for token renewal and suppresses shutdown-related warnings.
mock_tests/​test_auth.py Extends sync and async refresh tests and checks that nonrenewable bearer tokens start no refresher.

Review effort: Balanced

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.43%. Comparing base (7cb3af2) to head (8c61af5).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
weaviate/connect/v4.py 90.00% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2257      +/-   ##
==========================================
+ Coverage   89.41%   89.43%   +0.02%     
==========================================
  Files         314      314              
  Lines       24861    24886      +25     
==========================================
+ Hits        22229    22257      +28     
+ Misses       2632     2629       -3     

☔ 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.

@weaviate-proov-pr-reviewer

Copy link
Copy Markdown

Proov triage

Check Result
What this PR does Replaces per-refresh creation of a throwaway OAuth2Client with fetch_token() on the connection's own session for client-credentials token renewal, and suppresses the refresh-failure warning during close().
Risk 🟠 Amber — Auth token refresh path in production code; contained blast radius but touches credential handling.
Recommendation Human review required — Auth/credential flow change; tests are decent but an owner should verify token semantics.

Advisory, generated by Proov (deepseek-v4.1-flash) at 8c61af5. The review follows.

@weaviate-proov-pr-reviewer

Copy link
Copy Markdown

Proov review: approve-with-comments

The fix itself looks right — the refresher now renews on the session it owns, and the security pass confirms the grant is unchanged. What's missing is proof: the new shutdown.is_set() guard is untested.

  • weaviate/connect/v4.py:596 — the PR's headline claim (close() during a refresh no longer warns) rests on this guard, and no test drives close() concurrently with a refresh. It could be removed and the suite stays green. Add a test that blocks the /auth handler, starts a refresh, closes mid-flight, and asserts no Con001.
  • mock_tests/test_auth.py:203 — _reject_refreshes never reaches the client-credentials branch, so the rewritten fetch_token() failure path is unverified.
  • mock_tests/test_auth.py:417 — the "no refresher" test compares thread names, not thread objects; the sibling test at :307 already notes that's the weaker check.

Nits: mock_tests/test_auth.py:176 duplicates the async test; weaviate/connect/v4.py:554's new gate isn't exercised across close()+connect().

CI is green (129 success, 1 skipped).

review-branch@c31ceb2 · deepseek-v4.1-flash · tests not run · advisory

@dirkkul
dirkkul merged commit 2ec127a into main Nov 16, 2026
130 checks passed
@dirkkul
dirkkul deleted the fix_oidc_session_settings branch November 16, 2026 03:57
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.

4 participants