Skip to content

fix: support recursive attributes in lookup-entity#1

Open
erberkson wants to merge 1 commit intobefore-recursivefrom
demo-recursive
Open

fix: support recursive attributes in lookup-entity#1
erberkson wants to merge 1 commit intobefore-recursivefrom
demo-recursive

Conversation

@erberkson
Copy link
Copy Markdown
Owner

…ributes

fix: support recursive attributes in lookup-entity

…ive-attributes

fix: support recursive attributes in lookup-entity
@matrixreview
Copy link
Copy Markdown

matrixreview Bot commented Apr 10, 2026

πŸ”΄ MatrixReview β€” RED

βš™οΈ = code-backed Β Β·Β  πŸ”Ž = doc-backed Β Β·Β  πŸ’­ = AI suggestion Β Β·Β  πŸ“– = doc citation Β Β·Β  πŸ“ = PR location

Risk: 5 files directly affected
Findings: 12 (1 code-backed, 13 doc-backed, 3 AI suggestions)

πŸ”΄ SECURITY β€” 5 findings (4 doc-backed, 1 AI) Β· expand πŸ”½
  • πŸ”Ž [SECURITY] The PR introduces a new function decodeCursorValue that decodes a cursor token from a string. This function is used in the new expandRecursiveRelation method for pagination. If the cursor is us...

    Read more Β· expand πŸ”½

    ...er-controlled (e.g., from an API request), an attacker could potentially inject a maliciously crafted token that, when decoded, could cause unexpected behavior, such as panics or information disclosure, if the decoding fails or returns an unexpected value. The function does not validate the structure of the decoded token beyond type assertion, which could lead to security issues if the token is tampered with.

    - *Also flagged by: ARCHITECTURE, STYLE* πŸ“– *authorization-service_security_section.md lines 39-41* πŸ“ `internal/engines/entity_filter.go line 257`
  • πŸ”Ž [SECURITY] The PR adds a new constant _maxBFSDepth = 100 to limit recursive relation expansion depth, which is a good practice to prevent infinite recursion or excessive resource consumption. However, the d...

    Read more Β· expand πŸ”½

    ...epth limit is hard-coded and may not be sufficient for all schemas or could be too restrictive. An attacker could craft a deeply nested recursive relation chain to trigger the depth limit error, potentially causing a denial-of-service by forcing the system to traverse many levels before hitting the limit. The error message returned includes the depth limit value, which could be considered information disclosure.

    - *Also flagged by: ARCHITECTURE, STYLE, ONBOARDING* πŸ“– *authorization-service_security_section.md lines 10-15* πŸ“ `internal/engines/entity_filter.go line 18`
  • πŸ”Ž [SECURITY] The expandRecursiveRelation function performs a BFS traversal over recursive relations without any rate limiting or cost limiting beyond the depth limit. An attacker could create a large number o...

    Read more Β· expand πŸ”½

    ...f recursive relations (e.g., a densely connected graph) and trigger a lookup that would cause the engine to traverse many entities, consuming significant CPU and memory resources, leading to a potential denial-of-service attack.

    πŸ“– *authorization-service_security_section.md lines 10-15* πŸ“ `internal/engines/entity_filter.go line 274`
  • πŸ”Ž [BUG] In the attributeEntrance function, when expandRecursive is true and a cursor is present, the code fetches all seed entities without cursor filtering (`seedPagination := database.NewCursorPagina...

    Read more Β· expand πŸ”½

    ...tion(database.Sort("entity_id"))`). This could lead to performance issues if there are a large number of entities, as it loads all entities of that type into memory, defeating the purpose of pagination.

    πŸ“– *authorization-service_security_section.md lines 10-15* πŸ“ `internal/engines/entity_filter.go line 211`
  • πŸ’­ [BUG] In the expandRecursiveRelation function, the cursor value is decoded and used to filter entities (if cursorValue == "" || entity.GetId() >= cursorValue). This comparison assumes that entity IDs...

    Read more Β· expand πŸ”½

    ... are strings and that a lexicographic comparison is appropriate for pagination. However, if entity IDs are not lexicographically ordered (e.g., numeric IDs like "2" vs "10"), this could lead to incorrect pagination results, potentially skipping or duplicating entities. This could break the pagination logic for recursive attribute lookups.

    πŸ“ `internal/engines/entity_filter.go line 356`
🟑 ARCHITECTURE β€” 4 findings (1 code-backed, 3 doc-backed) Β· expand πŸ”½
  • βš™οΈ HIGH: 1 files depend on modified it.

    Show affected files
  • πŸ”Ž [ARCHITECTURE] The PR adds a new method SelfCycleRelationsForPermission to the LinkedSchemaGraph to detect recursive relations. This introduces a new schema analysis capability that is not documented in the a...

    Read more Β· expand πŸ”½

    ...rchitecture. The architecture documentation describes the schema server's role as validating requests and passing them to the database access layer, but does not mention runtime schema analysis for recursion detection. This could affect the performance and consistency of the schema server.

    πŸ“– *infrastructure.md lines 40-45* πŸ“ `internal/schema/linked_schema.go line 514`
  • πŸ”Ž [ARCHITECTURE] The PR modifies the findEntranceLeaf function in linked_schema.go to handle nested path chains and preserve tuple-set relations. This change affects the schema graph traversal logic, which is a...

    Read more Β· expand πŸ”½

    ... core part of the permission evaluation engine. The architecture documentation describes the permission server's invoker breaking down queries into sub-queries, but does not detail the schema graph traversal algorithms. Changes to this core logic without architectural documentation could impact the consistency and correctness of permission evaluations.

    πŸ“– *infrastructure.md lines 33-38* πŸ“ `internal/schema/linked_schema.go line 272`
  • πŸ”Ž [PERFORMANCE] The PR introduces a BFS expansion algorithm for recursive relations in entity_filter.go with a depth limit. This algorithm could lead to increased database queries and memory usage for deep recur...

    Read more Β· expand πŸ”½

    ...sion graphs, impacting the performance of the lookup engine. The architecture documentation states that loading authorization data presents a 'significant downside in terms of performance and scalability' and that the authorization service must be 'fast'. The new recursive expansion could exacerbate performance issues if not carefully optimized.

    πŸ“– *authorization-service_architecture_section.md lines 31-38* πŸ“ `internal/engines/entity_filter.go line 270`

🟒 LEGAL β€” No issues found

🟑 STYLE β€” 1 findings (1 AI) Β· expand πŸ”½
  • πŸ’­ [STYLE] The test 'should stop same-type recursive attribute expansion at the BFS depth limit' uses a hardcoded loop to create tuples up to '_maxBFSDepth'. The test may be inefficient and could be simplifie...

    Read more Β· expand πŸ”½

    ...d. However, no explicit style rule is violated.

    πŸ“ `internal/engines/lookup_test.go line 6390`
πŸ”΄ ONBOARDING β€” 2 findings (1 doc-backed, 1 AI) Β· expand πŸ”½
  • πŸ”Ž [CHORE] The PR description is minimal and does not follow the recommended issue/PR template structure. The CONTRIBUTING_onboarding_section.md suggests discussing new features with community members/maintai...

    Read more Β· expand πŸ”½

    ...ners and ensuring to follow the steps before contributing. The PR description lacks context about the problem being solved, the design decisions, or any prior discussion.

    πŸ“– *CONTRIBUTING_onboarding_section.md lines 3-8*
  • πŸ’­ [CHORE] The PR includes extensive test additions (check_test.go, lookup_test.go, linked_schema_test.go) but does not appear to have corresponding updates to the test documentation or contribution guideline...

    Read more Β· expand πŸ”½

    ...s about testing standards. The CONTRIBUTING_onboarding_section.md advises to ensure no duplicate issues and to discuss features, but does not explicitly require tests. However, the intro_onboarding_section.md states 'We're collaboratively working with our community to make Permify the best it can be! You can develop new features, fix existing issues...' which implies maintaining quality, including testing. The lack of any mention of test updates in the PR description or linked documentation suggests the contributor may not have considered updating test guidelines.

    πŸ“– *intro_onboarding_section.md lines 10-12* πŸ“ `internal/engines/check_test.go line 2375`

πŸ‘† Click expand on any gate above to see full findings with evidence and citations.


Powered by MatrixReview Β· Report incorrect finding

βš™οΈ Generate Fix

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.

2 participants