Conversation
Add Catch2 unit tests for validateScope()
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Documentation and API wording review comments remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Implements per-resource path-scope validation for the experimental access_control plugin.
Changes:
- Adds normalized path-prefix matching with backward-compatible empty scopes.
- Enforces scope checks during authorization.
- Adds unit tests and updates documentation.
| File | Description |
|---|---|
plugins/experimental/access_control/unit_tests/test_access_control.cc |
Scope matching and integration tests |
plugins/experimental/access_control/plugin.cc |
Scope enforcement integration |
plugins/experimental/access_control/access_control.h |
Scope validation API |
plugins/experimental/access_control/access_control.cc |
Path normalization and validation |
doc/admin-guide/plugins/access_control.en.rst |
Scope behavior documentation |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * ``tid`` for `token id`_, `optional` | ||
| * ``ver`` for `version`_, `optional`, defaults to ``ver=1`` if not specified. | ||
| * ``scope`` for `scope`_, `optional`, ignored by the current version of the plugin, still not finalized (more applications and their use cases need to be studied to finalize the format) | ||
| * ``scope`` for `scope`_, `optional`, A path-prefix scope that restricts token use to matching request paths. Matching is performed on normalized path segments; |
Comment on lines
+111
to
+113
| * Validates whether a request path fails within the scope claim of an access token. | ||
| * Matching is performed on normalized path segments. An empty or absent scope is | ||
| * treated as unrestricted (returns true). |
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.

Fixes #13607
Summary
The
access_controlplugin previously parsed and exposed ascopeclaim and supported the--invalid-scope-status-codeconfiguration option, butAccessToken::validate()never evaluated the scope against incoming request paths. Consequently, any valid token authorized access to every resource covered by a remap rule, and setting--invalid-scope-status-codeproduced no effect.This PR finishes the feature by implementing path-prefix scope validation on normalized path segments, providing per-resource granularity while remaining fully backward compatible with existing tokens.
Design Approach (per #13607 suggestion)
This PR implements the minimal backward-compatible approach:
These choices are open to feedback; see Design Decisions section below.
Key Requirements & Design Decisions
Clean Separation of Concerns (Plumbing):
AccessToken::validate()focused purely on token cryptographic integrity, semantics, and timing.validateScope(requestPath, scope), called inenforceAccessControl()immediately aftertoken->validate()succeeds.OUT_OF_SCOPE, correctly triggering--invalid-scope-status-code(default: 403) and suppressing subject header extraction.Matching Semantics (Normalized Path Segments):
TSUrlPathGet()format (which omits leading slashes)./reports/(or/reports) authorizes/reports/2026/but strictly rejects sibling paths like/reports2/or/reports_backup.Backward Compatibility (Absent / Empty Scope):
scopeclaim is treated as unrestricted. Existing tokens in the field continue to function without disruption.Resource Granularity vs Target Audience (
subclaim):subrepresents target audience (e.g.frogs-in-a-well), while adding the missing per-resource granularity (e.g.scope="/reports/2026/").What Changed
Core Matching Logic (access_control.cc, access_control.h):
validateScope(StringView requestPath, StringView scope).normalizePath()to ensure leading slashes, collapse consecutive slashes, and normalize trailing slashes.@todocomments regarding scope validation.Transaction Enforcement (plugin.cc):
enforceAccessControl(), extracted the request path viaTSUrlPathGet()and validated it againsttoken->getScope().data->_vaState = OUT_OF_SCOPEand invokeshandleInvalidToken().Unit Tests (test_access_control.cc):
/reports/reports)/reports/reports/2026/annual.pdf)/reportsvs/reports2"/")addScope()/getScope()scopeis "ignored by the current version of the plugin" with full documentation of the matching semantics, segment boundary rules, and status code behavior.Future Work
/reports/{year}/)example.com:/reports/)These can be added in follow-ups once the core prefix matching is proven.
Verification
./build/plugins/experimental/access_control/unit_tests/test_access_controlcmake --build build -t format