Skip to content

Commit a97f298

Browse files
jopemachineclaude
andcommitted
fix(BA-5978): strip input/ctx from SchemaValidationFailureInfo.errors
Pydantic v2 ErrorDetails carry the raw invalid input value and validator-specific ctx. Capturing those verbatim leaks sensitive data (passwords, tokens, …) into HTTP 400 responses / log output and can include non-JSON-serializable objects. Per review (#3224372025), strip the input and ctx keys before storing in SchemaValidationFailureInfo.errors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d0b7675 commit a97f298

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/ai/backend/common/types.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,19 @@ def build_validation_error(cls, info: SchemaValidationFailureInfo) -> BackendAIE
226226

227227
@classmethod
228228
def _validation_failure_info(cls, exc: ValidationError) -> SchemaValidationFailureInfo:
229-
return SchemaValidationFailureInfo(summary=str(exc), errors=exc.errors())
229+
# Strip ``input`` and ``ctx`` per-error entry: those carry the raw
230+
# invalid value and validator-specific context, which can contain
231+
# sensitive data (passwords, tokens) and non-JSON-serializable
232+
# objects. ``str(exc)`` may still embed input values; callers that
233+
# log/return ``summary`` should treat it as opaque.
234+
sanitized = [
235+
cast(
236+
ErrorDetails,
237+
{k: v for k, v in err.items() if k not in ("input", "ctx")},
238+
)
239+
for err in exc.errors()
240+
]
241+
return SchemaValidationFailureInfo(summary=str(exc), errors=sanitized)
230242

231243
@classmethod
232244
def model_validate(cls, *args: Any, **kwargs: Any) -> Self:

0 commit comments

Comments
 (0)