Repository navigation
fix(artifacts): screen note content for prompt injection before generating - #735
Conversation
|
@coderabbitai full review |
|
No actionable comments were generated in the recent review. WalkthroughArtifact generation now screens sanitized note content before generation. The guard checks plain-text and raw-HTML views, classifies excerpts for detected hits, and returns a refusal for unsafe or unclassifiable content. The pipeline releases its reservation when screening refuses or throws. ChangesArtifact note screening
Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant GenerateArtifactHandler
participant AIGenerationPipeline
participant NoteContentGuard
participant InjectionClassifierService
GenerateArtifactHandler->>AIGenerationPipeline: Submit generation request with screening callback
AIGenerationPipeline->>NoteContentGuard: Screen sanitized note after reservation
NoteContentGuard->>InjectionClassifierService: Classify excerpts for heuristic hits
InjectionClassifierService-->>NoteContentGuard: Return classifier verdicts
NoteContentGuard-->>AIGenerationPipeline: Return safe verdict or screening error
AIGenerationPipeline->>AIGenerationPipeline: Release reservation on error or exception
Merge Risk:
|
Action not completed
|
|
@coderabbitai full review |
d05a320 to
afae996
Compare
Action performed
|
Closes #383.
Why
POST /artifacts/generatesends a note of up to 48,000 characters to the model, and nothing scans it for prompt injection. The note can be shared or co-edited, so it can carry a collaborator's text. The artifacts pipeline bypassesAICompletionPipeline, the only pipeline that calls the heuristic guard. A spec even locked in the unguarded behavior.Policy
The heuristic can't tell an attack from a note that discusses one: a security note quoting "ignore all previous instructions" scores 0.9, the same as a real attack. So every hit has to be cleared by the model classifier (
AI_GUARD_CLASSIFIER_MODEL), and the generation is refused when the classifier flags a hit or can't decide.What changed
NoteContentGuard(artifacts/application/services/note-content-guard.ts):detectAiInputandlocateInjectionSpansfrom llm-router over two views: the plain text, which joins a phrase that inline markup splits, and the raw HTML the model receives, which keeps attributes and elements such as<style>.AIGenerationPipeline:screencallback that runs after the budget check, so a caller over budget doesn't pay for classifier calls.PROMPT_INJECTION_DETECTEDreturns 422. Refusals logartifacts.generate.injection_blockedwithreason; cleared notes logartifacts.generate.injection_cleared.docs/AI.md. The pipeline order is corrected too: model selection comes before the rate-limit check.POST /artifacts/learnisn't screened: its 200-character topic is the caller's own input.Trade-offs
too_many_hits).Review
An independent review ran three rounds. Fixed along the way:
<style>or an attribute through unjudged;Verification
>, and in<style>;nx run-many -t test lint -p api,api:typecheckand Prettier: clean.Summary by CodeRabbit