Skip to content

fix: reject dot segments as principals - #259

Merged
uniqueg merged 6 commits into
devfrom
fix/dot-principals
Oct 26, 2026
Merged

uniqueg merged 6 commits into
devfrom
fix/dot-principals

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Summary

User identifiers and groups in the permission paths (/services/{serviceId}/permissions/{userId}, /services/{serviceId}/permissions/groups/{group}) accepted dot segments. Clients that build URLs with encodeURIComponent leave dots unencoded, and URL resolution then sends such requests to other paths (found in cloud-registry-ui's pre-release review).

  • UserId and Group now have a pattern that rejects dot segments (400), like service IDs: the whole value . or .., and for groups (which may contain slashes) also ./.. segments between slashes, e.g. a/../b or ../a (which a client that doesn't encode slashes would resolve to the user a). Backslashes count as slashes, as in browsers (WHATWG URLs).
  • 400 is now declared on both revoke operations.
  • Docs: docs/access-control.md and docs/api.md.

LS Login subjects ([email protected]) and URN groups are unaffected; tests show that dots inside segments (..., .a, a., a/.b/c, URLs) are still accepted.

Closes #252

Verification

  • Regression tests first: the new tests in tests/test_access_control.py failed on dev (assert 200 == 400) and pass now.
  • coverage run --source cloud_registry,scripts -m pytest: 1288 passed, 230 skipped (MongoDB-backed); coverage 100%.
  • tests/test_access_control.py and tests/test_app.py against a local MongoDB 7.0: 284 passed.
  • pre-commit run on the changed files: passed.
  • Reviews: adversarial-reviewer (2 rounds) and quality-reviewer; fixed the findings except those listed below.
  • CI: all checks passed on f6b8ece (CI passed, Test (MongoDB 7.0), Test (mongomock), Lint, Docs, Chart, Smoke test, Scan image, CodeQL, Read the Docs).
  • Sourcery: 4 threads. Fixed the line-break bypass in the patterns and the test assertions; answered and resolved the client-side normalisation and existing-grants threads (see below).

Declined review findings

  • Grants to principals ./.. (or with such segments) stored before this change can no longer be revoked through the API (DELETE now returns 400), only by deleting the service or in the database. Not expected to exist: they could only be created by sending such URLs, which the clients in use don't do, and owners can only grant roles to groups they are members of.

Open questions

None. Merge only after v0.5.0 is tagged (dev is frozen for the 0.5.0 release); this goes into 0.6.0.

🤖 Generated with Claude Code

Summary by Sourcery

Prevent URL path normalization from redirecting permission requests to unintended users or groups by rejecting dot-segment principals.

Bug Fixes:

  • Reject user and group permission principals containing URL-resolvable . or .. path segments with 400 Bad Request.
  • Declare 400 Bad Request responses for both permission revoke operations.

Documentation:

  • Document the restrictions on dot segments in permission principals and their URL-resolution rationale.

Tests:

  • Add regression coverage for rejected dot segments, accepted non-segment dots, and slash/backslash variations in user and group principals.

uniqueg and others added 3 commits October 26, 2026 16:58
User IDs and groups in permission paths accepted `.` and `..`,
which clients resolve in URLs (`encodeURIComponent` leaves dots
unencoded), so requests went to other paths. Reject them with the
same pattern as service IDs (400) and declare 400 on the revoke
operations.

Closes #252

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Groups may contain slashes, so a group like `a/../b` or `../a` is
resolved by clients that don't encode slashes, e.g. to the user `a`.
Reject `.` and `..` segments anywhere in a group, document the 400 for
users and groups in the API docs and split the tests per principal kind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Browsers (WHATWG URLs) take backslashes in http(s) paths as slashes, so
`..\b` is resolved like `../b`. Reject dot segments between backslashes
in user identifiers and groups, too.

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

sourcery-ai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR prevents ambiguous URL resolution by validating user and group path parameters against dot segments, declares the resulting 400 responses, documents the behavior, and adds comprehensive regression tests covering encoded, slash/backslash-delimited, and valid dotted principals.

Sequence diagram for rejecting dot-segment permission principals

sequenceDiagram
    actor Client
    participant API
    participant Validator

    Client->>API: Request permission endpoint with userId or group
    API->>Validator: Validate path parameter pattern
    alt Dot segment detected
        Validator-->>API: Validation failure
        API-->>Client: 400 Bad Request
    else Valid principal
        Validator-->>API: Validation success
        API-->>Client: Permission operation result
    end
Loading

Flow diagram for principal path validation

flowchart TD
    A[UserId or Group path value] --> B{Contains standalone . or .. segment?}
    B -->|Yes| C[Reject with 400 Bad Request]
    B -->|No| D[Accept principal and process permission request]
    E[Dots inside segments or URLs] --> D
Loading

File-Level Changes

Change Details Files
Reject URL dot segments in permission principals before grants or revocations are processed.
  • Add OpenAPI path-parameter patterns rejecting . and .. as complete values and as slash/backslash-delimited segments.
  • Apply validation to both user identifiers and groups, while preserving dots embedded in ordinary segments and URL-like groups.
  • Document the new 400 Bad Request behavior and its URL-resolution rationale.
cloud_registry/api/additions.openapi.yaml
docs/access-control.md
docs/api.md
Add regression coverage for rejected and accepted principal forms.
  • Test dot-segment rejection for user and group grants and revocations, including encoded dots, slashes, and backslashes.
  • Verify ordinary dotted identifiers, group segments, and URLs remain accepted.
  • Verify rejected requests do not create permissions.
tests/test_access_control.py

Assessment against linked issues

Issue Objective Addressed Explanation
#252 Reject . and .. as user IDs and groups in the permissions API, as specified in the API schema. ✅
#252 Add tests confirming dot-segment principals are rejected with HTTP 400. ✅

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 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (48059aa) to head (bdcb403).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #259   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines         1778      1778           
=========================================
  Hits          1778      1778           

☔ 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 26, 2026 17:10

@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 4 issues

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

## Individual Comments

### Comment 1
<location path="cloud_registry/api/additions.openapi.yaml" line_range="798" />
<code_context>
       schema:
         type: string
+        # no dot segments (`.`, `..`), also between backslashes (cf. `Group`)
+        pattern: '^(?!(.*[/\\])?\.\.?([/\\]|$))'
     Group:
       name: group
</code_context>
<issue_to_address>
**Dot segments target another principal**

When a client puts literal slashes around a dot segment in a group permission URL, the browser normalizes the path before sending the request, so Connexion binds a different route or principal and the group pattern never sees the intended value; the permission handler grants or revokes access for the unintended principal.

Ensure slash-containing group values cannot be normalized into a different permission route before validation.

Also at `cloud_registry/api/additions.openapi.yaml:778`.
</issue_to_address>

### Comment 2
<location path="cloud_registry/api/additions.openapi.yaml" line_range="778" />
<code_context>
       schema:
         type: string
+        # no dot segments (`.`, `..`), also between backslashes (cf. `Group`)
+        pattern: '^(?!(.*[/\\])?\.\.?([/\\]|$))'
     Group:
       name: group
</code_context>
<issue_to_address>
**Existing grants cannot be revoked**

When a service already has a stored permission for a user or group containing a dot-segment path, dELETE parameter validation rejects the path before `deleteServicePermission` or `deleteServiceGroupPermission` reaches `_delete_roles`, so the stored role remains and its holder keeps access.

Provide a way to delete existing dot-segment permissions without the new validation blocking the DELETE request.

Also at `cloud_registry/api/additions.openapi.yaml:798`.
</issue_to_address>

### Comment 3
<location path="cloud_registry/api/additions.openapi.yaml" line_range="778" />
<code_context>
       schema:
         type: string
+        # no dot segments (`.`, `..`), also between backslashes (cf. `Group`)
+        pattern: '^(?!(.*[/\\])?\.\.?([/\\]|$))'
     Group:
       name: group
</code_context>
<issue_to_address>
**Newline bypasses dot-segment check**

When a user or group identifier contains a line break before a later slash- or backslash-delimited dot segment, the `.*` prefix in the user and group patterns cannot cross the line break, so validation accepts the principal and it can be stored despite containing a forbidden `.` or `..` segment.

Make the prefix match line breaks in both patterns.

Also at `cloud_registry/api/additions.openapi.yaml:798`.
</issue_to_address>

### Comment 4
<location path="tests/test_access_control.py" line_range="1263-1265" />
<code_context>
+    """
+    service_id = register(client)
+    url = f"{BASE}/services/{service_id}/permissions/{kind}{principal}"
+    response = client.put(url, json={"role": "owner"}, headers=headers(ADMIN))
+    assert response.status_code == 400
+    assert client.delete(url, headers=headers(ADMIN)).status_code == 400
+    assert permission_list(client, service_id) == [
+        {"user_id": ALICE, "name": NAMES[ALICE], "role": "owner"}
</code_context>
<issue_to_address>
**Principal state goes unchecked**

When the handlers return the expected status codes but mutate permissions incorrectly or do not persist the dotted user grant, the handlers can persist a backslash-dot user while returning 400, and `test_dot_segments_in_users` still passes because it checks only response codes. They can also return 200 for no-op grants and revokes, and `test_dotted_principals` still passes without checking that the user role was stored.

Assert that rejected user requests leave permissions unchanged and that the dotted user grant appears in the permission list before revoking it.

Also at `tests/test_access_control.py:1272-1275`.
</issue_to_address>

Sourcery assessment

Approval pending. 4 findings to address first.

Blocking findings: cloud_registry/api/additions.openapi.yaml:798, cloud_registry/api/additions.openapi.yaml:778, cloud_registry/api/additions.openapi.yaml:778, tests/test_access_control.py:1265


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

Comment thread tests/test_access_control.py Resolved
uniqueg and others added 3 commits October 26, 2026 19:43
`.` doesn't match line breaks, so a dot segment after one wasn't
rejected by the patterns (FOCA rejects such values in roles anyway).
Also check that rejected and accepted principals change the stored
roles as expected (Sourcery review).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit f579a98 into dev Oct 26, 2026
19 checks passed
@uniqueg
uniqueg deleted the fix/dot-principals branch October 26, 2026 19:43
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: reject dot segments as principals

1 participant