Skip to content

fix(connect): prevent bootstrap JWT leakage via repr and redirects#466

Open
tdstein wants to merge 1 commit intofeat/bootstrap-auth-tls-verify-python-settings-content-buildfrom
fix/bootstrap-jwt-no-leak-in-errors
Open

fix(connect): prevent bootstrap JWT leakage via repr and redirects#466
tdstein wants to merge 1 commit intofeat/bootstrap-auth-tls-verify-python-settings-content-buildfrom
fix/bootstrap-jwt-no-leak-in-errors

Conversation

@tdstein
Copy link
Copy Markdown
Collaborator

@tdstein tdstein commented Apr 9, 2026

Summary

Defensive hardening around Client.bootstrap() and BootstrapAuth to guarantee the short-lived bootstrap JWT cannot leak through reprs, exception chains, or HTTP redirects.

  • BootstrapAuth.__repr__ / __str__ now mask the token as BootstrapAuth(token=***).
  • Client.bootstrap() wraps the session call in try/except and raises a generic RuntimeError("Bootstrap authentication failed") from Nonefrom None suppresses the chained cause so the token cannot leak via traceback objects (e.g. requests exceptions carrying the prepared request).
  • Passes max_redirects=0 to the session call so the JWT cannot follow any redirect.
  • Session is always closed in finally.

Test plan

  • repr/str/f-string of BootstrapAuth(token="SEKRET") does not contain the token
  • Failing bootstrap (401) raises without the token in str(exc) / repr(exc) and uses the generic message
  • 7 tests passing (test_auth.py + TestClientBootstrap)
  • CI

Targets feat/bootstrap-auth-tls-verify-python-settings-content-build — the bootstrap code was introduced there (#463).

- BootstrapAuth now has an explicit __repr__/__str__ that masks the token.
- Client.bootstrap wraps the POST in try/except and re-raises a generic
  RuntimeError("Bootstrap authentication failed") with the cause
  suppressed so the underlying exception (which may include request
  details) cannot surface the JWT via str(exc).
- Pass max_redirects=0 to session.post so the bootstrap JWT cannot be
  forwarded on any redirect.
- Add tests asserting repr(BootstrapAuth(...)) does not contain the
  token and that a failing bootstrap raises without leaking the token.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 9, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2392 2242 94% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/posit/connect/auth.py 100% 🟢
src/posit/connect/client.py 99% 🟢
TOTAL 100% 🟢

updated for commit: ff2d36b by action🐍

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.

1 participant