A caller-supplied ASIN reaches log lines unsanitized

Abierto Apto para principiantes
#971 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
77/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp

Línea de trabajo

Empieza con listenarr.application/Metadata/Core/AudiobookMetadataService.cs y MetadataConverters.cs; luego usa como lista de verificación la lista del diff de la rama con 106 argumentos de registro de ASIN sin procesar en 26 archivos. Ejecuta primero tests/Features/Application/Security/Redaction/AsinLogForgingTests.cs; sanea cada ASIN registrado con LogRedaction.SanitizeText y confirma que las pruebas y la suite de backend se ejecuten correctamente.

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

Descripción

p3

Raised by the batch-B review of PR 768.

What happens

An ASIN is a route parameter on GET /metadata/{asin} and GET /metadata/audible/{asin}, a request
field on advanced search, and a body field on the add call. It is caller-supplied text, and nothing
constrains it to the shape of an ASIN before it is logged.
LogRedaction.SanitizeText exists for this and is used in 380 places. It is not used consistently
for ASINs. The clearest example is inside one method:

// listenarr.application/Metadata/Core/AudiobookMetadataService.cs:58-64, at a630572e
_logger.LogInformation("Found {Count} enabled metadata sources for ASIN {Asin}: {Sources}",
    metadataSources?.Count ?? 0, LogRedaction.SanitizeText(asin), ...);
if (metadataSources == null || !metadataSources.Any())
{
    _logger.LogWarning("No enabled metadata sources found for ASIN {Asin}", asin);

Line 59 sanitizes the value and line 64 does not, with nothing between them to explain the
difference. MetadataConverters.cs logs an ASIN raw in 22 places.
I counted the whole set rather than guessing at it: 106 log arguments across 26 files pass an
ASIN-shaped value straight to the logger. The list is in the branch diff.

Why it matters

A value carrying a newline forges an extra line in any plain-text sink:

B01E633FQM
2026-01-01 00:00:00 INFO Authentication disabled by administrator

A reader of that log, or anything parsing it, cannot tell the forged line from a real one. The
advanced-search request body is the straightforward way in, since a JSON string field takes an
escaped newline without argument. A percent-encoded newline in the {asin} path segment would do
it too, if the host does not reject the request first; I have not tested which way that goes and
the body path does not depend on it. The length bound matters separately: an unbounded request
field is an unbounded log line.
This is not a data-sensitivity question. An ASIN is a public catalogue identifier and the repository
logs it freely elsewhere, which is fine. The problem is that user-controlled text reaches a log
without being flattened first.

Suggested fix

Pass every logged ASIN through LogRedaction.SanitizeText, the same function the neighbouring lines
already use. It replaces newlines, carriage returns and tabs with spaces, trims, and truncates at
200 characters.
One transform, repeated: 106 arguments, 26 files, no logic change. The only visible difference is
that a null or blank ASIN now prints as [empty] rather than as nothing, which is what every other
SanitizeText call site in the repository already does.
I am happy to split this by area if one change across 26 files is harder to review than several.

Tests

tests/Features/Application/Security/Redaction/AsinLogForgingTests.cs, four cases against a
capturing logger:

  • SanitizeText flattens a forged log line and keeps the ASIN that preceded it
  • the metadata converter emits no log message containing a newline or carriage return when handed a
    forged ASIN
  • the converter still reports a well-formed ASIN, which is the control: without it, a version that
    simply stopped logging the value would pass the case above
  • the metadata lookup emits no forged line either, exercising the route-parameter path end to end
    With the sweep reverted and the tests kept, two of the four fail on the newline assertion. Full
    backend suite on the branch: 3122 passing, 0 failing, 130 skipped. dotnet format --verify-no-changes clean.

Relationship to #768

#768 edits AudiobookMetadataService.cs and MetadataConverters.cs, which is where this first
became visible, but the two are unrelated and this is deliberately not folded into it. #768 is a
series-identifier fix and grew once already.
Disclosure: drafted with Claude Code at my direction; I read the cited code at the stated commit and reviewed this before posting.

Lenguaje dominante
C#
Estrellas
901
Forks
70
Merge medio
16 h 27 min
PR fusionados (30 d)
60

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 Listenarrs/Listenarr

Todos los issues de Listenarrs/Listenarr

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.