6 Reasons Smart Security Engineer Never Use Wrong Github Credential.
They Use This Instead
Hey there,
In today’s newsletter, I’m breaking down why GitHub PAT (Personal Access Token) can be security disaster and what other choices you have.
Personal access tokens are intended to access GitHub resources on behalf of the GitHub user for programmatic scenarios. PATs are tied to GitHub users.
Imagine you as Security Engineer use PAT in your Github workflows.
yaml
- uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}3 days ago your PAT leaked. You don’t know it yet. By the time you find out, the attacker has already -
Cloned your private repos.
Pushed malicious code to production.
Exfiltrated customer data.
You nervously generated a new token, updated the secret, and revoked the old one. The new one lives indefinitely until your next rotation.
What changed ? Almost Nothing.
Same blast radius.
Same unlimited lifetime.
Same zero visibility if it leaks tomorrow.
Rotation assumes you’ll detect the breach before the next rotation cycle. Most organisations don’t.
Average breach detection time is 200 days, almost half a year.
So, here’s 6 reasons why you should stop using PATs in your organization's workflows immediately to -
Prevent Supply Chain Risks
Satisfy Security Audits requirements
And build your reputation as a thoughtful security engineer.
Let’s dive in -
The 6 Reasons
Reason 1 - Does not automatically expire.
Set and forget won't work here. Every workflow that invokes PAT from secrets will receive the same token.
This creates a persistent security risk as old tokens can be forgotten but remain active across your entire GitHub environment.
Reason 2 - Work across every repo you can access.
A single PAT grants access to all repositories within its scope, not just the one where it's being used.
If compromised, an attacker gains entry to your entire repository landscape, making the blast radius of a breach significantly larger than intended.
Reason 3 - Inherit all your user permissions.
The token carries every permission your user account has, regardless of what the workflow actually needs.
This violates the principle of least privilege, as workflows often require only read access but receive full write capabilities along with all other user-level permissions.
Reason 4 - Same key Used across workflows
One leak and indefinite compromise. When multiple workflows share the same PAT, you can't isolate which workflow caused a security incident.
This also means you can't revoke access for one specific workflow without breaking all others that depend on the same token.
Reason 5 - Tied to a User
When the user leaves the organization or changes roles, all workflows using their PAT break simultaneously.
This creates operational fragility and couples your CI/CD infrastructure to individual employee lifecycles rather than organisational resources.
Reason 6 - Requires manual revocation and rotation
There's no automated mechanism to refresh or rotate PATs, making security hygiene entirely dependent on manual processes.
Organisations must track expiration dates, coordinate rotation across all workflows, and ensure no gaps in service during updates, all error-prone human tasks.
These 6 reasons make PATs a risky choice for production workflows. So what's the alternative?
The Authentication Choice
GitHub workflows have 3 primary ways to authenticate:
GITHUB_TOKEN (the automatic one)
Tied to the repository that contains the workflow.
Expires automatically when your workflow completes.
Leak it during a run? Your window of exposure is minutes, not months.
No rotation needed. No secrets to manage. The token self-destructs.
GitHub App Tokens (the enterprise choice)
Live for 1 hour maximum.
They require explicit permission grants.
Every action is logged with the app’s identity.
You can revoke all tokens instantly by uninstalling the app.
Fine-grain PAT
PATs with repo-specific scopes—better than classic PATs.
Configurable Expiration Time.
Most teams ask: “What can this token do?”
What you should be asking: “How long does this token last if leaked?”
Because 2 things are guaranteed.
You will lose control of credentials eventually.
You won’t detect it immediately.
And choosing the right token for right job is difference between an incident and disaster.
Your Decision Framework
Here’s how to think about authentication choice in your workflows.
Use GITHUB_TOKEN When
Your workflow only needs repo-scoped access.
You’re doing standard CI/CD within one repository.
You want zero credential management overhead.
Why this works: automatic expiration + minimal scope = minimum blast radius. The token can’t escape its context.
Use GitHub App Tokens When
Your workflow needs cross-repo access.
You need granular, auditable permissions.
You’re in an enterprise with compliance requirements like SOC2 or FedRAMP.
Why this works: short-lived tokens + explicit permissions + audit trail = a defensible security posture.
When auditors ask “who did what,” you have answers. When tokens leak, they expire before attackers can weaponize them.
Here’s how to implement it.
Create a GitHub App with only the permissions you need. Install it on specific repos. Generate installation tokens in your workflow.
Each token lives for 60 minutes maximum.
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
That’s it. Every run gets a fresh token. Every token expires automatically.
Use Fine-Grained PATs Only When
You’ve explicitly documented why the above two won’t work.
You have compensating controls like secret scanning and monitoring.
Your business accepts the risk of indefinite exposure.
If you must use PATs, do it with eyes wide open.
Set the shortest expiration GitHub allows.
Scope it to the minimum repos.
Enable secret scanning.
Monitor for unexpected usage.
Document the business justification.
When Your Workflow Breaks
The most common roadblock: “Our workflow needs to trigger another workflow, and GITHUB_TOKEN can’t do that.”
This happens because of GitHub’s security design.
Workflows can’t chain-trigger each other with automatic tokens. It prevents infinite loops and abuse.
This is where teams reflexively reach for PATs. Don’t.
Use a GitHub App token instead.
It has the right permission model for cross-workflow triggers. It expires after the job completes. It gives you audit trails.
Or rethink whether you need the chain trigger at all. Sometimes the workflow design is the problem, not the authentication.
If you’re stuck with legacy systems that genuinely require PATs, at least contain the damage.
Create a separate GitHub account for automation. Limit its permissions to exactly what’s needed. Rotate its PATs weekly, not monthly. Monitor every use.
Your Path Forward
Go to your organisation’s GitHub and look for any secret named like
GH_TOKEN
GITHUB_PAT
PERSONAL_ACCESS_TOKEN
For each one, ask 3 questions.
Could this use GITHUB_TOKEN instead ? If the workflow only touches its own repo, the answer is Yes. Replace it today.
If not, why does it need to live forever? Document the specific requirement. 9/10 times a GitHub App token solves it with better security.
What happens if this leaks and you don’t notice for a week? If the answer includes “complete compromise of production,” you have a credential that’s too powerful.
Replace your longest-lived, highest-privilege credentials first. Those are your biggest risks.Then work backwards.
Each PAT you eliminate shrinks your attack surface permanently. Each GitHub App token you add gives you automatic expiration and audit trails.
Security isn’t about perfect compliance with rotation schedules. It’s about shrinking the window between credential that is useless and credential that is compromised.
Make that window as small as possible.
Worth Noting:
GitHub Enterprise Cloud supports fine-grained PATs with repo-specific scopes—better than classic PATs, but still not as good as GitHub App tokens for workflows
Secret scanning only catches known patterns after they’re pushed—it’s detective, not preventive
Chat Soon
-Kushal
What did you think of today’s newsletter?
❤️ Loved it? → Refer it to a friend or drop a ‘Like‘ below.
🥳 Just joined? → Start here: 9 Security Principals Beginners Must Know
💡 Have ideas? → Hit reply and tell me how I can make this more useful for you.


