Skip to content

Authenticated GET cache is not isolated by token #241

Closed

Description

@rundel

gh() caches GET responses by URL without distinguishing authentication tokens. This causes token-dependent GET responses to be reused after the caller switches tokens, potentially returning data associated with the previous token.

valid_token <- gh::gh_token()
invalid_token <- paste0("ghp_", strrep("x", 36))

first <- gh::gh("/user", .token = valid_token)
second <- gh::gh("/user", .token = invalid_token)

identical(first$login, second$login)
#> [1] TRUE

# Disabling the cache produces the expected authentication error.
options(gh_cache = FALSE)
gh::gh("/user", .token = invalid_token)
#> Error: GitHub API error (401): Bad credentials

Expected behavior: authenticated responses should never be reused across tokens. GitHub responses use Vary: Authorization, so the cache should account for that header, partition entries by authentication context, or avoid caching authenticated requests.

Observed with gh 1.6.1.

If this makes more sense as an upstream issue with httr2 I'm happy to move it there.

Activity

  1. added
    bugan unexpected problem or unintended behavior
    on Sep 2, 2026
  2. gaborcsardi commented on Sep 2, 2026

    @gaborcsardi
    Member

    @rundel If you want a quick release, please confirm that this works for you and I'll make a release.

  3. rundel commented on Sep 2, 2026

    @rundel
    ContributorAuthor

    I don't need a quick release - I opened this before I opted to shut off cacheing entirely in ghclass. It was the cause of a couple of weird bugs we were seeing (what I get for not paying attention to the gh news file) but the crude approach was pushed for our latest release so we're all good for the moment.

  4. rundel commented on Sep 2, 2026

    @rundel
    ContributorAuthor

    Can confirm the fix works with the pre-cache-nuke version of ghclass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions