Skip to content

Commit 018a577

Browse files
author
testikun
committed
fix(core): redact secrets from session references
1 parent e250e53 commit 018a577

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

apps/desktop/renderer-architecture.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,8 @@
979979
"@maka/ui/icons": 1,
980980
"react": 1
981981
},
982-
"importSpecifiers": 186,
983-
"nonTriviaTokens": 15722
982+
"importSpecifiers": 184,
983+
"nonTriviaTokens": 15689
984984
},
985985
"src/renderer/use-app-shell-composer-quotes.ts": {
986986
"importDeclarations": 1,

docs/astryx-surface-file-inventory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Generated against `@astryxdesign/core@0.5.2` (194 component exports).
66

77
Wiki bar: Design Conventions · API Use-the-System · Theming · Container Padding.
88

9-
**Totals:** 245 files — blocker 0, reimplementation 0, polish 1, aligned 244.
9+
**Totals:** 246 files — blocker 0, reimplementation 0, polish 1, aligned 245.
1010

1111
## Exclusions (explicit)
1212

packages/core/src/__tests__/session-reference.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ test('creates a recent, redacted snapshot and excludes non-conversation messages
7474
assert.equal(snapshot.reference.capturedAt, 123);
7575
});
7676

77+
test('redacts secrets from retained user and assistant messages before quoting them', () => {
78+
const snapshot = createSessionSnapshot(
79+
[
80+
user('user-secret', 'Use Authorization: Bearer sk-live-secret-token-value'),
81+
assistant('assistant-secret', 'The key is sk-ant-api03-live-secret-token-value'),
82+
],
83+
{
84+
sessionId: 'session-source',
85+
sessionName: 'Sensitive session',
86+
},
87+
);
88+
89+
assert.doesNotMatch(snapshot.text, /sk-live-secret-token-value/);
90+
assert.doesNotMatch(snapshot.text, /sk-ant-api03-live-secret-token-value/);
91+
assert.match(snapshot.text, /\[redacted\]/);
92+
assert.doesNotMatch(sessionSnapshotToQuote(snapshot).text, /sk-live-secret-token-value/);
93+
});
94+
7795
test('bounds a snapshot from the newest content and preserves truncation provenance', () => {
7896
const snapshot = createSessionSnapshot(
7997
[

packages/core/src/session-reference.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
import type { QuoteRef } from './events.js';
21+
import { redactSecrets } from './redaction.js';
2122
import type { StoredMessage } from './session.js';
2223
import { userFacingText } from './session.js';
2324

@@ -81,7 +82,7 @@ export function createSessionSnapshot(
8182
const candidates: SessionSnapshotItem[] = messages.flatMap((message) => {
8283
if (message.type !== 'user' && message.type !== 'assistant') return [];
8384
const text = message.type === 'user' ? userFacingText(message) : message.text;
84-
const normalized = text.trim();
85+
const normalized = redactSecrets(text).trim();
8586
if (!normalized) return [];
8687
return [
8788
{

0 commit comments

Comments
 (0)