Feature/pin and redaction preview#163
Open
DevSars24 wants to merge 2 commits into
Open
Conversation
Storage (Option B): separate ConcurrentDictionary for pinned entries,
protected from FIFO eviction. MaxPinnedEntries=5 constant cap.
TryPin() toggles; Clear() flushes all (full session reset).
POST /debug/pin/{id} endpoint returns 409 when cap exceeded.
Dashboard: Pinned Traces section, pin/unpin buttons per row.
CSS, JS, HTML template updates. 13 new tests.
- DebugProbeOptions: AllowRedactionPreview (default false) - DebugProbeOptionsValidator: fail fast if AllowRedactionPreview=true && AllowUiInProduction=true - DebugEntry: OriginalRequestHeaders, OriginalRequestBody, OriginalResponseBody, OriginalQuery - DebugProbeMiddleware: capture pre-redaction raw values into OriginalXxx when AllowRedactionPreview=true - HtmlRenderer: server-side two-gate check (AllowRedactionPreview=true AND Development env); render collapsible preview banner with original values - CSS: redaction-preview-toggle, redaction-original-value styles - Tests: 7 new tests (options validation, middleware capture, renderer two-gate check)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two independent Phase 2 features, shipped as two separate commits so either can be reviewed or reverted on its own:
Both stay within the existing in-memory
DebugEntryStore— no new database, no external storage, no persistence added.Feature 1: Pin/Favorite a Trace
Lets you pin an important trace from the dashboard so it survives eviction once the store fills up and starts trimming old entries.
IsPinnedonDebugEntryPOST /debug/pin/{id}toggles pin state409 Conflictinstead of silently bumping another oneClear()resets pinned entries too, so there's no leftover state after a full resetFeature 2: Redaction Preview Toggle
Lets a developer temporarily view the original value of a redacted header/field (e.g. an API key) on the trace detail page. Local debugging only — not intended for production.
New config option:
AllowRedactionPreview(defaultfalse)When
true, the middleware stores both the redacted and original valuesWhen
false(default), the original value is never stored anywhere — not even in memoryThe banner and original values only render when both are true:
AllowRedactionPreview = trueThis is enforced server-side before the HTML is generated — not hidden with CSS. The original value is never sent to the browser unless both conditions hold.
Setting
AllowRedactionPreview = truetogether withAllowUiInProduction = truethrows at startup, to prevent this from accidentally shipping open in production.RedactionUtils.cs— the actual redaction logic — is untouched. This feature is purely an additional layer on top of it.On the sample app config:
DebugProbe.SampleApi/Program.csships withAllowRedactionPreview = false, matching the library default. This doesn't mean the feature only works in this one file — any consumer of the library can set it totruein their ownProgram.csand it behaves exactly as shown below. Keeping the sample off by default just avoids anyone copy-pasting a security-preview feature into production already turned on.The screenshot below was captured with the option set to
truelocally, purely to demonstrate the feature end-to-end.Testing
All 119 tests pass.
Pin feature — 13 new tests: toggle on/off, 5-entry cap enforcement (409), pinned entries surviving eviction,
Clear()behavior, dashboard section rendering.Redaction preview — 11 new tests: startup validation on misconfiguration, values not persisted when disabled, values persisted correctly when enabled, banner rendering gated on both config and environment.
Manually verified end-to-end via curl and browser:
AllowRedactionPreview=false, the secret never appears — not in the JSON response, not in the page sourceAllowRedactionPreview=true+ Development environment, banner and original value render correctly (see screenshot above)Files changed
Models/DebugEntry.cs— AddedIsPinnedand original-value fieldsStorage/DebugEntryStore.cs— Pin storage, eviction logic, cap enforcementOptions/DebugProbeOptions.cs— AddedAllowRedactionPreviewOptions/DebugProbeOptionsValidator.cs— Blocks unsafe config combination at startupMiddleware/DebugProbeMiddleware.cs— Captures original values when preview is enabledExtensions/DebugProbeExtensions.cs— New pin endpointInternal/Rendering/HtmlRenderer.cs— Pinned section + redaction preview bannerDebugProbe.SampleApi/Program.cs— AddedX-Api-Keyto redacted headers,AllowRedactionPreviewset tofalseDebugProbe.AspNetCore.Tests/— 24 new tests across both features