Malformed local configuration is silently accepted and can be overwritten

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

Los mantenedores suelen responder en 1 día

@aniket866 ya está trabajando en esto.

Desde el 31/10/2026.

  • #616 de @aniket866 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
cli

Línea de trabajo

Empieza en pkg/config/localconfig.go, alrededor de las líneas 103-112, donde se ignora el error de UnmarshalLocalFile y se valida la configuración con valores cero, y luego en las líneas 416-421, donde la ruta de watch devuelve una configuración vacía si falla el unmarshal. Devuelve un error cuando falle el unmarshal, manteniendo la rama os.IsNotExist. Está terminado cuando un archivo principal o de watch malformado produce un error de YAML y el archivo queda sin cambios, y ambos casos están cubiertos por pruebas.

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

Descripción

Describe the bug
Malformed local configuration is silently accepted and can be overwritten

Evidence: pkg/config/localconfig.go:103-112 calls UnmarshalLocalFile, but does not return when that call fails; it proceeds to validate the zero-value config. The watch equivalent at :416-421 returns &config, nil even when unmarshalling fails.

Impact: A truncated or manually edited config file can be treated as an empty configuration instead of producing an error. Commands may then overwrite the corrupted file, losing contexts, servers, and cached credentials; a malformed watch file can silently erase watch entries.

steps to reproduce:

Run each command separately, pressing Enter after each command.

  1. Create a malformed main configuration file:

    set "CFG=%TEMP%\microcks-config.yaml"
    echo current-context: [broken> "%CFG%"
    type "%CFG%"
    

    The file should contain:

    current-context: [broken
    
  2. Run:

    go run . --config "%CFG%" context
    
  3. Observe that no YAML parse error is reported. The command instead reports that no contexts are defined, treating the malformed file as an empty configuration.

  4. Save a copy and compare the file after any command that writes local configuration:

    copy /y "%CFG%" "%CFG%.before"
    fc "%CFG%.before" "%CFG%"
    
  5. Repeat with a malformed watch configuration:

    set "MICROCKS_CONFIG_DIR=%TEMP%\microcks-malformed"
    mkdir "%MICROCKS_CONFIG_DIR%" 2>nul
    echo entries: [broken> "%MICROCKS_CONFIG_DIR%\watch"
    type "%MICROCKS_CONFIG_DIR%\watch"
    go run ./watcher
    

    The watcher should report a YAML parsing error. On the affected code, it starts with an empty watch configuration instead.

Suggested fix: Immediately return a typed environment/configuration error when unmarshalling fails, while preserving the existing os.IsNotExist behavior. Add tests for malformed main and watch files and verify the files remain unchanged after the failed read.

Image
Lenguaje dominante
Go
Estrellas
59
Forks
74
Merge medio
4 d 5 h
PR fusionados (30 d)
15

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 microcks/microcks-cli

Todos los issues de microcks/microcks-cli

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.