Scoped OAuth Permissions and Least-Privilege Testing for GitHub Apps

Stateful tests catch what stateless mocks miss about GitHub App permissions.

· 10 min read · Updated
Cover illustration for “Scoped OAuth Permissions and Least-Privilege Testing for GitHub Apps”
OAuth and SSO Flows · October 9, 2026 · 10 min read · 2,260 words

GitHub Apps and OAuth Apps both connect a third-party integration to a GitHub repository, but they get there through different permission models, and that difference is what makes least-privilege testing hard to do correctly. GitHub Apps don't work that way at all: permissions are declared statically in the app's configuration, and the scope URL parameter is simply ignored.

GitHub Apps Permission Architecture vs. OAuth Apps Scopes

An OAuth App asking for the repo scope gets full read and write access to every public and private repository the authorizing user can touch, along with repository hooks, collaborators, and deployment statuses. A GitHub App built only to label pull requests can be configured to request contents: read and pull_requests: write on a specific set of repositories, and nothing beyond that. The granularity isn't a minor convenience; it changes what a compromised credential can actually do.

Token lifecycle follows the same split. OAuth App tokens don't expire unless someone revokes them by hand, and there's no refresh mechanism built in. If a long-lived OAuth token sits in a CI secret store or a misconfigured log file, it stays valid until someone notices and pulls it.

The core architectural fact to hold onto is this: GitHub App permissions are fixed at configuration time, not negotiated at request time. That single design choice is what the rest of this piece is about, because it changes how a team can ever confirm, with confidence, that an app behaves correctly at the edges of what it's allowed to do.

Why Statically Declared Permissions Create a Testing Problem

Installing a GitHub App is an all-or-nothing act for the user. The only lever a user has is which repositories the app can reach, not which permissions within those repositories it holds. A GitHub community discussion from as recently as September 2026 raised this as a security gap: the install flow lets users practice least privilege only at the repository-selection level, not at the grant level.

That constraint carries straight into testing. Because the permission set is baked into the app's identity rather than requested per session, a team can't dynamically narrow or widen scope the way an OAuth App could by passing a different scope string in a URL. Verifying that the app correctly handles a denied permission, returns the right error, degrades gracefully, and doesn't silently skip a step, requires producing a condition the live installation simply doesn't offer without reconfiguring the app itself. Reconfiguring a shared installation to test a failure path risks breaking the integration for every other user or environment depending on it.

Live credentials bring their own friction on top of that. Real repository data sits behind those credentials too, so if a test suite touches production data, it can expose or corrupt something it shouldn't. If you run a full permission-boundary suite across several scope configurations on every pull request, against live infrastructure with those constraints, the CI pipeline becomes unstable before it becomes useful. Testing a fixed permission model rigorously requires building conditions deliberately rather than hoping a live API exposes them on its own.

Permission Boundaries, Failure Paths, and Stateful Sequences in Least-Privilege Testing

Diagram: Three Layers of Least-Privilege Testing. Visualizes: Show three sequential layers that make up a complete least-privilege test suite for a GitHub App.

You need three distinct layers to cover least-privilege testing for a GitHub App completely. The third confirms that multi-step workflows behave properly when one step in the sequence has a narrower permission than a step before it.

The failure-path layer is the one teams most often skip. It's common to test that an app with checks: write can create a check run successfully. It's far less common to test what happens when checks: write is absent: does the app surface a clear, useful error and stop, or does it fail silently, or worse, attempt the operation anyway and choke on a 403 it never expected?

The stateful-sequence layer exists because GitHub workflows are cumulative by nature. A workflow that opens a pull request and then posts a review comment on it depends on that pull request object persisting between the two calls. Testing the comment step alone, against a mock that returns a fixed, canned pull request object regardless of what came before, confirms nothing about whether the actual sequence works end to end.

Real GitHub permission categories span repository contents, pull requests, issues, metadata, actions, checks, deployments, administration, and organization-level data, each mapping to a distinct capability boundary. A least-privilege suite doesn't need to cover every category GitHub exposes; it needs to cover the categories the app under test actually touches. The reason any of this matters beyond correctness is blast radius: the permission set attached to an app determines how far a compromised credential, a misconfigured integration, or a malicious dependency can move once it's inside. Validating the boundary is containment verification, done before an incident forces the question.

Why stateless mocks cannot enforce permission boundaries across sequential GitHub API calls

A stateless mock behaves like a configuration file. It sees a GET request on a given path and returns whatever response was configured for that path, with no memory of any request that came before it. Such a mock has no way to know whether a pull request posted in step one of a test actually exists by the time a review comment in step three tries to reference it.

That creates a specific kind of false confidence. A stateless mock test that passes consistently is passing because of how someone configured the mock, not because the integration correctly handles the real API. The test can be green while the integration it's supposedly validating is broken in production.

For permission testing, the gap goes further. A stateless mock can be told to return a 403 on a specific configured path, but it has no mechanism to enforce a permission model dynamically across a sequence of calls. It can't represent an app holding pull_requests: read versus one holding pull_requests: write as a running condition, because real enforcement requires tracking what operations have already happened and against which objects they were performed. A mock with no memory can't track any of that.

Recorded cassette-style replays share the same weakness from a different angle. A cassette captures real API responses recorded under one specific permission configuration and plays them back verbatim. It can't represent a different permission scope than the one it was recorded under, and when the live API changes behavior, the cassette keeps replaying its old responses without any signal that it's drifted out of sync.

None of this means stateless tools are worthless. For isolated contract validation, confirming that a single request is well-formed and that the response comes back in the expected shape, a stateless mock runs fast and catches basic regressions cheaply. Contract validation and permission-boundary validation are different jobs, though, and treating the first as a substitute for the second is where the failure mode actually sits.

A Stateful, Continuously Verified GitHub Simulator for Permission Scopes in CI

Rystic's GitHub simulator maintains state across calls, tracking what happened previously so later responses reflect it. It ships with pre-seeded, realistic data out of the box, and it's verified against the real GitHub API before every release, with a measured fidelity score built from a broad suite of probes run against both the live API and the simulator side by side. That verification matters because it means the permission enforcement the simulator shows reflects how GitHub actually behaves, not a developer's best guess based on reading the documentation.

Stateful enforcement is what closes the sequential-workflow gap described earlier. A review comment posted against that pull request succeeds or fails based on the simulator's permission model applied to a real, persisted object, not based on a canned response written into a config file ahead of time.

That turns permission-boundary testing into a configuration question, not an infrastructure problem. A team configures the simulator to represent a specific permission scope, runs its actual integration code against that configuration, and observes both the success path and the failure path, all without touching live credentials, without hitting a rate limit, and without reconfiguring a shared live installation that other users or environments depend on.

Because the simulator runs locally or inside a container, you can run the full permission-boundary suite in parallel on every pull request opened against the codebase. A matrix of scope configurations that would be impractical to maintain against real GitHub installations turns into a routine, repeatable CI job. The simulator also supports fault injection, meaning rate-limit responses, service-unavailable errors, and added latency can be introduced on specific permission-sensitive paths, so a team can confirm its app handles a temporarily unavailable checks endpoint without escalating privileges or landing in a broken state.

Structuring a permission-matrix test suite against the GitHub simulator

The natural way to organize this work is a matrix. One axis lists the permission categories the app actually uses: contents, pull requests, checks, issues, metadata, deployments, administration. The other axis lists the access level under test for each: none, read, write. Each cell in that matrix becomes a distinct test scenario the simulator can exercise on its own.

Layer 1 covers permitted operations succeeding.

Layer 2 covers denied operations failing correctly. For each permission the app doesn't hold, the test confirms that the simulator returns the right error code and that the app's own code surfaces a useful error, rather than silently skipping the step or attempting some unintended workaround. This is the layer where graceful degradation gets validated.

Layer 3 covers stateful sequences that cross permission boundaries. A workflow that opens a pull request with pull_requests: write, posts a check run with checks: write, and then comments with pull_requests: write again gets tested end to end, with the simulator maintaining object state across every step. That way, a failure in step three is a genuine failure tied to a real permission boundary, not an artifact of a missing object the test never actually created.

Test isolation matters across all three layers. The simulator's pre-seeded data gives each test a realistic starting point, and if the suite builds from a known baseline, it can run in any order without scenarios interfering with one another.

Applying the same approach to GitHub Actions token permissions in CI workflows

GitHub Actions workflows raise the identical problem in a different setting. A workflow's GITHUB_TOKEN inherits a default permission scope that's often broader than any individual job within that workflow actually needs, but most teams leave that default in place, because narrowing it means writing an explicit permissions: declaration at the job level, and many never get around to it.

One concrete hardening pattern is declaring an explicit, minimal top-level permissions: {} block wherever no default grant is needed, rather than omitting the block entirely (which silently inherits the repository's default token scope) or granting write access workflow-wide during development and never tightening it before shipping to production. Those are already at least privilege, so the test suite's job there isn't to shrink the permission further but to confirm it's granted only to the specific jobs that actually need it, not applied workflow-wide out of convenience.

The same testing problem runs through the rest of this piece. A team that wants to confirm a workflow behaves correctly with a read-only token, instead of the write token it currently runs with, can't safely produce that condition in a shared live repository without risking other workflows breaking or credentials being exposed in the process. Running the workflow's API calls against the Rystic GitHub simulator, configured to the specific token permissions under test, gives Actions workflows the same permission-matrix coverage already described for installed GitHub Apps: the same stateful, fault-injectable, credential-free environment, applied to a different but structurally identical problem.

Preventing permission drift as the app and the GitHub API evolve

The most dangerous form of drift doesn't announce itself. The integration's tests keep passing, the CI pipeline stays green, and nobody notices that the permission boundaries the suite was written to validate no longer match what the live GitHub API actually enforces, or what the app's current, possibly expanded, permission set now covers.

Two separate vectors drive that drift, and both need to be watched. Separately, an app's own permission declarations tend to expand over time as new features get added, and each additional permission widens the blast radius whether anyone on the team consciously registers it or not.

Rystic's continuous verification approach addresses the first vector by design: because the simulator gets re-verified against the real GitHub API before every release, a behavioral change on a permission-sensitive endpoint becomes visible as a measurable, detected fidelity gap rather than a silent divergence that only surfaces once it's already broken something in production. The second vector is a process issue. The permission matrix test suite itself can serve as the forcing function: adding a new permission to the app's configuration should require adding the corresponding test scenarios to the matrix, a step that forces a conscious review rather than letting the blast radius expand unexamined.

You should treat periodic access recertification for GitHub Apps with the same seriousness it gets for human credentials in any mature security program. Integrations accumulate permissions that felt convenient to request at some earlier point and were never actually needed for current operation, and reviewing that accumulated surface works best as a routine part of change control, not as a reactive audit that only happens after something has already gone wrong. Rystic's published fidelity scores give teams a concrete number to track over time: a score that declines between releases is a signal of API drift worth investigating before it turns into a production incident.

Sources

  1. GitHub Apps vs. OAuth Apps: Choose the right GitHub connection · Logto blog

More in OAuth and SSO Flows