Repository navigation
fix: reject dot segments as principals - #259
Conversation
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]>
Reviewer's GuideThe 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 principalssequenceDiagram
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
Flow diagram for principal path validationflowchart 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
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 #259 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 18
Lines 1778 1778
=========================================
Hits 1778 1778 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
`.` 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]>
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 withencodeURIComponentleave dots unencoded, and URL resolution then sends such requests to other paths (found in cloud-registry-ui's pre-release review).UserIdandGroupnow have apatternthat 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/../bor../a(which a client that doesn't encode slashes would resolve to the usera). Backslashes count as slashes, as in browsers (WHATWG URLs).400is now declared on both revoke operations.docs/access-control.mdanddocs/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
tests/test_access_control.pyfailed ondev(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.pyandtests/test_app.pyagainst a local MongoDB 7.0: 284 passed.pre-commit runon the changed files: passed.adversarial-reviewer(2 rounds) andquality-reviewer; fixed the findings except those listed below.Declined review findings
./..(or with such segments) stored before this change can no longer be revoked through the API (DELETEnow returns400), 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 (
devis 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:
.or..path segments with400 Bad Request.400 Bad Requestresponses for both permission revoke operations.Documentation:
Tests: