← Back to Pull requests

Prevent SQL injection in message metadata column search #361

Closed
unknown closed this pull request without merging on Sep 10, 2026 20:31 UTC
View on GitHub
unknown unknown commented on Jul 23, 2026 21:48 UTC
Author

Problem

Custom metadata column names in message search are interpolated into SQL as identifiers (MyBatis ${}) across all database dialects — ${element.columnName} (metaDataSearch) and ${column} (textSearchMetaDataColumns) — and arrive from the REST parameters with no validation, so an authenticated MESSAGES_VIEW user can inject arbitrary SQL. The search value (#{...}) and operator (enum-constrained) were already safe; only the column name is affected. Ref GHSA-mf46-33w3-84j6.

Fix

Validate every referenced metadata column name against the channel's own defined columns before the filter reaches the data layer:

  • MetaDataColumnValidator (new, server/util): pure check, lazy channel-column lookup, returns the first unknown column name (or null).

  • MessageServlet: primary gate at the REST boundary; an unknown column returns 400. Applied to all message-search entry points, in both the parameter and MessageFilter-body forms (getMessages, getMessageCount, reprocessMessages, removeMessages, exportMessagesServer).

  • DonkeyMessageController: defense-in-depth backstop for callers that reach the controller directly (e.g. plugins via MessageController.getInstance()), throwing on an unknown column.
  • Column names are matched exactly against the channel's (upper-cased) defined columns. No SQL/mapper changes; the value and operator are untouched.

    Tests

  • MetaDataColumnValidatorTest — unit tests the check: unknown/known/non-uppercase/null column, and that the channel lookup is skipped when the filter references no custom column.

  • MessageServletTest — REST-boundary reject/allow paths.

  • Full clean :server build green (unit tests included).
  • Verifying

    Verified against a running server (Derby) with a channel that has a custom metadata column:

  • metaDataSearch=<definedColumn> = foo → 200 (search runs normally).

  • metaDataSearch=<undefinedColumn> = foo → 400 (rejected before reaching SQL).
  • Diff: 247 lines (+185 / -62) across 3 files Reviewer: gibson9583 Review duration: 70482m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 247 lines diff across 3 files
    0.39
    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%
    60%
    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.330
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #361"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 38.9% (MEDIUM) · Higher = larger blast radius
    38.9%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.4% · Safe to merge
    15.4%