fix(graders): insert untrusted code verbatim in judge prompt#97
Conversation
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe change modifies llmJudge's prompt construction to use String.replace function replacers instead of direct string substitution when inserting untrusted question/code into the template, preventing special ChangesLLM Judge Prompt Safety
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
String.prototype.replace with a string pattern interprets $&, $`, $',
and $1 in the replacement specially. Since the judged code is untrusted
agent output, those sequences silently corrupted the judge prompt (e.g.
$& expanded to the matched {code} placeholder). Use function replacers so
question/code are inserted verbatim.
eddd654 to
c34a751
Compare
Summary
The LLM judge built its user prompt with
String.prototype.replace('{code}', code)using a string replacement. String replacements interpret$&,$`,$', and$1..$nas special substitution patterns. Sincecodeis untrusted agent output, any such sequence in the generated code would silently corrupt the judge prompt (e.g.$&expands to the matched{code}placeholder rather than being inserted literally).This switches both
{question}and{code}interpolations to function replacers (() => value), which insert the value verbatim with no pattern interpretation.Changes
packages/eval-core/src/graders/llm-judge.ts— use function replacers soquestion/codeare inserted verbatim.packages/eval-core/tests/graders/engine.test.ts— regression test asserting code containing$&,$1,$`, and$'reaches the judge prompt unmodified.Test plan
npm test(eval-core grader tests, including the new regression test)Summary by CodeRabbit
Bug Fixes
$-style sequences from being altered when generating judge prompts.Tests