From cf50650e5530c48ee7eea70d6e1bb0cffe37bcd2 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Thu, 19 Nov 2026 15:13:00 +0000 Subject: [PATCH] Record PromptKit algorithm audit findings --- docs/roadmap/remediation.md | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index e0b3c21..bbd1034 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -81,3 +81,46 @@ that same-ID conflicts within one discovery underlay fail. For an intentional override, select a separate, later framework source using the existing application selector list. No scanner, de-duplication, new namespace restriction, or change to composition is needed. + +## R5: Replay framework explanation history once (Stage 3) + +[Framework configuration inspection](../../internal/adapter/cli/framework_config.go) +calls `view.Explain(path)` to check existence, discards the complete +explanation, then calls `view.WriteExplanation`. The pinned native writer +calls `Explain` itself. A successful request therefore replays the same +captured history and builds the same redacted value snapshots twice. If +`H` is the work to construct that explanation and `W` the work to render +it, the command does roughly `2H + W` work instead of `H + W`. This is a +constant-factor cost, not a new quadratic algorithm, but it repeats a +history- and value-sized operation and its allocations. The legacy wrapper +already used two calls; the native inspection path need not retain them. + +Delegate once to `view.WriteExplanation`, as app configuration inspection +already does with its native writer. A direct probe with the selected +PromptKit and ConfigKit releases confirmed that this writes a known path, +returns an error without output for an unknown path, and preserves writer +errors. Keep JSON Pointer parsing, native redaction, and the existing exit +and stream behavior; no new formatter or replay algorithm is needed. + +## R6: Prevent artifact read-limit overflow (Stage 4) + +[The restricted HTTP artifact reader](../../internal/adapter/http/artifact_reader.go) +allows the same nonnegative `int64` limit as application configuration +and the CLI. It computes `maxBytes + 1` for `io.LimitReader` to detect +oversized files. At the valid setting `9223372036854775807` +(`math.MaxInt64`), that addition wraps to a negative number. The limited +reader then immediately returns EOF, so a nonempty file is accepted as an +empty artifact. A loopback check confirmed HTTP 200 at this setting while +the outgoing prompt silently lost the file content. The same synthetic +request included the file at zero and at the ordinary positive limit. +The defect predates the migration and remains in the reader retained +by Stage 4. + +Use overflow-safe byte-limit arithmetic: for example, retain the capped +`limit + 1` read for smaller positive limits and skip the increment at +`math.MaxInt64`, or limit the read first and probe separately for an extra +byte. Accepted files should still require linear time and buffer space in +the bytes read; normal limits should continue to reject oversized files +without a full read. Add a boundary test using a small nonempty file. +Do not reduce the accepted configuration range or change containment +or the zero-limit semantics.