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

Aberta
#174 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
78/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
go
Domínio
backend, security

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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

Linguagem predominante
Go
Estrelas
0
Forks
1
Merge médio
8h 14min
PRs com merge (30d)
3

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de TMHSDigital/Spackle

Todas as issues de TMHSDigital/Spackle

Issues semelhantes

Mais issues de Go

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.