You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The access_control plugin previously parsed and exposed a scope claim and supported the --invalid-scope-status-code configuration option, but AccessToken::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-code produced 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.
Scope check in separate function after token validation
These choices are open to feedback; see Design Decisions section below.
Key Requirements & Design Decisions
Clean Separation of Concerns (Plumbing):
Kept AccessToken::validate() focused purely on token cryptographic integrity, semantics, and timing.
Implemented scope comparison as a separate helper function, validateScope(requestPath, scope), called in enforceAccessControl() immediately after token->validate() succeeds.
When out of scope, the transaction state is set to OUT_OF_SCOPE, correctly triggering --invalid-scope-status-code (default: 403) and suppressing subject header extraction.
Matching Semantics (Normalized Path Segments):
Matching is performed as a path-prefix on normalized segments.
Handles trailing slashes, redundant slashes, and ATS's TSUrlPathGet() format (which omits leading slashes).
Enforces directory segment boundaries so that a token scoped to /reports/ (or /reports) authorizes /reports/2026/ but strictly rejects sibling paths like /reports2/ or /reports_backup.
Backward Compatibility (Absent / Empty Scope):
An absent or empty scope claim is treated as unrestricted. Existing tokens in the field continue to function without disruption.
Resource Granularity vs Target Audience (sub claim):
Retains the existing model where sub represents target audience (e.g. frogs-in-a-well), while adding the missing per-resource granularity (e.g. scope="/reports/2026/").
Token builder & parser integration with addScope() / getScope()
Documentation (access_control.en.rst):
Replaced the note stating scope is "ignored by the current version of the plugin" with full documentation of the matching semantics, segment boundary rules, and status code behavior.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
The new enforcement branch is only exercised through direct validateScope() unit calls; the existing access-control AuTest does not send a scoped token through enforceAccessControl() or verify the configured out-of-scope status and subject-header suppression. Add an integration case for an in-scope and out-of-scope request so this transaction-level plumbing is protected.
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
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