[Duplicate Code] Cloud Hypervisor development-artifact bypass gate duplicated in runtime-validation and preflight-artifact-trust

Abierto Apto para principiantes
#12,411 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

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
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript
Área
security

Línea de trabajo

Lee las comprobaciones existentes en src/cloud-hypervisor/runtime-validation.ts y src/cloud-hypervisor/preflight-artifact-trust.ts; después, revisa src/cloud-hypervisor/artifact-trust.ts como ubicación propuesta para el helper. Conserva la condición de protección de cada llamador y consolida la comprobación de la variable de entorno y el mensaje de error; el trabajo estará terminado cuando ambas rutas usen el helper compartido y sigan exigiendo que la variable sea igual a '1'.

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

Descripción

code-quality refactoring

Duplicate Code Opportunity

Summary
  • Pattern: The AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS=1 opt-in check and its identical error message are repeated in two artifact-trust validation paths.
  • Locations: src/cloud-hypervisor/runtime-validation.ts and src/cloud-hypervisor/preflight-artifact-trust.ts
  • Impact: About 8 duplicated lines per copy. This is a security control (the gate that permits unattested artifacts). If the variable name, the required value, or the message changes in one copy but not the other, the two validation paths can disagree about whether the bypass is permitted.
Evidence
  • src/cloud-hypervisor/runtime-validation.ts: lines 110-117
    if (
      process.env.AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS !== '1'
    ) {
      throw new Error(
        'Cloud Hypervisor development artifact bypass requires ' +
        'AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS=1',
      );
    }
  • src/cloud-hypervisor/preflight-artifact-trust.ts: lines 73-81
    if (
      developmentBypass &&
      process.env.AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS !== '1'
    ) {
      throw new Error(
        'Cloud Hypervisor development artifact bypass requires ' +
        'AWF_CLOUD_HYPERVISOR_DEVELOPMENT_ALLOW_UNATTESTED_ARTIFACTS=1',
      );
    }

Both copies have the same env check, the same error text, and the same thrown error. Only the guarding condition differs (developmentAllowUnattestedArtifacts versus developmentBypass).

Suggested Refactoring
  • Add assertDevelopmentArtifactBypassAllowed(env = process.env) to src/cloud-hypervisor/artifact-trust.ts, which already reads env for artifact trust decisions. It should throw the canonical message when the variable is not '1'.
  • Replace both inline checks with a call to this helper, keeping each caller's own guarding condition unchanged.
  • Optionally add a unit test in artifact-trust covering the message and the '1' requirement, so both call sites are covered by one test.
Affected Files
  • src/cloud-hypervisor/runtime-validation.ts — lines 110-117
  • src/cloud-hypervisor/preflight-artifact-trust.ts — lines 73-81
  • src/cloud-hypervisor/artifact-trust.ts — target for the shared helper
Effort Estimate

Low


Detected by Duplicate Code Detector workflow. Run date: 2026-11-30

Generated by Duplicate Code Detector · copilot · routed: haiku55 xhigh · ~2 AIC · ⊞ 18.3K · history

  • expires on Dec 30, 2026, 9:54 PM UTC
Lenguaje dominante
TypeScript
Estrellas
169
Forks
89
Merge medio
5 h 18 min
PR fusionados (30 d)
450

Preparar el entorno

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 github/gh-aw-firewall

Todos los issues de github/gh-aw-firewall

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.