Skip to content

Commit 4257cfc

Browse files
committed
fix: token checker
1 parent b6df7f4 commit 4257cfc

5 files changed

Lines changed: 23 additions & 8 deletions

File tree

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Environment Variables Configuration
22
# Copy this file to .env and fill in your values
33

4-
# GitHub Personal Access Token
4+
# GitHub token (Personal Access Token or fine-grained token)
55
# Create a token at: https://github.com/settings/tokens
6-
# Required permissions: repo (full control of private repositories)
6+
# Required permissions: repo or repository contents access for the target repository
77
# WARNING: Never commit this file or expose the token publicly!
8-
VITE_API_KEY=your_github_personal_access_token_here
8+
VITE_API_KEY=your_github_access_token_here
99

1010
# Security Notes:
1111
# - Keep this token secure and never share it

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ For more details about bundle analysis and performance monitoring, see [BUNDLE_I
3636
This application implements several security measures to protect sensitive data:
3737

3838
### API Token Security
39-
- ✅ GitHub Personal Access Tokens are stored in environment variables only
39+
- ✅ GitHub access tokens (Personal Access or fine-grained tokens) are stored in environment variables only
4040
-**Service Worker Protection**: Tokens are stored in IndexedDB and injected by service worker
4141
-**Network Tab Security**: Authorization headers are not visible in DevTools Network tab
4242
- ✅ Tokens are never logged in console output or error messages
@@ -67,7 +67,7 @@ cp .env.example .env
6767
```
6868

6969
**Required environment variables:**
70-
- `VITE_API_KEY`: GitHub Personal Access Token with `repo` scope
70+
- `VITE_API_KEY`: GitHub Personal Access Token or fine-grained token with repository access (`repo` or `contents` permissions)
7171

7272
**Security best practices:**
7373
- Never commit `.env` files to version control

SERVICE_WORKER_SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This implementation uses a Service Worker to securely handle GitHub API authenti
66
## Architecture
77

88
### 1. Token Storage
9-
- GitHub Personal Access Token is stored in IndexedDB within the Service Worker context
9+
- GitHub access tokens (Personal Access or fine-grained tokens) are stored in IndexedDB within the Service Worker context
1010
- Token is never accessible from the main application thread after initial setup
1111
- Token is encrypted at rest using browser's IndexedDB security
1212

src/lib/apiErrorHandler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ function isRateLimitError(error: any): boolean {
3535
'rate limit',
3636
'api rate limit',
3737
'too many requests',
38-
'403 forbidden', // GitHub returns 403 for rate limits
3938
'secondary rate limit',
4039
'exceeded',
4140
'limit exceeded'
4241
];
4342

44-
return rateLimitPatterns.some(pattern => message.includes(pattern));
43+
return (
44+
error.status === 429 ||
45+
rateLimitPatterns.some(pattern => message.includes(pattern))
46+
);
4547
}
4648

4749
// Export for use in components

src/lib/github.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ async function createGitHubError(res: Response): Promise<Error> {
3636
// ignore parse errors
3737
}
3838

39+
if (res.status === 403 && detail) {
40+
const normalized = detail.toLowerCase();
41+
if (/rate limit|secondary rate limit|exceeded|too many requests/.test(normalized)) {
42+
// Keep GitHub rate limit message as-is for user clarity
43+
} else if (/resource not accessible|permission|access denied|forbidden|repository access/.test(normalized)) {
44+
detail = 'The provided GitHub token does not have permission to access this repository. Use a GitHub fine-grained token with repository access or a PAT with repo/content permissions.';
45+
}
46+
}
47+
48+
if (res.status === 401 && !detail) {
49+
detail = 'Invalid or missing GitHub token. Check your VITE_API_KEY and token permissions.';
50+
}
51+
3952
const message = detail
4053
? `GitHub API error: ${res.status} ${statusText} - ${detail}`
4154
: `GitHub API error: ${res.status} ${statusText}`;

0 commit comments

Comments
 (0)