Repository navigation
fix: quote no client values in gateway errors - #740
Conversation
Refusals of per-request pipelines and backends name fields, settings and the positions of steps, never the client's values: validation errors of steps by location and type, rejected JSON constants, unavailable presets and plugins and duplicate step identifiers with fixed messages, and invalid params of client steps by the step's position. Errors of the admin's configuration keep their messages. Update the plugins page, the exceptions configuration, the migration guide and the release notes. Closes #739 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Name the repeating step by position via `check_pipeline(by_position=True)` instead of a second implementation. Name keys in the docs, add a heading for the gateway messages in the migration guide, and check a secret params value in the test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reserved-tag refusal quoted the client's tag key; it now names the allowed tags instead, as the other gateway messages do (#739). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideAPIRemove client-provided values from plugin-gateway refusal messages while preserving actionable field and step-position context, including for invalid pipelines, unavailable choices, duplicate identifiers, invalid params, JSON constants, and reserved tags.
DocumentationExplain the value-free gateway refusal messages and their compatibility impact in the plugin guidance, exception configuration, migration guide, and release notes.
TestsUpdate expected refusal messages and add exact-message checks that verify client values are absent from gateway errors.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #740 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 74 74
Lines 9377 9385 +8
=========================================
+ Hits 9377 9385 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="foca/plugins/engine.py" line_range="837" />
<code_context>
invalid = (
- f"Invalid params of plugin {alternative.plugin!r} in step"
- f" {step.id!r}"
+ f"Invalid params of plugin {alternative.plugin!r} in step {label}"
)
try:
</code_context>
<issue_to_address>
**Plugin errors expose rejected values**
When a selected plugin's `check_params` raises `InvalidParams` with a client-supplied value in its message, a client-selectable plugin can include a submitted parameter value in its `InvalidParams` message; `resolve_steps` appends that message to the error and the caller receives it in the refusal response.
Sanitize or replace `InvalidParams` messages for client-originated steps, or otherwise enforce a value-free error contract before returning them.
</issue_to_address>
### Comment 2
<location path="foca/plugins/engine.py" line_range="837" />
<code_context>
invalid = (
- f"Invalid params of plugin {alternative.plugin!r} in step"
- f" {step.id!r}"
+ f"Invalid params of plugin {alternative.plugin!r} in step {label}"
)
try:
</code_context>
<issue_to_address>
**Short parameter values remain exposed**
When a plugin's parameter validator includes a rejected client string shorter than four characters in its error message, `describe_validation_error` preserves a validator message when the rejected string is shorter than four characters, even if that message includes the string; the resulting 400 response therefore still quotes a client value.
Ensure validator messages cannot expose rejected input regardless of its length, for example by returning a fixed error for custom messages that contain the input.
</issue_to_address>
### Comment 3
<location path="tests/plugins/test_plugin_selection.py" line_range="621" />
<code_context>
("value", "message"),
[
- ('[{"plugin": "a.b", "params": {"x": NaN}}]', "NaN is not allowed"),
+ ('[{"plugin": "a.b", "params": {"x": NaN}}]', "NaN, Infinity and"),
('[{"plugin": "a.b", "params": {"x": -Infinity}}]', "-Infinity"),
('[{"plugin": "a.b", "params": {"x": 1e999}}]', "finite"),
</code_context>
<issue_to_address>
**Leaked values pass refusal tests**
When a refusal message includes the submitted value, `pytest.raises(..., match=message)` in `test_client_pipelines_are_i_json` and `test_invalid_selections` accepts the expected text even when the response also includes `-Infinity` or `test.tag`, so tests pass while the caller's value is exposed.
Assert the complete expected refusal messages or explicitly assert that the submitted values are absent in both tests.
Also at `tests/plugins/test_plugin_selection.py:189`, `tests/plugins/test_plugin_selection.py:195`, `tests/plugins/test_plugin_selection.py:201`.
</issue_to_address>Linked issues
#739 fix: don't quote values in gateway selection errors · 5 of 6 met · 1 to check by hand
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Name client fields, settings and step positions rather than rejected values in pipeline and backend refusals. | ✅ Met | Pipeline validation reports locations and error types; backend parse failures use a fixed message rather than exposing submitted values. |
| 2 | Use fixed messages for rejected JSON constants, unavailable presets and plugins, and duplicate step identifiers; identify client steps by position. | ✅ Met | The client paths use value-free messages, and unavailable plugins and duplicate identifiers name the step position. |
| 3 | Keep messages that name settings or keys, and plugin parameter errors that name the parameter without its value. | ✅ Met | Limits and allowed tags remain named; client parameter errors identify the step by position, and the plugin documentation addresses plugin-owned parameter messages. |
| 4 | Keep the gateway's configuration errors at startup unchanged. | ✅ Met | The position-based messages are selected for client-origin steps; configuration checks retain their default identifier-based messages. |
| 5 | Test-first. | 👀 Check by hand (manual process) | Confirm from the development history that the tests were written before the implementation. |
| 6 | Update the plugins and exceptions documentation, the 0.22 migration guide, and the 0.22.0 release notes. | ✅ Met | All four requested documentation locations are updated. |
Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: foca/plugins/engine.py:837, foca/plugins/engine.py:837, tests/plugins/test_plugin_selection.py:621
Partial matches would pass if a message also quoted the client's value (Sourcery review of #740). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The plugin gateway's refusals of per-request pipelines and backends (
400, problem typesinvalid-pipeline,invalid-backends,reserved-tag) quoted the client's values (preset and plugin names, step identifiers, invalid identifiers, JSON constants, reserved tag keys). They now follow the same rule asexceptions.validation_reasons(#736): they name fields, settings and step positions (from 0), never the client's values.parse_client_pipelinevalidates the steps one by one and reports the location and error type of the first error, e.g.,Invalid pipeline: 0.alternatives.0.plugin (value_error).Preset not available,Plugin not available in step 1,Step identifiers must be unique: step 1 repeats one; set unique 'id's.NaN, Infinity and -Infinity are not allowed, without the constant.Docs:
docs/plugins.md,docs/configuration/exceptions.md, the migration guide (new section "Plugin gateway messages") and the 0.22.0 release notes (Security).Closes #739
Verification
ruff format,ruff check,mypy foca: clean.coverage run -m pytestwith MongoDB 7.0: 4888 passed, 2 skipped;coverage report: 100%.mkdocs build --strict: OK.CI passed, tests on Python 3.11 to 3.15, CodeQL, Codecov, Read the Docs).test_messages_quote_no_valuesandtest_reserved_tag_message_quotes_no_keyassert the exact messages and that the client's values don't appear.Declined review findings
exceptions.validation_reasons: false; documented indocs/plugins.mdand the migration guide.describe_validation_error; it predates this PR, applies to all settings errors and is out of scope for fix: don't quote values in gateway selection errors #739.describe_validation_error, which already hides the input; messages of a plugin's ownInvalidParamsare passed on, anddocs/plugins.mdnow asks plugins to name params and settings in them, not values.Step <n> has no enabled pluginwith client origin: unreachable for client steps, because_check_client_stepsrefuses plugins that aren't loaded beforeresolve_stepsruns.Steps have either 'plugin' or 'alternatives'now readsInvalid pipeline: 0 (value_error)): accepted as the cost of the rule and documented in the migration guide; distinct types could follow if clients need them.ValueErrors (e.g., on integers with too many digits) to the generic message: older than this branch and value-free; the docstring now says so."secret" not in ...assertion next to the exact message check: kept as an explicit guard of the rule if the expected messages change.Open questions
None.
🤖 Generated with Claude Code