fix(authz): anchor tenant-scope auth exemption to exact paths#74
Merged
Conversation
The tenant_scope middleware exempted identity endpoints from tenant
scoping with an unanchored substring test (`path.contains("/forge/auth/")`).
A crafted entity path that merely contained that substring — e.g.
`/forge/Account/forge/auth/me` — or a prefix+traversal path such as
`/forge/auth/me/../Account/123` would skip tenant scoping and reach
tenant-scoped data unscoped.
Replace the substring check with an exact-match allowlist of the three
known identity routes, extracted as a pure `is_tenancy_exempt` function
so the security-relevant decision is directly unit-testable. Add tests
covering the substring and traversal bypass vectors; the prior early-out
had no regression coverage because the integration harness does not layer
this middleware.
Follow-up to #70/#72.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes an authorization-bypass class in the
tenant_scopemiddleware introduced alongside #70 (GET /auth/me, merged in #72).The middleware exempted identity endpoints from tenant scoping with an unanchored substring test:
Any request path that merely contains
/forge/auth/would skip tenant scoping and reach tenant-scoped entity data unscoped. Vectors:/forge/Account/forge/auth/me/forge/auth/me/../Account/123(should an upstream proxy fail to normalize..)Flagged by automated security review (MEDIUM — Substring/Unanchored Allowlist Bypass).
Fix
/forge/auth/{login,refresh,me}— the path shape this layer observes, since it wraps the/forgenest but sits under the/api/v{n}version mount).is_tenancy_exempt(path: &str) -> boolso the security-relevant logic is directly unit-testable./forge/auth/*routes are not silently exempted — they must be added to the allowlist explicitly.Tests
auth_login.rs) mountsauth_routes()without this layer.462 passed.cargo clippy -p schema-forge-acton --all-targets: 0 warnings.Follow-up to #70 / #72.