Fix on a CRLF file holding a multi-line secret is always rejected

Aperta
#174 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend, security

Direzione di ricerca

Read internal/agent/fixer.go around loadOriginals, restoreSecrets, and hideKnownSecrets, then compare its input handling with the model view in internal/agent/tools/tools.go and internal/walk/walk.go. Update internal/agent/fixer_test.go to build that view in production order and cover CRLF multi-line secrets and a UTF-8 BOM. Done means the marker is accepted, secret bytes and CRLF endings are preserved, and the BOM remains.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug severity: medium

Summary

Every fix that touches a CRLF file containing a multi-line secret (for example a PEM block) is rejected, because the redaction marker the model saw was hashed over the LF form and the fixer looks it up over the CRLF form.

Where

  • internal/agent/fixer.go:108 (loadOriginals reads the raw bytes)
  • internal/agent/fixer.go:142-158 (restoreSecrets)
  • internal/agent/tools/tools.go:365-378 (model view: walk.ReadText then redact.KeepLinesIn)
  • internal/walk/walk.go:387 (ReadText strips the BOM and turns CRLF into LF)
  • internal/agent/fixer_test.go:486 (test builds the view in the opposite order)

Details

The model reads a file through Registry.text: walk.ReadText (strips a UTF-8 BOM, turns every CRLF into LF) and only then redact.KeepLinesIn. The marker for a secret that spans lines therefore carries the hash of the LF form of the value. loadOriginals reads the same file raw and restoreSecrets computes redact.MatchesIn(file, orig) on the CRLF bytes. The value there holds \r\n, so its hash is different, the marker in the model's content never matches, and the check fires: "it holds a redaction marker that stands for no secret in the file". The code clearly means to support this case (the eol handling), and TestRestoreSecretsKeepsAMultiLineKeyInACRLFFile passes only because it redacts the CRLF text first and converts line endings second, the reverse of production.

Same root cause, smaller symptom: ReadText strips the BOM and loadOriginals puts back line endings only, so a fix to a file that starts with a BOM silently removes the BOM and the patch shows line 1 as changed.

Impact

On a checkout with CRLF line endings (the default on Windows with core.autocrlf=true), every fix and every debug fix that touches a file holding a multi-line secret is rejected on every attempt when the model keeps the marker, as the fixer prompt tells it to. The run spends all max_attempts model conversations and reports that no patch passed verification.

Steps to reproduce

  1. Create app.py with CRLF endings holding a triple-quoted PEM private key block and one more line of code.
  2. Take the model view as production does: redact.KeepLinesIn("app.py", walk.ReadText(abs)), and change the other line.
  3. Pass the result to loadOriginals(root, {"app.py": content}): it returns the "redaction marker that stands for no secret" error.
  4. Repeat with LF endings: it succeeds.

Suggested fix

In restoreSecrets (and hideKnownSecrets), compute the matches on the view the model had: normalize orig the way walk.ReadText does, take markers and values from that text, and map each value back to its raw form (LF to the file's line ending) before substituting. Put the BOM back when the original had one. Change the test to build the view as production does (KeepLinesIn over the ReadText-normalized text).

Acceptance criteria

  • A fix to a CRLF file with a multi-line secret is accepted when the model keeps the marker
  • The written file keeps its CRLF endings and the secret bytes unchanged
  • A fix to a file with a UTF-8 BOM keeps the BOM
  • The test builds the model view in production order

Getting started

  • Relevant files: internal/agent/fixer.go, internal/agent/fixer_test.go, internal/agent/tools/tools.go, internal/walk/walk.go
  • How to run tests: make test-short (Unix) or .\make.ps1 test-short (Windows PowerShell); make lint before you call it done
  • Related docs: CONTRIBUTING.md, docs/ARCHITECTURE.md

Filed by repo-audit/full-audit at 50e92ec. Severity: medium. Effort: S. audit-key: bug|internal/agent/fixer.go|restoreSecrets

Lingua principale
Go
Stelle
0
Fork
1
Merge medio
8h 14m
PR unite (30g)
3

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TMHSDigital/Spackle

Tutte le issue di TMHSDigital/Spackle

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.