Skip to content

fix: quote no client values in gateway errors - #740

Merged
uniqueg merged 6 commits into
devfrom
fix/739-selection-errors
Nov 7, 2026
Merged

uniqueg merged 6 commits into
devfrom
fix/739-selection-errors

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

The plugin gateway's refusals of per-request pipelines and backends (400, problem types invalid-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 as exceptions.validation_reasons (#736): they name fields, settings and step positions (from 0), never the client's values.

  • parse_client_pipeline validates 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.
  • Invalid params of client steps name the step by position.
  • NaN, Infinity and -Infinity are not allowed, without the constant.
  • The reserved-tag refusal names the allowed tags instead of the client's key.
  • Errors in the gateway's configuration (at startup) keep their messages.

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 pytest with MongoDB 7.0: 4888 passed, 2 skipped; coverage report: 100%.
  • mkdocs build --strict: OK.
  • CI: all checks passed (CI passed, tests on Python 3.11 to 3.15, CodeQL, Codecov, Read the Docs).
  • New parametrised test test_messages_quote_no_values and test_reserved_tag_message_quotes_no_key assert the exact messages and that the client's values don't appear.

Declined review findings

  • Keys of fields (e.g., unknown keys of params, or of a step) are named in the locations: they are field names, not values, as with exceptions.validation_reasons: false; documented in docs/plugins.md and the migration guide.
  • Sourcery: inputs of 1-3 characters may still appear in validator messages, through the length threshold of 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.
  • Messages of plugins' params validators pass through describe_validation_error, which already hides the input; messages of a plugin's own InvalidParams are passed on, and docs/plugins.md now asks plugins to name params and settings in them, not values.
  • A test for Step <n> has no enabled plugin with client origin: unreachable for client steps, because _check_client_steps refuses plugins that aren't loaded before resolve_steps runs.
  • Distinct pydantic error types for FOCA's value-free step checks (e.g., Steps have either 'plugin' or 'alternatives' now reads Invalid 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.
  • Mapping the parser's own 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.
  • Dropping the "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

uniqueg and others added 5 commits November 7, 2026 16:42
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]>
@sourcery-ai

sourcery-ai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Remove 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.

  • foca/plugins/config.py L186-188, L193-194, L203-209
  • foca/plugins/engine.py L824-831 (+8 small edits)
  • foca/plugins/selection.py L164-170, L344-351, L376-396 (+3 small edits)

Documentation

Explain the value-free gateway refusal messages and their compatibility impact in the plugin guidance, exception configuration, migration guide, and release notes.

  • docs/configuration/exceptions.md L194-199
  • docs/migration-0.22.md L279-310
  • docs/plugins.md L128-140
  • docs/releases/0.22.0.md L14

Tests

Update expected refusal messages and add exact-message checks that verify client values are absent from gateway errors.

  • tests/plugins/test_plugin_selection.py L263-267, L622-644, L777-841 (+6 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4919338) to head (4dc3d18).

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     
Flag Coverage Δ
test_unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 7, 2026 16:34

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread foca/plugins/engine.py Resolved
Comment thread foca/plugins/engine.py Resolved
Comment thread tests/plugins/test_plugin_selection.py Resolved
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]>
@uniqueg
uniqueg merged commit 1c155af into dev Nov 7, 2026
83 checks passed
@uniqueg
uniqueg deleted the fix/739-selection-errors branch November 7, 2026 16:56
@uniqueg uniqueg added this to the v0.22.0 milestone Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: don't quote values in gateway selection errors

1 participant