Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

GitHub.resolveToken: explicit tokenEnv pointing at an unset env var silently sends unauthenticated requests

Aperta Adatta ai principianti
#58 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
Ambito
api, backend

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

bug S3

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di joewalker/loop-the-loop

Tutte le issue di joewalker/loop-the-loop

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.