PR-A: token core (api_tokens, registry, generator)#1
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <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.
PR-A — token core
Implements the database-backed API token core for the package, per the locked design (scratchpad #53).
What shipped (vs plan)
api_tokensmigration (uuid pk,name, uniquetoken_hash,last_used_at,request_count,expires_at,revoked_at, timestamps)ApiTokenmodel (HasUuids, casts,scopeResolvable, factory)TokenGenerator+GeneratedTokenvalue object — plaintext = configured prefix +bin2hex(random_bytes(32)), hash = sha256TokenRegistry:resolve()(empty → null; constant-time fallback; hashed DB lookup gated solely byexpires_at; atomic usage bump),store()(reserved-name + sha256-format guarded),rotate()(1h grace default / immediate on emergency; never setsrevoked_at),revoke()(sets bothexpires_atandrevoked_at)Deserves attention
expires_atis the sole resolution gate;revoked_atis informational only (locked by a dedicated test: a row withrevoked_atset but unexpired still resolves).request_count + 1update (no read-modify-write race).store()enforces a 64-char lowercase hex hash, upholding the "only sha256 is ever stored, never plaintext" invariant.Findings disposition
request_countread-modify-write race (fixed, atomic increment) plus advisories; hardening pass also addedstore()hash validation and 4 tests (revoked_at-alone resolves, empty-string fallback disabled, non-hash rejected, rotation doesn't mutate the new row's expiry).ApiToken::$fillable— the model is only filled via the registry/factory with controlled arrays, never request input.Gate evidence
composer lint:test(pint) → passedcomposer stan(phpstan level 6) → no errorscomposer test(pest) → 21 passed (40 assertions)Risk / next
Low risk; pure additive package code. Next: PR-B (CloudCommandRunner + UsageReporter contract +
token:*/fallback-token:generatecommands), then tagv0.1.0.