Skip to content

Commit 95c104d

Browse files
committed
feat(security): read GITHUB_TOKEN only on server & avoid client env access
- guard constructor to load env token only when window is undefined - prevent touching process.env in browser by gating source detection = reduce risk of exposing secrets client-side
1 parent bf3fb51 commit 95c104d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/lib/api/github-api-client.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ class GitHubAPIClient {
112112
private githubToken = ''
113113

114114
constructor() {
115-
// Try to get token from environment
116-
if (typeof process !== 'undefined' && process.env?.GITHUB_TOKEN) {
117-
this.githubToken = process.env.GITHUB_TOKEN;
115+
// Only read env token on the server to avoid exposing secrets client-side
116+
if (typeof window === 'undefined' && typeof process !== 'undefined' && process.env?.GITHUB_TOKEN) {
117+
this.githubToken = process.env.GITHUB_TOKEN
118118
}
119119
}
120120

@@ -169,7 +169,9 @@ class GitHubAPIClient {
169169
return {
170170
hasToken: !!this.githubToken,
171171
tokenPrefix: this.githubToken ? this.githubToken.substring(0, 10) + '...' : 'NO_TOKEN',
172-
source: this.githubToken === process.env.GITHUB_TOKEN ? 'ENV_VAR' : 'USER_SET'
172+
source: (typeof window === 'undefined' && typeof process !== 'undefined' && process.env?.GITHUB_TOKEN && this.githubToken === process.env.GITHUB_TOKEN)
173+
? 'ENV_VAR'
174+
: (this.githubToken ? 'USER_SET' : 'NONE')
173175
}
174176
}
175177

0 commit comments

Comments
 (0)