Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#58 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
github, gitlab, typescript
Área
api, backend

Línea de trabajo

Comienza en src/prompt-generators/github/github.ts, en resolveToken y el flujo del constructor/searchIssues de GitHub; después, compara la lógica correspondiente en src/prompt-generators/gitlab/gitlab.ts. Verifica que una variable de entorno faltante o vacía nombrada explícitamente produzca un error claro, mientras que el comportamiento de fallback existente permanezca sin cambios cuando se omite tokenEnv.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
2
Forks
1
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de joewalker/loop-the-loop

Todos los issues de joewalker/loop-the-loop

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.