GitHub token (ghp_) in your JavaScript bundle? Revoke it, check your security log, move it server-side
· PlugLeak
A GitHub token (ghp_ or github_pat_) in VITE_ or NEXT_PUBLIC_ is in the JavaScript visitors download. How to find it, delete it, read the security log, and call the API from the server.
A GitHub token in frontend code is already public. Anyone who loads the site can save the JavaScript and read it. GitHub says to treat access tokens like passwords (Managing your personal access tokens). The same leak shows up in apps built with Bolt, v0, and Cursor when the page calls the GitHub API, or when the token is stored in a VITE_ or NEXT_PUBLIC_ variable.
Why the token ends up in the bundle
A generated app often gets a feature that talks to GitHub from the browser: a control that saves a file into a repository, or a content feature that reads a repository as the CMS. The page then calls api.github.com with a personal access token. If that token is a string in a client file, every visitor receives it. If it is an environment variable with a public prefix, the bundler copies the value into the same file.
Vite exposes names that start with VITE_ in client source after bundling. To avoid leaking env variables to the client, avoid that prefix. In the docs, import.meta.env.VITE_SOME_KEY is "123" and import.meta.env.DB_PASSWORD is undefined. VITE_* variables should not contain sensitive information such as API keys, because the values are bundled into your source at build time. For production, Vite says to consider a backend server or a serverless or edge function (Env variables and modes). VITE_GITHUB_TOKEN is that case. An unprefixed GITHUB_TOKEN is not placed on import.meta.env.
Next.js uses NEXT_PUBLIC_. Names without that prefix stay in the Node.js environment and are not accessible to the browser. The prefix inlines the value at build time, replacing process.env.NEXT_PUBLIC_… with a hard-coded string in the JavaScript sent to the browser. After the build, the app no longer responds to changes to those variables. They stay at the value from the environment where next build ran (Environment variables). NEXT_PUBLIC_GITHUB_TOKEN ships. GITHUB_TOKEN does not, unless client code reads it.
Which names the bundler inlines is the NEXT_PUBLIC_ and VITE_ guide. On Bolt, values the browser can read live in the project .env file, and values that must stay off the published site go in Secrets. That split is the Bolt environment variables guide. A Stripe secret or an OpenAI key shipped the same way is the Stripe frontend guide and the OpenAI frontend guide.
Which prefix is which
GitHub's credential types reference lists these prefixes. The credential revocation API accepts the same list except ghs_.
ghp_is a personal access token (classic). It is long-lived until you revoke it, it expires, or GitHub revokes it. It is tied to your user account.github_pat_is a fine-grained personal access token. The lifespan is configurable, up to 1 year or with no expiration. It is tied to your user account.gho_is an OAuth app access token. It is long-lived and tied to your user account.ghu_is a GitHub App user access token. It expires after 8 hours by default. App owners can configure these tokens never to expire. GitHub does not recommend that, because of the security implications (Token expiration and revocation).ghs_is a GitHub App installation access token. It expires after 1 hour. It is tied to an app installation, not to a personal access token page. The revocation API does not accept it.ghr_is a GitHub App refresh token. It lasts 6 months. It is tied to your user account.
GitHub says personal access tokens (classic) are less secure, and that a classic token will grant access to all repositories within the organizations that you have access to, as well as all personal repositories in your personal account. The creation warning is the same point: your personal access token (classic) can access every repository that you can access. GitHub recommends a fine-grained token instead, which you can restrict to specific repositories, with fine-grained permissions instead of broad scopes (Managing your personal access tokens).
Scopes still apply. A token has the same capabilities as its owner, and is further limited by the scopes or permissions granted to it. A token cannot grant the owner access they do not already have. A classic token with no assigned scopes can only access public information. A content feature that needed one private repository does not change the classic token's reach: within those scopes, the copy in the JavaScript can be used against every repository that account can access.
A fine-grained token is limited to resources owned by a single user or organization, then to the repositories you select, then to the permissions you grant. Choose the minimal repository access and the minimal permissions. Tokens always include read-only access to all public repositories on GitHub. GitHub recommends fine-grained tokens instead of classic tokens whenever possible. Personal access tokens are for access on behalf of yourself. To access resources on behalf of an organization, or for long-lived integrations, GitHub says you should use a GitHub App.
Search the live site
Open the deployed site. In DevTools, search Sources across the loaded files, or open a script in Network and search the response. Also open the script URL with the browser's view-source. Check lazy-loaded chunks, not only the first file. If a script names a source map (sourceMappingURL), open that .map URL and search it too. Look for:
ghp_,github_pat_,gho_,ghu_,ghs_, andghr_.VITE_GITHUB_TOKEN,NEXT_PUBLIC_GITHUB_TOKEN, and any other public prefix on a token.
Read the line before you treat a placeholder as a live token, and do not paste a match into a chat or a public page. Never push a token to a public repo or gist to trigger GitHub's auto-revocation: that publishes another copy. Delete it in settings instead.
Then run the free PlugLeak scan on the same URL. It is a passive GET of the page and same-site JavaScript, and it stops at 25 files or 12 MB. It checks /.env, /.git/config, security headers, and TLS. It detects Stripe, OpenAI, Anthropic, and AWS keys, GitHub tokens, PEM private keys, sb_secret_ keys, and service_role JWTs. The GitHub shapes it matches are ghp_, gho_, ghu_, ghs_, and ghr_ followed by exactly 36 letters or digits, and github_pat_ followed by at least 60 letters, digits, or underscores. A shorter or longer ghp_, gho_, ghu_, ghs_, or ghr_ string does not match. Search the files yourself for the prefix. It does not download source maps. It does not test Row Level Security or grants, query a database, log in, crawl, or read the repository or git history.
The scan is free, with no signup. Run it at https://plugleak.com/?utm_source=seo&utm_medium=article&utm_campaign=github-token-frontend#scan. The fix report is $9, or $29 for 10. A full refund is available within 30 days of purchase, no questions asked (refund policy). Prices are on the pricing section.
1. Delete the token
Treat a token in the bundle as exposed. GitHub says you should consider any leaked secret immediately compromised. Removing it from the code does not revoke it (Remediating a leaked secret). For a high-risk secret that is still active, the same tutorial says to revoke it immediately. If downtime is the problem, it says you can generate a replacement first, point the app at the new token, and then revoke the old one. A token already sitting in public JavaScript is the immediate case: delete it before you keep using it.
For a personal access token that belongs to you, GitHub's delete path is (Managing your personal access tokens):
- In the upper-right corner of any page, click your profile picture, then Settings.
- In the left sidebar, click Developer settings.
- In the left sidebar, under Personal access tokens, click Fine-grained tokens or Tokens (classic), matching the token you are deleting.
- To the right of that token, click Delete.
An expired or revoked token cannot be restored. You create a new one. If you delete a personal access token that was used to create a deploy key, that deploy key is deleted too. Deleting your own token is a different action from an organization owner revoking a fine-grained token: in that second case, GitHub says any SSH keys created by the token keep working, and the token can still read public resources in the organization (Credential types).
GitHub also revokes a valid OAuth token, GitHub App token, or personal access token automatically when it is pushed to a public repository or a public gist (Token expiration and revocation). The remediation tutorial says GitHub automatically revokes personal access tokens leaked in public repositories. A token that reached visitors through a deployed JavaScript file, and was not pushed to a public repository or gist, is not covered by that rule. Delete it anyway, and confirm it is gone. An unused OAuth token or personal access token is revoked after one year without use. That wait is not a response to a leak.
If you have the token value and you cannot use the settings page, GitHub's revocation API is unauthenticated. POST /credentials/revoke takes a JSON body, {"credentials":["…"]}, with up to 1000 credentials. It is for credentials the caller does not own, found on GitHub.com or elsewhere, and for a credential from an old account you can no longer access. Authenticated requests return 403. Unauthenticated traffic is limited to 60 requests per hour. A successful request returns 202. GitHub notifies the credential owner and cannot reactivate a revoked credential. The endpoint accepts ghp_, github_pat_, gho_, ghu_, and ghr_. It does not accept ghs_ (Revoke a list of credentials).
A ghs_ value is an installation access token. It expires after one hour. App owners revoke the current installation token with DELETE /installation/token. Organization owners can uninstall the app, which deactivates its installation tokens (Credential types).
2. Read the security log, then the organization audit log
After the token is revoked, look for activity you did not take. The remediation tutorial says to review the security log for your personal account and the audit log for your organization. The event names below are the ones those docs list for new tokens, SSH and deploy keys, workflow changes, repository visibility, and pushes. You cannot search either log with free text. Filter with qualifiers. The documented action example is team.create. Use the same qualifier with one of the event names below (Reviewing your security log, Reviewing the audit log for your organization).
Your security log lists actions from the last 90 days. Open it from your profile picture, then Settings, then Security log in the Archives section of the sidebar. These events are on the security log events list:
personal_access_token.createis a fine-grained personal access token you created.personal_access_token.request_createdis a fine-grained token created to access organization resources when that organization requires approval.personal_access_token.access_grantedis a fine-grained token granted access to resources. Thepersonal_access_tokencategory is fine-grained tokens. The event list does not name a separate "classic token created" action.oauth_access.createis an OAuth access token that was generated. When a personal access token, OAuth app token, or GitHub App token expires or is revoked, you may seeoauth_authorization.destroy(Token expiration and revocation). The event list describes that action as an OAuth application authorization being deleted.public_key.createis an SSH key added to a user account, or a deploy key added to a repository.repo.accessis a repository visibility change.workflows.disable_workflowis a workflow that was disabled.workflows.enable_workflowis a workflow enabled after that.workflows.delete_workflow_runis a workflow run that was deleted. Theworkflowscategory has more actions on the events page, including approve, reject, pin, and unpin.
The personal security log event list does not include git.push. Do not treat a quiet security log as proof that nobody pushed.
The organization audit log is separate. Only organization owners can open it. It keeps 180 days. The web UI shows the past three months unless you set created. The path is: profile picture, Organizations, the organization, Settings, then in the Archive section Logs, then Audit log. If you are not an owner, the remediation tutorial says you may need an organization owner or an enterprise administrator. On that log, the events page documents:
personal_access_token.request_created,personal_access_token.access_granted, andpersonal_access_token.access_revokedfor fine-grained tokens that touch the organization.access_revokedstill leaves the token able to read public organization resources. The organization event list does not includepersonal_access_token.create.public_key.create, with the same meaning as on the personal log: an SSH key on a user account, or a deploy key on a repository.repo.access, a visibility change.workflows.disable_workflow,workflows.enable_workflow, andworkflows.delete_workflow_run.workflows.created_workflow_runis also documented, and the events page says it is not available in the web interface. It is available through the REST API, audit log streaming, or a JSON or CSV export.git.pushmeans changes were pushed to a repository. It is not shown in the web interface. For GitHub Enterprise Cloud, Git events are available through the REST API only, with 7-day retention. For GitHub Enterprise Server, Git events have to be enabled in the audit log configuration and are not included in search results (Audit log events for your organization).
To tie events to the exposed token, the organization audit log stores hashed_token, a SHA-256 hash of the token used outside the web UI. Token data is recorded for a personal access token, an OAuth token, a GitHub App (as an installation or on behalf of a user), a deploy key, and an SSH key. Display of token data for SSH keys and deploy keys is in public preview. On macOS or Linux, GitHub's command is echo -n TOKEN | openssl dgst -sha256 -binary | base64. Run it on your machine. Do not paste the token into a chat or a public page. Search hashed_token:"VALUE" with the hash in quotes. Searches in the web UI and through the REST API do not return Git events. Identifying those requires an export, and display of token data on Git events is in public preview (Identifying audit log events performed by an access token).
3. Call GitHub from the server
Put a new token in GITHUB_TOKEN, with no VITE_ or NEXT_PUBLIC_ prefix. Next.js will not inline that name. Prefer a fine-grained token: one resource owner, only the repositories the route needs, an expiration, and only the permissions the call needs. On the token form, the Contents permission has read and write. The form says to choose the minimal permissions necessary. For a route that only reads a file, that is the read level. Under Expiration, select an expiration. Infinite lifetimes are allowed, but a maximum lifetime policy set by an organization or enterprise owner can block them. In the classic-token section of that page, GitHub says it highly recommends adding an expiration to your personal access tokens.
For a long-lived integration, or for access on behalf of an organization, use a GitHub App instead of a personal access token. That is the recommendation on the personal access token page.
The route below reads one file with Get repository content, GET /repos/{owner}/{repo}/contents/{path}. The headers are the ones GitHub says most REST endpoints use. sessionUserId is a stand-in for your own session check. The file response includes path, content, and encoding.
// app/api/github/route.ts
export async function GET(request: Request) {
const userId = await sessionUserId(request);
if (!userId) return new Response("Unauthorized", { status: 401 });
const token = process.env.GITHUB_TOKEN;
if (!token) return new Response("Server misconfigured", { status: 500 });
const res = await fetch("https://api.github.com/repos/OWNER/REPO/contents/PATH", {
headers: {
Accept: "application/vnd.github+json",
Authorization: "Bearer " + token,
"X-GitHub-Api-Version": "2026-03-10",
},
});
if (!res.ok) return new Response("GitHub request failed", { status: 502 });
const file = await res.json();
return Response.json({ path: file.path, encoding: file.encoding, content: file.content });
}The page calls that route and never receives the token:
const res = await fetch("/api/github");
const data = await res.json();An open /api/github still lets anyone use whatever the token can do. The handler has to see the session. A page redirect does not. The Cursor checklist is that check for Route Handlers.
A Vite app has no Next.js route handler. Put the same fetch in a backend server or a serverless or edge function that reads GITHUB_TOKEN from the host's server environment. Do not prefix that name with VITE_ (Env variables and modes).
On Bolt, keep the new token out of .env if browser code can read it. Secrets work only with server functions. Bolt reads a secret when a server function needs it, and does not write it into project files, browser code, or the published site. Open the project, click the database icon, then Secrets. The Secrets page needs a connected database. Bolt says not to paste secret values into project code (Secrets). Which values can stay in .env is the Bolt environment variables guide.
4. Redeploy, then follow the leaked-secret steps if it was committed
Remove the client string and the public env name, rebuild, and redeploy. Next.js freezes NEXT_PUBLIC_ at next build, and Vite replaces import.meta.env at build time, so a dashboard edit does not change a bundle already shipped. Search the live JavaScript again for ghp_, github_pat_, gho_, ghu_, ghs_, and ghr_. Run the free scan again. A revoked token that is still in the JavaScript still matches the scan until visitors load a build without that string. If the replacement was written into the same public variable, it is exposed too.
If the token was committed, follow Remediating a leaked secret. Revoke first. GitHub says simply removing the secret from the codebase, pushing a new commit, or deleting and recreating the repository does not prevent it from being exploited. The tutorial says the value may still be in old commits, and that cleaning history can be destructive because it may mean a force push. Removing sensitive data from a repository says the first step for a password, token, or credential is to revoke or rotate it. Once it is revoked, rewriting history may not be warranted. A history rewrite does not revoke the token. If you only rewrite history and force-push, GitHub says the commits may still be reachable in clones or forks, by SHA-1 in cached views on GitHub, and through pull requests that reference them. A rewrite also does not change a JavaScript bundle you already deployed. The remediation tutorial says to weigh a history cleanup with the repository's security leads.
FAQ
Does GitHub already revoke a token that is only in my website's JavaScript?
No. GitHub automatically revokes a valid OAuth token, GitHub App token, or personal access token when it is pushed to a public repository or a public gist. A token that appears only in the JavaScript a deployed site sends to visitors is not that case. Delete it under Settings, Developer settings, Personal access tokens, or submit the value to POST /credentials/revoke.
Is a classic ghp_ token limited to the one repository my app uses?
No. GitHub says a personal access token (classic) can access every repository you can access, and that it grants access to all repositories in organizations you have access to and all personal repositories in your account. Scopes still limit it, and a token with no scopes can only access public information. A fine-grained token can be limited to specific repositories. It still includes read-only access to all public repositories.
I deleted the line and redeployed. Is the old token safe?
No. Deleting the source line does not revoke the token. Delete it in Developer settings, or submit the value to the credential revocation API. If it was committed, GitHub says removing it from the codebase, pushing a new commit, or deleting and recreating the repository does not prevent it from being exploited. Rewriting history does not revoke it.
Can the free scan see a GitHub token that is only in git history?
No. The scan at https://plugleak.com/?utm_source=seo&utm_medium=article&utm_campaign=github-token-frontend#scan is a passive GET of the public page and same-site JavaScript (max 25 files / 12 MB). It checks /.env, /.git/config, security headers, and TLS. It detects Stripe, OpenAI, Anthropic, and AWS keys, GitHub tokens, PEM private keys, sb_secret_ keys, and service_role JWTs. The GitHub shapes it matches are ghp_, gho_, ghu_, ghs_, and ghr_ followed by exactly 36 letters or digits, and github_pat_ followed by at least 60 letters, digits, or underscores. It does not test Row Level Security or grants, query a database, log in, crawl, read the repository or git history, or download source maps.
Sources
- GitHub: Managing your personal access tokens
- GitHub: Token expiration and revocation
- GitHub REST: Revoke a list of credentials
- GitHub: Reviewing your security log
- GitHub: Security log events
- GitHub: Reviewing the audit log for your organization
- GitHub: Audit log events for your organization
- GitHub: Identifying audit log events performed by an access token
- GitHub: Credential types reference
- GitHub: Remediating a leaked secret
- GitHub: Removing sensitive data from a repository
- GitHub REST: Get repository content
- Vite: Env variables and modes
- Next.js: Environment variables
- Bolt: Secrets
Check your app now — free, passive, about 20 seconds.
Same scanner as the homepage scan. Paste the live URL. It reads what a visitor already downloads. It does not log in or query your database.
Related guides
- Stripe secret key in the frontend
- CheckVibe alternatives
- OpenAI API key in the frontend
- Claude Code settings.local.json keys
- Bolt environment variables vs Secrets
- v0 app security checklist
- Cursor app security checklist
- NEXT_PUBLIC_ and VITE_ API keys
- Lovable app data exposure check
- Supabase 42501 permission denied
- Supabase RLS checklist
- Bolt Supabase API key visible
- Supabase service_role key exposed
- Lovable app security check
- Is my vibe-coded app secure?
Scan by builder