Skip to content

fix: hide duplicates from non-readers in 409 - #208

Merged
uniqueg merged 7 commits into
devfrom
fix/hide-duplicates-409
Oct 23, 2026
Merged

uniqueg merged 7 commits into
devfrom
fix/hide-duplicates-409

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Registering a service with the URL and API type of a registered one (POST /services, or PUT of another service) returned 409 Conflict with the registered service's identifier (serviceId, and in detail) to every caller, also to users who may not read services under the readers recipe of "Requiring login for reads".

As decided in #203:

  • Callers who may read the registered service get the 409 as before, with serviceId and the identifier in detail.
  • Other callers get a generic 409 ("A service with the same URL and API type is registered."), without serviceId or other details of the registered service.
  • The read check is the same decision as for GET /services/{serviceId} with the caller's token (may_read_service() in permissions.py). It pushes a request context for that GET, takes FOCA's decision on whether policies are enforced on its route (only with the login-for-reads patch), and if they are, evaluates them with FOCA's is_permitted(), using the caller's validated token. Policy evaluation is not reimplemented. Identifiers that aren't routed to that operation (e.g., with slashes) count as not readable.
  • With default public reads, nothing changes.
  • The spec addition (DuplicateService response) describes both forms; serviceId is no longer required.
  • Docs: docs/access-control.md, docs/api.md and the 0.3.0 release notes say who gets the identifier, and that 409 rather than 201 still tells others that the URL is taken, which can't be avoided while duplicates are rejected.

may_read_service() relies on FOCA's internal _enforces_access_control() (as FOCA's own ownership_server does) and on Connexion's connexion_context on the request context, because FOCA has no public helper for the decision on another request. The tests pin the behaviour against the pinned FOCA commit. Proposed follow-up: a public FOCA helper (e.g., is_permitted(path, method)), so that apps don't need these internals.

Verification

  • pytest -W ignore::DeprecationWarning under coverage (mongomock; the MongoDB-only tests are skipped locally and run in CI): 983 passed, 211 skipped; coverage 100%.
  • New tests in tests/test_access_control.py, for POST and PUT:
    • public reads: all users get the identifier;
    • login for reads by any user: all users get it;
    • readers recipe: readers and admins get it, other users get the generic 409, also for services they own themselves;
    • identifiers routed elsewhere (a/b, a/verification, a/permissions) count as not readable.
  • pre-commit run --all-files (ruff, mypy, semgrep, gitleaks, actionlint, ast-grep): passed.
  • mkdocs build --strict: passed.
  • python scripts/release_notes.py check docs/releases/0.3.0.md: passed.
  • CI: all checks passed on 05f87a2 (tests with mongomock and MongoDB 7.0, docs, chart, Docker Compose, image scan, CodeQL).

Review

Full lane (access control). Reviewers: adversarial and quality, 2 rounds.

Round 2 found one docstring placement issue (fixed); no other findings.

Round 1, fixed:

  • Identifiers with slashes were routed to other operations, whose policies then decided. Now only the route of GET /services/{serviceId} counts.
  • A log line explains why a 409 hides the service, next to FOCA's "Access denied" line for the check.
  • DuplicateService.hidden() now builds the generic conflict.
  • Test additions and a docs rewrap.

Declined review findings

  • Use a public FOCA helper instead of internals (quality, medium): FOCA has none at the pinned commit, and adding one means a FOCA change plus a repin before v0.3.0. The dependency is documented in the docstring, pinned by tests, and proposed as a FOCA follow-up.
  • An end-to-end test for unroutable identifiers (quality, medium): PUT routing can't create such services, so the branch is covered by the unit test of may_read_service().
  • Reuse the registration payload instead of reading the service back in the test helper (quality, low): register() builds its payload internally; reading the service back keeps the helper independent of it.
  • Return the generic 409 if the policy backend fails during the read check (Sourcery): a 500 already fails closed (no identifier), the same backend just enforced the POST/PUT policies in the same request, and catching it would hide infrastructure errors.

Open questions

None.

Closes #203

🤖 Generated with Claude Code

uniqueg and others added 6 commits October 23, 2026 18:58
Registering a service with the URL and API type of a registered one
(POST, or PUT of another service) returned 409 with the registered
service's identifier to every caller, also to users who may not read
it when a deployment requires login for reads (readers recipe).

Name the registered service (serviceId, detail) only if the caller may
get it: the same decision as for GET /services/{serviceId}, via the
route of that request (whether FOCA enforces policies on it) and FOCA's
is_permitted() for its path, with the caller's validated token. Others
get a generic 409 without the service. The spec describes both forms;
serviceId is no longer required.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The access control and API pages and the 0.3.0 release notes say that
409 names the registered service only to users who may read it, and
that 409 rather than 201 still tells others the URL is taken.

Closes #203

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Identifiers with slashes were routed to other operations (e.g.,
/services/{id}/verification), whose policies then decided. Require the
route of GET /services/{serviceId} for the identifier. Log why a 409
hides the service, next to FOCA's denied check, and let
DuplicateService build the hidden conflict (review findings).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Google-style parsers read paragraphs after Args as part of the last
argument (review finding).

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

sourcery-ai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR prevents duplicate-service 409 responses from exposing the conflicting service identifier to callers who cannot read it, while preserving existing details for authorized readers. It implements the decision using the GET /services/{serviceId} route and FOCA policy evaluation, updates the API/docs, and adds comprehensive access-control tests.

File-Level Changes

Change Details Files
Conditionally redact duplicate-service identifiers based on the caller’s ability to read the conflicting service.
  • Added a may_read_service() check that reproduces GET /services/{serviceId} routing and FOCA policy enforcement using the validated caller token.
  • Returned the existing detailed conflict for authorized readers and a generic conflict for non-readers, including owners.
  • Added a DuplicateService.hidden() factory for the redacted response and explanatory logging for hidden conflicts.
cloud_registry/ga4gh/registry/permissions.py
cloud_registry/ga4gh/registry/server.py
cloud_registry/ga4gh/registry/service.py
Updated the API contract and user-facing documentation to describe the two duplicate-conflict response forms and their remaining URL-existence disclosure.
  • Made serviceId optional in the DuplicateService response schema and documented when it is included.
  • Documented reader-dependent disclosure behavior in access-control, API, and release documentation.
cloud_registry/api/additions.openapi.yaml
docs/access-control.md
docs/api.md
docs/releases/0.3.0.md
Added access-control coverage for duplicate registration and update conflicts across read-policy configurations and routing edge cases.
  • Verified named conflicts for public reads and login-required reads.
  • Verified named conflicts for readers and admins, and generic conflicts for other users and self-owned services.
  • Verified identifiers routed to other operations or no matching read route are treated as unreadable for this check.
tests/test_access_control.py

Assessment against linked issues

Issue Objective Addressed Explanation
#203 Return the existing service’s identifier and name in duplicate-service 409 responses only when the caller may read that service using the same access-control decision as GET /services/{id}; otherwise return a generic 409 without identifying details. Apply this to both POST and PUT, while preserving behavior under public reads. ✅
#203 Document both forms of the duplicate-service 409 in the API specification and update access-control and release documentation to explain the remaining URL-taken signal for callers who cannot read the service. ✅
#203 Add tests covering readable and non-readable callers under the readers policy, and confirm default public-read behavior remains unchanged for both POST and PUT. ✅

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

@uniqueg
uniqueg marked this pull request as ready for review October 23, 2026 17:29
@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (022527b) to head (05f87a2).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #208   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines         1136      1156   +20     
=========================================
+ Hits          1136      1156   +20     

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

@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="cloud_registry/ga4gh/registry/permissions.py" line_range="245" />
<code_context>
+            return True
+        # an attribute that Connexion adds
+        request_ctx.connexion_context = connexion_context  # type: ignore[attr-defined]
+        return is_permitted()
+
+
</code_context>
<issue_to_address>
**Permission backend error aborts duplicate response**

When the duplicate-service lookup succeeds but FOCA's permission or role backend errors while evaluating the read policy, `is_permitted()` propagates the authorization-backend error, and `_register_service()` has no handler for it, so a duplicate registration returns a 500 instead of the generic 409.

Handle authorization-evaluation failures explicitly, returning only a generic conflict if that is the intended fail-closed response.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the permission check incorrectly treats a non-reader as allowed, the 409 response includes the registered service’s identifier and detail, which cannot be undisclosed by reverting. The response still reveals that a duplicate exists, but this change introduces the risk of also exposing which service it is.

Blocking findings: cloud_registry/ga4gh/registry/permissions.py:245


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

@uniqueg
uniqueg merged commit b3253b3 into dev Oct 23, 2026
19 checks passed
@uniqueg
uniqueg deleted the fix/hide-duplicates-409 branch October 23, 2026 17:32
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: hide duplicates from non-readers in 409

1 participant