Remembered-secret search costs O(values x text) on every redaction call

未關閉
#182 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
go

研究方向

Read internal/redact/redact.go around rememberedMatches and its caller, then trace the Remember calls in internal/seed/common.go and the infrastructure seed files. Compare candidate matching approaches and inspect how per-file and per-run limits could be reported. Done means one text pass without copying the global set, both caps with a run note, and a benchmark demonstrating improvement with 10,000 values.

由索引模型根據 Issue 內容生成。

描述

help wanted performance severity: medium

Summary

Every redaction call copies all remembered token-like values into a new map and runs one substring search over the whole text per value. The number of values is set by the scanned tree, so a tree with many secret-named values in infrastructure files makes every tool call slow.

Where

  • internal/redact/redact.go:532-547 (rememberedMatches)
  • internal/redact/redact.go:348 (called from every redaction-mode scan)
  • internal/redact/redact.go:391 (maxRemembered = 1 << 20)
  • internal/seed/common.go:82, internal/seed/k8s.go:217, internal/seed/terraform.go:137, internal/seed/docker.go:154 (Remember callers)

Details

One call costs O(V) allocations plus O(V x len(text)) scanning, where V is the number of remembered values. The infrastructure checks call redact.Remember for every secret-named value in every Dockerfile, Kubernetes YAML and Terraform file, with no per-file or per-run cap below the global bound. A value of 12 or more token characters with a letter and a digit is global, so it is searched for in all text. This runs for every file the tools read or search for the first time, twice per tool result, once per new model message and once per lead.

Impact

Unmeasured; estimates from the code. With a few hundred values the cost is negligible. With about 10,000 token-like values (a monorepo with many generated manifests or variable files, or fixtures full of dummy credentials) each call makes 10,000 passes over its text: seconds per 1 MB file, so the first whole-target search of a run takes minutes. Near the bound, a scan effectively stops making progress, and tool calls are outside the model-call deadline.

Suggested fix

Match all remembered values in one pass: build an Aho-Corasick automaton (or a first-bytes index plus map lookup, since token-like values use a fixed character set) for the global set, rebuild it only when the set changes (a generation counter), and reuse it across calls. Iterate the global set under the read lock without copying it per call. Independently, cap token-like global values per file and per run well below the current bound and note in the run when the cap was hit.

Acceptance criteria

  • One pass over the text per call, whatever the number of values
  • No per-call copy of the global set
  • A per-file and per-run cap with a run note when it is hit
  • A benchmark with 10,000 values shows the improvement

Getting started

  • Relevant files: internal/redact/redact.go, internal/seed/common.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: M. audit-key: performance|internal/redact/redact.go|rememberedMatches

主要語言
Go
星號
0
分支
1
平均合併
8 小時 14 分鐘
30 天內合併 PR
3

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TMHSDigital/Spackle 的其他 Issue

查看 TMHSDigital/Spackle 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。