Repository navigation
feat!: tighten group checks and error details - #475
Conversation
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]>
Reviewer's GuideThis 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 detailssequenceDiagram
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
Flow diagram for access-control startup validationflowchart 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]
File-Level Changes
Assessment against linked issues
Possibly linked issues
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 #475 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 29
Lines 3446 3447 +1
=========================================
+ Hits 3446 3447 +1
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 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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sourcery withdrew this approval because the latest commits introduced blocking findings.
Summary
Maintainer decisions of 2026-10-24 for the unreleased 0.18.0 (follow-ups of #459/PR #466 and #461/PR #464):
Foca.create_app()refuses to start (ValueError, raised in_check_group_config(), like therequire_admincheck of feat: add startup checks of the config #466) ifgroup_mappingmaps groups butclaim_groupsis not set, or ifclaim_groupshas surrounding whitespace. An emptygroup_mappingwithoutclaim_groupsis still allowed, with a warning (rephrased, since nothing is mapped).group_mappingwithoutkeep_group_subjectsstays 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_detailsdefaults totrue: clients get the validator's reason asdetail, 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 /petswith{}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 ownBadRequestProblemexceptions too; the startup-check docs (configuration/access-control.md,deployment.md) andconfiguration/exceptions.mddescribe the new behaviour.Verification
pytestwith MongoDB 7 (coverage): 2326 passed, 1 skipped;coverage report: 100%mypy: no issues (88 files);ruff check/ruff format --check: cleanpre-commit run --all-files: all hooks passed (incl. semgrep, ast-grep)mkdocs build --strict: no warningstests/integration_tests.py) need the dockerised petstore: they run in CI only; the changed expectation was probed locally with Connexion and the petstore spec.BadRequestProblem, default stated in the model docstring, default-config test, check-order test,create_app()Raises, re-wrapping).Declined review findings
_create_base_app()(so that a misconfigured app fails before MongoDB is set up): declined, the same ordering applies to the existingrequire_admincheck, and the checks only apply with access control enabled, whichregister_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:
Bug Fixes:
Enhancements:
Documentation:
Tests: