GitHub.resolveToken: explicit tokenEnv pointing at an unset env var silently sends unauthenticated requests
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- github, gitlab, typescript
Direzione di ricerca
Inizia in src/prompt-generators/github/github.ts, passando da resolveToken e dal flusso del costruttore/searchIssues di GitHub, quindi confronta la logica corrispondente in src/prompt-generators/gitlab/gitlab.ts. Verifica che una variabile d’ambiente esplicitamente nominata, ma mancante o vuota, produca un errore chiaro, mentre il comportamento di fallback esistente rimanga invariato quando tokenEnv viene omesso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Observed behavior
resolveToken in src/prompt-generators/github/github.ts returns the value of process.env[options.tokenEnv] whenever tokenEnv is set, without checking whether that variable actually has a value:
function resolveToken(options: GitHubConstructorOptions): string | undefined {
if (options.token !== undefined) {
return options.token;
}
if (options.tokenEnv !== undefined) {
return process.env[options.tokenEnv];
}
return process.env['GITHUB_TOKEN'] ?? process.env['GH_TOKEN'];
}
If the user explicitly configures tokenEnv: 'CI_GITHUB_TOKEN' in a JSON config (the recommended path for storing tokens out of files) but the environment variable is missing or empty, process.env[options.tokenEnv] returns undefined. The constructor then sets this.#token = undefined, and searchIssues proceeds to call the GitHub API anonymously, hitting the much smaller unauthenticated rate limit (60 requests/hour shared per IP, with search subject to even tighter limits).
The user receives no signal that their token was not picked up. The first symptom is usually a 403 rate limit exceeded from GitHub after a handful of requests, with no hint that the cause was a typo in tokenEnv or a forgotten export in the shell.
The fallback branch (no tokenEnv set) is intentionally permissive because the caller did not request a specific env var, but the explicit-tokenEnv branch is asking for a specific token, so silently falling back to anonymous is surprising.
Expected behavior
When tokenEnv is explicitly supplied, an unset or empty value for that env var should produce an immediate, clear error from the GitHub constructor (or from searchIssues), rather than silently sending anonymous requests.
Minimal reproduction
import { GitHub } from 'loop-the-loop/prompt-generators/github/github';
delete process.env['CI_GITHUB_TOKEN'];
const github = new GitHub({ tokenEnv: 'CI_GITHUB_TOKEN' });
// No error. Subsequent searchIssues() calls go out without
// an Authorization header.
Suggested fix
In resolveToken, throw when the named env var is missing or empty:
if (options.tokenEnv !== undefined) {
const value = process.env[options.tokenEnv];
if (value === undefined || value === '') {
throw new Error(
`GitHub tokenEnv '${options.tokenEnv}' is not set; either set the env var or omit tokenEnv to fall back to GITHUB_TOKEN/GH_TOKEN`,
);
}
return value;
}
Note: the same pattern exists in src/prompt-generators/gitlab/gitlab.ts (resolveToken); a matching fix there would keep the two clients consistent.
- Lingua principale
- TypeScript
- Stelle
- 2
- Fork
- 1
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di joewalker/loop-the-loop
-
bug S4
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal informationApertabug S3
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
joewalker/loop-the-loop#79 ·
Tutte le issue di joewalker/loop-the-loop
Issue simili
-
Native Web
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
digitalfabrik/integreat-app#4517 ·
I maintainer di solito rispondono entro 2 giorni
-
TLS guide repeats certs/ in the certificate directoryForse già presa @maheshrijal l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
prometheus/docs#3156 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
medusajs/dtc-starter#90 ·
I maintainer di solito rispondono entro 1 giorno
-
usability
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
inmanta/web-console#7632 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
zaidmukaddam/scira#261 ·