Sanitize wizard remarks and make remark parsing robust

Aperta
#812 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
typescript
Ambito
security, tooling

Direzione di ricerca

Inizia da src/lib/agent/output-signals.ts, inclusi AgentOutputSignals.remark() e il controllo dell’echo di REMARK_INSTRUCTION, quindi segui la chiamata analytics.capture per WIZARD_REMARK_EVENT_NAME. Esamina il flusso remark esistente e determina dove dovrebbero essere testati la consegna strutturata e il sanitization; il lavoro è completo quando sono coperti la consegna tipizzata di remark, gli echo e i valori vuoti rifiutati e i payload analytics sanitizzati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

The end-of-run "remark" is free-form model output that we extract from the agent's prose by string-matching a [WIZARD-REMARK] marker (AgentOutputSignals.remark() in src/lib/agent/output-signals.ts) and then ship straight to analytics:

const remark = signals.remark();
if (remark) analytics.capture(WIZARD_REMARK_EVENT_NAME, { remark });

Two problems with this:

1. It's not sanitized (security)

The remark is untrusted, model-generated text captured from output and sent to PostHog analytics with no sanitization. It can carry things we don't want to ingest verbatim: secrets/API keys the model echoed from the environment, file paths or PII, prompt-injection payloads, or control/escape characters. We should sanitize before capturing — strip control chars, redact secret-shaped tokens, cap length, and validate it looks like a single reflection line rather than arbitrary content.

2. Parsing it out of prose is flaky

Marker-scanning the agent's output stream is fragile. We've already hit failure modes:

  • The model echoes the ask itself instead of a real remark (fixed narrowly in #806 / the REMARK_INSTRUCTION echo check in remark()).
  • Only the first line after the marker is captured; multi-line or marker-mid-line output is dropped or truncated.
  • Any change to prose formatting can silently break extraction.

As noted in the thread: parsing wizard logs/output for remarks is inherently flaky and should be reworked.

Proposed direction

Move remarks off free-text prose parsing onto a structured channel — e.g. have the agent emit the remark via a dedicated tool call / structured output field instead of an inline marker, so it arrives as a typed value we don't have to regex out of the stream. Then run whatever we receive through a sanitization pass before analytics.capture.

Acceptance criteria

  • Remark content is sanitized (control chars stripped, secret-shaped tokens redacted, length-capped) before being captured to analytics.
  • Remark delivery no longer depends on regex-scanning prose — it comes through a structured/typed channel.
  • Echo-of-the-ask and empty/garbage remarks are reliably rejected.
  • Tests cover sanitization and the new extraction path.

Context: found while debugging the Windows skill-install issue; remarks broke (#806) and Vincent flagged the parsing approach as flaky and wanting a rework.

Lingua principale
TypeScript
Stelle
208
Fork
58
Merge medio
2g 7h
PR unite (30g)
76

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PostHog/wizard

Tutte le issue di PostHog/wizard

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.