Skip to content

feat!: tighten group checks and error details - #475

Merged
uniqueg merged 7 commits into
devfrom
feat/tighten-config-checks
Oct 24, 2026
Merged

uniqueg merged 7 commits into
devfrom
feat/tighten-config-checks

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Maintainer decisions of 2026-10-24 for the unreleased 0.18.0 (follow-ups of #459/PR #466 and #461/PR #464):

  • Group settings that cannot apply are errors. With access control enabled, Foca.create_app() refuses to start (ValueError, raised in _check_group_config(), like the require_admin check of feat: add startup checks of the config #466) if group_mapping maps groups but claim_groups is not set, or if claim_groups has surrounding whitespace. An empty group_mapping without claim_groups is still allowed, with a warning (rephrased, since nothing is mapped). group_mapping without keep_group_subjects stays a warning. _check_admin_role() no longer needs the "(not applied …)" branch, as those cases fail earlier; a test pins the order of the two checks.
  • exceptions.validation_details defaults to true: clients get the validator's reason as detail, and Connexion's unescaped request-validation messages are filtered out by default. Template, model docstring, docs, unit tests, example comments and the integration test (POST /pets with {} now gets 'name' is a required property, checked locally against the petstore spec) are updated. The test fixture for Connexion's validation logger now removes FOCA's process-wide filter for each test, since apps of other tests add it by default now.
  • docs/migration-0.18.md: two new breaking-change sections, covering the app's own BadRequestProblem exceptions too; the startup-check docs (configuration/access-control.md, deployment.md) and configuration/exceptions.md describe the new behaviour.

Verification

  • pytest with MongoDB 7 (coverage): 2326 passed, 1 skipped; coverage report: 100%
  • mypy: no issues (88 files); ruff check / ruff format --check: clean
  • pre-commit run --all-files: all hooks passed (incl. semgrep, ast-grep)
  • mkdocs build --strict: no warnings
  • Integration tests (tests/integration_tests.py) need the dockerised petstore: they run in CI only; the changed expectation was probed locally with Connexion and the petstore spec.
  • CI: all 30 checks passed (2 skipped: image push/publish), incl. integration tests and the kind chart installation; Sourcery approved (one thread, on the process-wide log filter, answered with a migration-guide note and resolved).
  • Review: adversarial + quality reviewers, two rounds; findings fixed (migration note on app-raised BadRequestProblem, default stated in the model docstring, default-config test, check-order test, create_app() Raises, re-wrapping).

Declined review findings

  • Run the group checks before _create_base_app() (so that a misconfigured app fails before MongoDB is set up): declined, the same ordering applies to the existing require_admin check, and the checks only apply with access control enabled, which register_access_control() decides; moving all startup checks earlier would be a separate change.

Open questions

None.

Closes #467

🤖 Generated with Claude Code

Summary by Sourcery

Tighten access-control startup validation and make request-validation reasons visible by default.

New Features:

  • Default request-validation responses to include the validator’s reason in their problem detail and log it instead of the mapped exception detail.
  • Reject unusable access-control group configurations during application startup.

Bug Fixes:

  • Prevent applications from starting with group mappings that cannot apply because the group claim is missing or contains surrounding whitespace.
  • Filter Connexion’s redundant unescaped validation log messages when validation details are enabled.

Enhancements:

  • Clarify access-control startup checks and exception behavior across configuration references and migration guidance.
  • Update examples and API documentation to reflect the new validation-detail default.

Documentation:

  • Document the breaking changes for group configuration validation and default request-validation details in the 0.18 migration guide.
  • Update access-control, deployment, exception, model, template, and example documentation for the revised behavior.

Tests:

  • Expand unit and integration coverage for validation details enabled by default and for startup rejection of invalid group settings.
  • Verify group checks run before admin checks and before access-control database registration.

uniqueg and others added 4 commits October 24, 2026 16:00
With access control enabled, Foca.create_app() now refuses to start
(ValueError) if group_mapping maps groups but claim_groups is not set,
or if claim_groups has surrounding whitespace, as no group mapping can
then apply. An empty group_mapping without claim_groups stays allowed,
with a warning; group_mapping without keep_group_subjects stays a
warning.

exceptions.validation_details now defaults to true, so clients get the
reason of requests rejected by Connexion's validation, and Connexion's
unescaped request validation messages are filtered out by default.

BREAKING CHANGE: apps with these group settings no longer start, and
responses to invalid requests have the validator's reason as detail
unless exceptions.validation_details is set to false.

Closes #467

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document that app-raised BadRequestProblem exceptions get their own
detail by default too, state the default in the model docstring, list
the startup errors of create_app(), test the default without a config
and the order of the group and admin checks, and re-wrap the migration
guide.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This breaking change tightens access-control startup checks so ineffective group settings fail explicitly, while making request-validation reasons the default response and logging detail and filtering Connexion's duplicate messages; configuration, implementation, tests, examples, and migration documentation are updated accordingly.

Sequence diagram for request-validation details

sequenceDiagram
    participant Client
    participant Connexion
    participant FOCA
    participant Logger

    Client->>Connexion: Invalid request
    Connexion->>FOCA: BadRequestProblem or ExtraParameterProblem
    FOCA->>FOCA: problem_response
    FOCA->>Logger: Log validator reason at INFO
    FOCA-->>Client: 400 detail: validator reason
    Connexion-->>Logger: Validation message filtered
Loading

Flow diagram for access-control startup validation

flowchart TD
    A[Foca.create_app] --> B[_check_group_config]
    B --> C{Invalid group configuration?}
    C -->|Mapped groups without claim_groups| D[Raise ValueError]
    C -->|claim_groups has surrounding whitespace| D
    C -->|Empty mapping without claim_groups| E[Log warning]
    C -->|Otherwise| F[_check_admin_role]
    D --> G[Startup stops]
    E --> F
    F --> H{require_admin and no admin?}
    H -->|Yes| I[Raise ValueError]
    H -->|No| J[Continue app startup]
Loading

File-Level Changes

Change Details Files
Startup validation now rejects group configurations that cannot take effect while preserving warnings for harmless or partial no-op settings.
  • Raise ValueError for mapped groups without a group claim and for whitespace-padded claims.
  • Allow empty mappings without a claim with a warning, and retain the keep-group-subjects warning.
  • Simplify admin-role checks because invalid group configurations fail first.
  • Document and test validation behavior and check ordering.
foca/security/access_control/register_access_control.py
foca/foca.py
foca/models/config.py
tests/security/access_control/test_register_access_control.py
docs/configuration/access-control.md
docs/deployment.md
docs/migration-0.18.md
Request-validation details are enabled by default and Connexion's duplicate unescaped validation logs are filtered.
  • Change ExceptionConfig and the generated template default to true.
  • Return validator reasons in detail and log them at INFO; retain mapped responses and exception logging when disabled.
  • Apply the behavior to app-raised BadRequestProblem and ExtraParameterProblem exceptions.
  • Update unit and petstore integration expectations and isolate the process-wide Connexion logger filter in tests.
  • Document the breaking response and logging changes, including migration guidance.
foca/models/config.py
templates/config.yaml
tests/errors/test_errors.py
tests/integration_tests.py
docs/configuration/exceptions.md
docs/migration-0.18.md
examples/petstore-access-control/exceptions.py
examples/petstore/exceptions.py

Assessment against linked issues

Issue Objective Addressed Explanation
#467 With access control enabled, reject group configurations that prevent mappings from applying: raise ValueError for a non-empty group_mapping without a group claim and for a claim_groups value with surrounding whitespace, while allowing an empty mapping without a claim. ✅
#467 Default exceptions.validation_details to true, so validation rejection reasons are returned and logged as details while Connexion’s unescaped request-validation messages are filtered out by default. ✅
#467 Update configuration and deployment documentation, migration guidance, templates, and tests to reflect the changed group checks and validation-detail default. ✅

Possibly linked issues


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 Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (08b2df1) to head (a1b44a6).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #475   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        29           
  Lines         3446      3447    +1     
=========================================
+ Hits          3446      3447    +1     
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 October 24, 2026 14:23

@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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="foca/models/config.py" line_range="295" />
<code_context>
     logging: ExceptionLoggingEnum = ExceptionLoggingEnum.oneline
     media_type: str = DEFAULT_ERROR_MEDIA_TYPE
-    validation_details: bool = False
+    validation_details: bool = True
     max_detail_length: PositiveInt = 500
     # Problem details by exception class, imported from `mapping`
</code_context>
<issue_to_address>
**Disabled details still suppress validation logs**

When multiple apps run in one process and at least one uses the new default while another sets `validation_details: false`, `validation_details` defaults to true, so another app registered with default settings installs `_keep_response_validation_records` on Connexion’s process-wide validation logger. That filter also suppresses request-validation messages for an app configured with `validation_details: false`, so that app does not retain its previous Connexion logs.

Clarify the migration guidance that `false` cannot restore Connexion’s request-validation logs when another app in the process has enabled validation details.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and with validation_details enabled by default, unauthenticated requesters can receive validator reasons in responses, potentially revealing API structure or validation constraints; those disclosures cannot be undone by reverting. This is a default information-disclosure policy, so the exposure applies across deployments that do not override it.

Blocking findings: foca/models/config.py:295


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

Comment thread foca/models/config.py Resolved
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Oct 24, 2026

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

Sourcery assessment

Approved.

@sourcery-ai
sourcery-ai Bot dismissed their stale review October 24, 2026 14:36

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@uniqueg
uniqueg merged commit b2cc3f3 into dev Oct 24, 2026
32 checks passed
@uniqueg
uniqueg deleted the feat/tighten-config-checks branch October 24, 2026 14:42
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.

feat: tighten group checks and error details

1 participant