← Back to Pull requests

[ISSUE #8261] Inspect decoded JSON text in the sensitive word plugin #8267

Closed
unknown closed this pull request without merging on Nov 02, 2026 15:37 UTC
View on GitHub
unknown unknown commented on Nov 01, 2026 02:31 UTC
Author

Fixes #8261

Problem

SensitiveWordPlugin scanned the raw request body. A JSON document can carry the same text with
escape sequences, so a message whose word is written with JSON Unicode escapes reached the model
while the same word spelled literally was rejected. The text a model reads is the decoded value,
not its wire form.

Impact

  • Literal and Unicode-escaped content now produce the same decision.

  • The original request is still forwarded byte for byte: nothing is re-serialized.

  • Plain-text scanning of non-JSON bodies is unchanged, and the raw scan is kept for every body, so

  • no currently rejected request becomes accepted.
  • The decoded scan is a streaming walk bounded by a nesting limit and by the existing maxBodySize

  • check, so it never retains a parsed JSON tree.

    Changes

  • JsonTextValues (new): a package-private streaming walker that decodes every JSON string member

  • and skips object member names and non-string values. It stops at the first match, leaves the body
    untouched, and stops at the first malformed token.
  • SensitiveWordPlugin: scans the raw body, and when no word is found there, scans the decoded

  • string values. The class Javadoc states the inspected fields and the malformed/non-JSON policy.
  • README.md: a JSON decoding section listing the covered fields and the limits.

  • SensitiveWordPluginTest: seven tests — the issue reproduction, an escape split across incoming

  • buffers, a multimodal text part, a tool definition, a Responses input, byte-preservation of the
    forwarded body, and a malformed document.

    Inspected fields

    A JSON body is scanned once as raw text and once through the decoded value of every string member:

  • openai-chat: messages[].content, both as a string and as the text members of multimodal

  • content parts, plus tool definitions and function arguments;
  • openai-responses: input, either a string or items whose text lives in content or text.
  • Object member names and non-string values are not decoded. A string value that itself holds JSON is
    decoded once, not recursively parsed. A body that is not a JSON object or array, and a malformed
    JSON document, keep the raw plain-text scan only, so they are never treated as decoded and clean.

    Validation

  • Affected module and its reactor dependencies:

  • ./mvnw -pl shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-sensitive-word -am test -Dtest='AhoCorasickTest,SensitiveWordPluginTest,SensitiveWordPluginDataHandlerTest' -Dsurefire.failIfNoSpecifiedTests=false -Drat.skip=true -Djacoco.skip=true
    → Tests run: 54, Failures: 0, Errors: 0 (27 in SensitiveWordPluginTest).
  • Regression proof: with only the SensitiveWordPlugin change reverted, the five escaped-content

  • tests fail (Tests run: 5, Failures: 5, Errors: 0); with the fix they pass.
  • Checkstyle: 0 violations. Apache RAT: 0 unapproved, 8 approved licenses.
  • Non-blocking note

    #8255 owns the reusable normalized request view. It is not available yet, so this walker is
    deliberately protocol-agnostic: it decodes string values instead of modeling a protocol schema,
    which also covers model-visible fields the profile-based PII plugin does not redact, such as tool
    definitions. When #8255 lands, the walker can be replaced without changing the plugin contract.

    Checklist

  • I have read the contribution guidelines.

  • I submit test cases that back this change.

  • The affected module and its reactor dependencies passed locally.
  • Diff: 443 lines (+332 / -111) across 5 files Reviewer: yuluo-yx Review duration: 2226m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 443 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.365
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8267"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.3% (MEDIUM) · Higher = larger blast radius
    45.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.6% · Safe to merge
    19.6%
    Repository