Index debug sensitivity paths once per capture
This commit is contained in:
@@ -424,6 +424,11 @@ a public index-build-count contract or a timing-based release gate.
|
|||||||
|
|
||||||
## Finding 8: Index Debug Sensitivity Paths Once
|
## Finding 8: Index Debug Sensitivity Paths Once
|
||||||
|
|
||||||
|
**Status: Complete.** A single historical-path traversal groups marked suffixes
|
||||||
|
by exact native resource prefix before resource association. Capture regressions
|
||||||
|
and race checks pass, including mixed root/collection resources, escaped keys,
|
||||||
|
nested arrays, and native snapshot ownership.
|
||||||
|
|
||||||
Priority: P3. Relevant stages: 30–31 and 33.
|
Priority: P3. Relevant stages: 30–31 and 33.
|
||||||
|
|
||||||
### Evidence And Complexity
|
### Evidence And Complexity
|
||||||
|
|||||||
@@ -61,18 +61,30 @@ func newRunEvidenceRecorder(recorder *frameworkdebug.Recorder, result *configkit
|
|||||||
return writer
|
return writer
|
||||||
}
|
}
|
||||||
sensitive := config.Definition("").Sensitive
|
sensitive := config.Definition("").Sensitive
|
||||||
paths := result.Metadata().HistoricalPaths()
|
masksByPrefix := map[string][][]string{}
|
||||||
register := func(masks map[string][][]string, id string, prefix configkit.Path) {
|
for _, field := range result.Metadata().HistoricalPaths() {
|
||||||
for _, field := range paths {
|
segments := strings.Split(strings.TrimPrefix(field.String(), "/"), "/")
|
||||||
if !strings.HasPrefix(field.String(), prefix.String()+"/") || !sensitive(field) {
|
extraParams := -1
|
||||||
|
// Match native root/collection resource paths before unescaping keys.
|
||||||
|
if len(segments) >= 5 && segments[0] == "promptkit" &&
|
||||||
|
(segments[1] == "profiles" || segments[1] == "backends") && segments[3] == "extra_params" {
|
||||||
|
extraParams = 3
|
||||||
|
} else if len(segments) >= 7 && segments[0] == "promptkit" && segments[1] == "collections" &&
|
||||||
|
(segments[3] == "profiles" || segments[3] == "backends") && segments[5] == "extra_params" {
|
||||||
|
extraParams = 5
|
||||||
|
}
|
||||||
|
if extraParams < 0 || !sensitive(field) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
segments := strings.Split(strings.TrimPrefix(field.String(), prefix.String()+"/"), "/")
|
prefix := "/" + strings.Join(segments[:extraParams+1], "/")
|
||||||
for index, segment := range segments {
|
suffix := segments[extraParams+1:]
|
||||||
segments[index] = strings.ReplaceAll(strings.ReplaceAll(segment, "~1", "/"), "~0", "~")
|
for i, segment := range suffix {
|
||||||
|
suffix[i] = strings.ReplaceAll(strings.ReplaceAll(segment, "~1", "/"), "~0", "~")
|
||||||
}
|
}
|
||||||
masks[id] = append(masks[id], segments)
|
masksByPrefix[prefix] = append(masksByPrefix[prefix], suffix)
|
||||||
}
|
}
|
||||||
|
register := func(masks map[string][][]string, id string, prefix configkit.Path) {
|
||||||
|
masks[id] = append(masks[id], masksByPrefix[prefix.String()]...)
|
||||||
}
|
}
|
||||||
root := configkit.Keys("promptkit")
|
root := configkit.Keys("promptkit")
|
||||||
for index, profile := range result.Config.PromptKit.Profiles {
|
for index, profile := range result.Config.PromptKit.Profiles {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -15,6 +16,53 @@ import (
|
|||||||
"go.maximumdirect.net/promptkit"
|
"go.maximumdirect.net/promptkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestRunCaptureRoutesRootAndCollectionSensitivityMasks(t *testing.T) {
|
||||||
|
result, err := configkit.LoadLayered(configkit.Input{Source: configkit.Bytes("mixed resources", []byte(`version: 6
|
||||||
|
promptkit:
|
||||||
|
profiles:
|
||||||
|
- id: chosen
|
||||||
|
extra_params:
|
||||||
|
token: root-profile
|
||||||
|
nested/key:
|
||||||
|
a~b: [{authorization: root-nested, caption: ordinary-caption}]
|
||||||
|
backends:
|
||||||
|
- id: chosen
|
||||||
|
endpoint: https://example.invalid/v1
|
||||||
|
extra_params: {password: root-backend}
|
||||||
|
collections:
|
||||||
|
fixture:
|
||||||
|
profiles:
|
||||||
|
- id: chosen
|
||||||
|
extra_params: {token: collection-profile}
|
||||||
|
backends:
|
||||||
|
- id: chosen
|
||||||
|
endpoint: https://example.invalid/v1
|
||||||
|
extra_params: {password: collection-backend}
|
||||||
|
`))}, configkit.LayeredOptions[config.Document]{Definition: config.Definition(t.TempDir())})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
writer := newRunEvidenceRecorder(nil, result).(*runEvidenceRecorder)
|
||||||
|
nested := map[string]any{"a~b": []any{map[string]any{"authorization": "root-nested", "caption": "ordinary-caption"}}}
|
||||||
|
for _, namespace := range []string{"", "fixture/"} {
|
||||||
|
target := promptkit.ExecutionTarget{ExtraParams: map[string]any{"token": "original-token", "password": "original-password", "nested/key": nested, "caption": "ordinary-caption"}}
|
||||||
|
masked := writer.target(target, namespace+"chosen", namespace+"chosen")
|
||||||
|
if masked.ExtraParams["token"] != "[REDACTED]" || masked.ExtraParams["password"] != "[REDACTED]" || masked.ExtraParams["caption"] != "ordinary-caption" {
|
||||||
|
t.Fatalf("misrouted resource masks for %q: %#v", namespace, masked)
|
||||||
|
}
|
||||||
|
wantNested := nested
|
||||||
|
if namespace == "" {
|
||||||
|
wantNested = map[string]any{"a~b": []any{map[string]any{"authorization": "[REDACTED]", "caption": "ordinary-caption"}}}
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(masked.ExtraParams["nested/key"], wantNested) {
|
||||||
|
t.Fatalf("nested mask crossed resource boundary for %q: %#v", namespace, masked)
|
||||||
|
}
|
||||||
|
if target.ExtraParams["token"] != "original-token" || nested["a~b"].([]any)[0].(map[string]any)["authorization"] != "root-nested" {
|
||||||
|
t.Fatal("native snapshot was mutated")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRunCaptureUsesFrozenSecretAwareConfiguration(t *testing.T) {
|
func TestRunCaptureUsesFrozenSecretAwareConfiguration(t *testing.T) {
|
||||||
result, err := configkit.LoadLayered(configkit.Input{Source: configkit.Bytes("captured application", []byte(`version: 6
|
result, err := configkit.LoadLayered(configkit.Input{Source: configkit.Bytes("captured application", []byte(`version: 6
|
||||||
promptkit:
|
promptkit:
|
||||||
|
|||||||
Reference in New Issue
Block a user