bug: malformed JSON passed to --document (and other body object flags) silently passes validation
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 74/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- cli
Línea de trabajo
Start in src/factory.ts around the object-flag parsing near line 609 and schema relaxation near line 700. Reproduce the elastic stack es index command with the malformed --document value, then trace how JSON.parse failures reach validation. Done means the command reports an input_validation_failed error for invalid JSON and exits 1 instead of printing a successful dry-run payload.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
Running the following command reports success for inputs that are valid, but the JSON is malformed:
elastic stack es index \
--index test-idx \
--document '{"name":"Alice"invalid}' \
--dry-run
The command exits 0 and prints the resolved request payload without any validation error, even though {"name":"Alice"invalid} is not valid JSON.
Root cause
There are two cooperating bugs in src/factory.ts.
Bug 1 — silent catch in object-flag parsing (≈ line 609)
When a CLI flag is typed as object and JSON.parse fails, the catch block silently falls back to storing the raw string:
} else if (arg.type === 'object') {
try {
const parsed = JSON.parse(raw as string)
cliInput[arg.schemaKey] = parsed
...
} catch {
// If JSON parse fails, pass the raw value - handles schema-less fields
// that accept plain strings (e.g. connector update-error --error)
cliInput[arg.schemaKey] = raw // ← malformed JSON stored as string
}
}
The comment's rationale ("schema-less fields that accept plain strings") does not apply to --document, which is explicitly typed as object in the Elasticsearch index API schema. There is no connector update-error command in the current codebase, so the comment appears stale.
Bug 2 — schema relaxed to {} before AJV validation (≈ line 700)
Even if Bug 1 were fixed and the raw string reached validation, the validator would still accept it because body fields with type === 'object' have their JSON Schema replaced with {} (accept anything) before AJV runs:
const relaxFields = schemaArgs.filter(
(a) =>
sortParsedKeys.has(a.schemaKey) ||
(a.foundIn === 'body' && (a.type === 'object' || a.type === 'array'))
)
// ...
props[f.schemaKey] = {} // ← accepts any value, including a malformed-JSON string
The relaxation exists to avoid false positives for complex Elasticsearch DSL bodies (e.g. query, _source), but it also suppresses the type error introduced by Bug 1.
Proposed fix
Fix Bug 1: When JSON.parse throws for an object-typed flag, emit an input_validation_failed error immediately instead of falling back to the raw string. The silent fallback was added for a use case that no longer exists.
Fix Bug 2 (optional / complementary): The schema relaxation for body object fields is a blunt instrument. A narrower approach would be to only relax fields that come from user-provided structured DSL (e.g. query, aggs), not scalar-like fields such as document. In the short term, fixing Bug 1 is sufficient to surface the error before validation is reached.
Expected behaviour
elastic stack es index --index test-idx --document '{"name":"Alice"invalid}' --dry-run
# Error: --document: invalid JSON: ...
# exit 1
Actual behaviour
Command exits 0 and prints the dry-run payload as if the input were valid.
authored by Pi Coding Agent (Claude Sonnet 4.5)
- Lenguaje dominante
- TypeScript
- Estrellas
- 49
- Forks
- 27
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 73
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de elastic/cli
-
feat: ship skills/elastic/SKILL.md for agent invocationPosiblemente ocupada @onatozmenn la tomó hace 16 días. Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
elastic/cli#628 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
elastic/cli#617 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Upgrade @elastic/schemas to latestPosiblemente ocupada @JoshMock la tomó hoy. Abiertoauto-pr
elastic/cli#767 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Auto-detection of Elasticsearch and Kibana version being usedPosiblemente ocupada @JoshMock la tomó hoy. Abierto
elastic/cli#766 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 58/100
Los mantenedores suelen responder en 1 día
Todos los issues de elastic/cli
Issues similares
-
Add: VIVE TVAbiertoapproved check:passed streams:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
iptv-org/iptv#55293 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Fission-AI/OpenSpec#2084 ·
Los mantenedores suelen responder en 2 días
-
Contrib indemnité de départ à la retraite : faire le pont avec le simulateur sur la page génériqueAbiertoP1
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
SocialGouv/code-du-travail-numerique#7561 ·
Los mantenedores suelen responder en 1 día
-
beginner bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
hiero-ledger/hiero-sdk-js#4517 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
kubernetes-sigs/headlamp#7950 ·
Los mantenedores suelen responder en 3 días