Skip to content

[CLI] Add hf auth revoke to revoke leaked tokens - #5389

Open
Wauplin wants to merge 4 commits into
mainfrom
Wauplin/huggingface-hub-owner-s-note-ask-246c85ae
Open

Wauplin wants to merge 4 commits into
mainfrom
Wauplin/huggingface-hub-owner-s-note-ask-246c85ae

Conversation

@Wauplin

@Wauplin Wauplin commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5387. Server: huggingface-internal/moon-landing#19370, huggingface-internal/moon-landing#19443

Summary

  • hf auth revoke TOKEN...: revokes one or more tokens, e.g. leaked ones. No login needed: anyone holding the raw value can revoke it, and the token owner gets an email.
  • revoke_tokens(tokens: list[str]): same in Python, exported at top level.
  • docs: CLI guide section, package reference, regenerated CLI reference
  • not done on purpose: S3 credentials ({"accessKeyId", "secretAccessKey"}). Easy to add later if asked.

No breaking change.

Example

$ hf auth revoke hf_xxx hf_yyy
✓ Revocation requested for 2 token(s)
  count: 2

$ hf auth revoke hf_xxx --format json
{"count": 1}
>>> from huggingface_hub import revoke_tokens
>>> revoke_tokens(["hf_xxx"])

Decisions taken

  • No Authorization header: the server answers 403 when one is sent, so headers come from build_hf_headers() (user agent included) with authorization popped. Nice side effect: the user's own token can never be revoked by mistake.
  • Output says "revocation requested", not "revoked": the server always answers 202, whether the token existed or not, so we can't tell more.

Validation: make style and make quality pass, tests/test_auth.py passes. Ran the command against hub-ci (human / json / agent output, plus 1500 tokens to exercise batching). New test hits hub-ci with HF_TOKEN set and a fake token: it would 403 if the user's token leaked into the request (checked by sending the header by hand: 403). Not tested against production with a real token.

Written by Hubert.py Bot via Launchpad, posted automatically


Note

Medium Risk
Touches credential lifecycle (new unauthenticated revoke path to Hub), but behavior is intentionally narrow and avoids using the caller's stored token on the request.

Overview
Adds hf auth revoke TOKEN... and a top-level Python revoke_tokens API so anyone who has a raw token value can request revocation without logging in; token owners are notified by email.

Revocation hits POST /api/credentials/revoke with headers from build_hf_headers(token=False) (no Authorization), batches up to 1000 tokens per request, and surfaces CLI output as “revocation requested” because the Hub does not confirm whether each token existed.

Docs are updated in the CLI guide, authentication package reference, and regenerated CLI reference; revoke_tokens is exported from huggingface_hub.

Reviewed by Cursor Bugbot for commit 77676b0. Bugbot is set up for automated code reviews on this repo. Configure here.

Written by Hubert.py Bot via Launchpad, posted automatically

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread tests/test_auth.py Resolved
Comment thread tests/test_auth.py Resolved
Co-authored-by: Lucain <lucainp@gmail.com>
@Wauplin
Wauplin marked this pull request as ready for review November 19, 2026 14:59

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 19c20e5. Configure here.

Comment thread src/huggingface_hub/_login.py Outdated
if not tokens:
raise ValueError("No token to revoke.")
headers = build_hf_headers()
headers.pop("authorization", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Revoke still resolves user token

Medium Severity

revoke_tokens builds headers with build_hf_headers() and only then drops authorization. That still runs full token resolution, so an unauthenticated revoke can fail or block: HF_OIDC_RESOURCE can raise OIDCError, an OAuth token can be refreshed, and Colab can prompt for HF_TOKEN. build_hf_headers(token=False) skips that lookup and still provides the user-agent.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 19c20e5. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, fixed in 77676b0: build_hf_headers(token=False) skips token resolution entirely instead of resolving then dropping it.


Written by Hubert.py Bot via Launchpad, posted manually

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

[CLI] Add hf auth revoke to revoke leaked tokens

1 participant