Sub topic 9
App permissions and webhook events
This chapter assumes you know what a GitHub App and an installation are, and that you have set fine-grained permissions on a personal access token. Here you will see how an app's permissions and its webhook events fit together, and why one does not imply the other.
Two separate settings
A GitHub App has two configuration areas that are easy to confuse.
- Permissions decide what the app may read or write through the API. They use the same model as fine-grained tokens: each permission (for example Contents, Issues, Pull requests) has an access level of No access, Read-only, or Read and write.
- Webhook events decide what GitHub sends to your server when something happens, such as a pull request being opened.
Permissions control access. Events control notification. An app can receive an event it cannot act on, and it can hold a permission without subscribing to any event.
Permissions are set on the app, then granted per installation
You declare the maximum permissions on the app itself. Each installation then approves those permissions for the repositories it covers. Installation access tokens can never exceed what the installation approved.
Permissions fall into three groups: repository, organization, and account (user) permissions. Repository permissions apply to the repositories chosen at install time. Account permissions apply only when the app acts for a user.
Some permissions are always included. Metadata read access is granted to every app, because many endpoints need it.
If you later add a permission, existing installations do not receive it automatically. GitHub asks the owner of each installation to review and accept the change. Until they accept, tokens keep the old permissions.
Events depend on permissions
You can only subscribe to an event if the app holds the permission that covers it. For example, subscribing to the Issues event requires the Issues permission, and the Pull request event requires the Pull requests permission. The permission level needed is at least read-only.
| Event | Permission needed |
|---|---|
| `issues` | Issues (read) |
| `pull_request` | Pull requests (read) |
| `push` | Contents (read) |
| `installation` | None, always delivered |
How a delivery flows
The webhook payload includes an installation.id. Your server uses that ID to request an installation access token for the right account, which later chapters cover in detail.
Verifying the webhook
Anyone who knows your webhook URL can send it requests. Set a webhook secret in the app settings. GitHub then signs each payload with HMAC-SHA256 and puts the result in the X-Hub-Signature-256 header. Compute the same hash over the raw request body and compare in constant time.
import crypto from "node:crypto";
export function isValidSignature(rawBody, signatureHeader, secret) {
if (!signatureHeader) return false;
const expected =
"sha256=" +
crypto.createHmac("sha256", secret).update(rawBody).digest("hex");
const a = Buffer.from(expected);
const b = Buffer.from(signatureHeader);
return a.length === b.length && crypto.timingSafeEqual(a, b);
}Use the raw bytes of the body, not re-serialized JSON. Re-serializing can change whitespace and break the match.
Common errors
- No events arrive. You may have subscribed to an event without the matching permission, or the webhook is not active. Check the app's Advanced tab, then Recent Deliveries, for status codes and a redelivery option.
- 403 "Resource not accessible by integration". The token lacks a permission, or the installation has not accepted an updated permission set.
- Signature mismatch. Usually caused by parsing the body before hashing, or by a wrong secret.
- Over-broad permissions. Request only what the app calls. Fewer permissions mean fewer approval prompts and less damage if a token leaks.
Exercise
Your app subscribes to the pull_request event and holds Pull requests read access. You later change that permission to Read and write and add the Issues permission. Existing installations still return 403 when the app comments on issues. Why, and what fixes it?
Show answer
Permission changes are not applied to existing installations automatically. Each installation owner must review and accept the updated permissions. Until they do, installation tokens keep the old permissions, so the Issues call fails with 403. Once the owner approves the request, newly created installation tokens include the new permissions.