Document that SciToken/Validator/Enforcer handles are not thread-safe#218
Open
djw8605 wants to merge 1 commit into
Open
Document that SciToken/Validator/Enforcer handles are not thread-safe#218djw8605 wants to merge 1 commit into
djw8605 wants to merge 1 commit into
Conversation
Validation mutates state on the Validator (detected token profile) and Enforcer (test path, test authorization, generated ACL list -- written by scope_validator during verification). Two threads sharing one Enforcer can therefore race and have one thread's authorization test evaluated against the other thread's requested path, i.e. return a wrong authorization decision, not merely crash. Nothing in the public header said so; make the per-handle thread-safety contract explicit, along with the guarantee that distinct handles are safe to use concurrently (the shared key cache, configuration, and monitoring state are internally synchronized). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
Nothing in the public header states the thread-safety contract of the API handles — and it matters more than usual here:
Validatormutates internal state during verification (m_profile, the detected token profile).Enforcerstores the request being evaluated inside the handle:enforcer_test/enforcer_generate_aclswritem_test_path/m_test_authz/m_gen_acls, and thescope_validatorcallback reads them back mid-verification.Two threads sharing one
Enforcercan therefore race so that thread A's authorization test is evaluated against thread B's requested path — a wrong authorization decision, not merely a crash. Given the library's consumers are heavily threaded (XRootD et al.), this deserves an explicit statement.Change
Documentation only, in
scitokens.h:validator_createandenforcer_create, with the enforcer note explaining why (request state lives in the handle).Making the
Enforceractually thread-safe (moving per-request state into the async status / stack) would be a larger behavioral change, best done separately if desired.Testing
🤖 Generated with Claude Code