Repository navigation
fix: log route templates instead of paths - #750
Conversation
Requests rejected by request validation without invalid fields were logged at INFO with the validator's reason, which may quote rejected values. Log the mapped detail or the title at INFO instead, and the reason at DEBUG. Refs #748 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The traffic log wrote the request line with the concrete path, whose path parameters are values of clients. Log the route (path template of the operation, or <unknown route>) instead, and the path at DEBUG. Refs #748 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Denials of access control logged the request path at the denied level. Log the route instead, and the path at DEBUG. Refs #748 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Document that request logs, access denials and validation rejections log routes and titles at INFO and paths and reasons at DEBUG, in the utilities, logging, exceptions and access control pages, the migration guide and the 0.22.0 release notes. Refs #748 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Controllers routed by Flask, not as operations, are logged with the <unknown route> placeholder; validation reasons, which quote rejected values, may appear at DEBUG. Also rewrap docs paragraphs. Refs #748 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Log the subject with the path of denied requests, test denials without a route, and document that validation exceptions are logged at ERROR without exceptions.validation_details. Refs #748 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideImplementationLog validation failures at INFO using invalid-field details, mapped detail, or title, and move potentially value-bearing validator reasons to DEBUG.
Use operation route templates for access-denial messages and log the concrete denied path, with the subject, at DEBUG.
Use route templates in traffic logs, represent missing routes with a placeholder, and log each concrete request path at DEBUG when traffic logging is enabled.
DocumentationDocument route-based traffic and denial logs, DEBUG-level paths and validation reasons, and the related migration and release-note changes.
TestsVerify validation responses and logs keep reasons at DEBUG while INFO summaries avoid rejected values.
Verify traffic logs use routes or the unknown-route placeholder and emit escaped concrete paths at DEBUG only when needed.
Verify access-denial logs use route templates at the denied level and include escaped paths only at DEBUG, including requests without a route.
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 #750 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 74 74
Lines 9434 9443 +9
=========================================
+ Hits 9434 9443 +9
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:
|
Keep both Security entries in docs/releases/0.22.0.md and add #750 to the entry for #748. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="foca/errors/exceptions.py" line_range="357-363" />
<code_context>
else:
- logged = problem.get("detail")
+ logged = problem["title"]
logger.info(
"Request rejected: %s",
- _shorten(
- escape_log_value(problem["title"] if logged is None else logged),
- conf.max_detail_length,
- ),
+ _shorten(escape_log_value(logged), conf.max_detail_length),
)
+ if reason is not None:
+ logger.debug(
+ "Reason for rejecting the request: %s",
+ _shorten(escape_log_value(reason), conf.max_detail_length),
+ )
</code_context>
<issue_to_address>
**Exception logging docs name wrong level**
When an application’s operators rely on the `ExceptionConfig` API documentation for validation-log behavior, users consulting the `ExceptionConfig` documentation are told that validation rejections without invalid fields log the validator’s reason at `INFO`. The handler now logs the mapped detail or title at `INFO` and the reason at `DEBUG`, so callers get incorrect guidance about which log level contains rejected values.
Update the `ExceptionConfig` docstring to describe the mapped detail or title at `INFO` and the reason at `DEBUG`.
</issue_to_address>
### Comment 2
<location path="tests/utils/test_logging.py" line_range="185" />
<code_context>
+
+ with request_context("/items/s3cr3t", client_address=CLIENT_ADDRESS, app=app):
+ mock_func()
+ assert len(debugs) == count
</code_context>
<issue_to_address>
**Debug count does not verify path**
When `log_request` or `log_response` is true, but the decorator logs one unrelated debug message instead of the request path, `test_logging_decorator_path_once` checks only `len(debugs)`, so with request-only or response-only logging a debug message unrelated to the request path still satisfies the assertion. The test therefore passes while that configuration omits the path.
Assert the expected path message for each enabled configuration, and assert no messages when both options are false.
</issue_to_address>Linked issues
#748 Log route templates instead of request paths · 6 of 6 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Log route templates in traffic request and response lines, and concrete paths at DEBUG only. | ✅ Met | Traffic descriptions use the route or <unknown route>; the escaped request path is logged once at DEBUG when request or response logging is enabled. |
| 2 | Log route templates for access denials at the configured level, and concrete paths at DEBUG only. | ✅ Met | Denials use the route at the denied level and log the escaped path at DEBUG. |
| 3 | For validation rejections without invalid fields, log the mapped detail or title at INFO and the validator's reason at DEBUG. | ✅ Met | The handler selects the mapped detail or title for INFO and separately logs the shortened, escaped reason at DEBUG. |
| 4 | Use a fixed placeholder when no route template is known. | ✅ Met | Traffic logs and access denials use <unknown route> when the route is None. |
| 5 | Leave audit logs of grants and resource changes unchanged. | ✅ Met | The diff does not change audit logging. |
| 6 | Document the changes in logging, access control and exceptions configuration, the migration guide, and the 0.22.0 release notes. | ✅ Met | The diff updates all of the specified documentation pages. |
Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: foca/errors/exceptions.py:363, tests/utils/test_logging.py:185
The docstring of validation_details still said that the reason is logged at INFO; it is the mapped detail or the title, with the reason at DEBUG only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Follow-up to #745 (#743): log lines at
INFOand above no longer carry request paths or validators' reasons, which hold values of clients.log_traffic, also FOCA's own controllers): request and response lines name the route, the path template of the operation, e.g.,Incoming request: "GET /ga4gh/tes/v1/tasks/{id} HTTP/1.1" from 127.0.0.1, instead of the concrete path. Requests that no operation serves are logged with the placeholder<unknown route>. The concrete path is logged once per request atDEBUG(Path of request ...: /ga4gh/tes/v1/tasks/123).enforcement.py):Access denied: DELETE /items/{id} to 'alice'at the configured level (INFOfor requests,DEBUGforis_permitted_for()). The path is logged atDEBUG(Path of the denied request: DELETE /items/1 to 'alice'). TheDEBUGlineAccess grantedis unchanged._validation_handler_json): rejections without invalid fields are logged atINFOwith the mappeddetail, if any, or the title (Request rejected: Bad Request). The validator's reason is logged atDEBUG(Reason for rejecting the request: ...), shortened and escaped. Rejections with invalid fields are logged by location and code, as before.Closes #748
Verification
DEBUGonly, and paths atDEBUGonly. They pass now..semgrep),mkdocs build --strict: all passed./admin/access-control/permissions/{id}, so its traffic logs name the route. Some unit tests route the controllers with Flask directly, so those log<unknown route>.dev(with build: pick up OS security updates in images #749; ec5b32e): the only conflict was indocs/releases/0.22.0.md(both Security entries kept,#750added to this one), so no further review. Rerun locally: full suite under coverage 4910 passed, 2 skipped, 100% coverage (test_address_fallback_boundedpassed in both runs); ruff, mypy, ast-grep, semgrep (.semgrep),mkdocs build --strictpassed.dev.validation_detailsnamed the wrong level for the reason) and 302300b (test asserts the logged path, not the count);tests/utils/test_logging.py(40 passed), ruff and mypy rerun locally. CI on the final head: see the checks.Round 1 had no high findings. These were fixed:
exceptions.validation_details: false, validation exceptions are still logged atERRORwith the reason.DEBUGdenial line now names the subject.Declined review findings
Access denied: invalid subject: <exc>. Not changed: the messages ofvalidate_rule_value()are fixed texts, without the value.<unknown route>(low): not done. The private constant is used in two places only.foca/security/auth.pylogs the token validation error'sdescriptionat INFO. Checked: only errors without aninvalid_tokenchallenge reach that line, and their descriptions are fixed texts or URLs of the configured identity providers (from the trusted issuer or its discovery document), not values of clients or tokens. No change needed.Open questions
None.
🤖 Generated with Claude Code