Skip to content

Absorb auth package - #13

Merged
ChiragAgg5k merged 84 commits into
mainfrom
absorb-auth
Jun 20, 2026
Merged

Absorb auth package#13
ChiragAgg5k merged 84 commits into
mainfrom
absorb-auth

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

  • absorb utopia-php/auth into packages/auth with history
  • strip package-local QA tooling in favor of monorepo tooling
  • add mirror redirect workflow, update package CI, and refresh the dependency graph
  • update PHPUnit config/data provider usage for the monorepo PHPUnit 12 toolchain

Testing

  • bin/monorepo check auth --fix
  • bin/monorepo test auth
  • bin/monorepo validate
  • bin/monorepo split auth --dry-run

Notes

  • No related issue found; leaving issue reference as #XXXX.
  • GitHub ruleset creation for the auth mirror returned 404 locally, so mirror branch protection still needs to be created manually or with an account/app token that has access.

eldadfux and others added 30 commits March 8, 2025 09:23
Co-authored-by: Matej Bačo <matejbaco2000@gmail.com>
Co-authored-by: Matej Bačo <matejbaco2000@gmail.com>
Co-authored-by: Matej Bačo <matejbaco2000@gmail.com>
- Set default algorithm in Password class when initializing
- Update tests to use new algorithm methods and default settings
- Modify token generation to explicitly set SHA algorithm
- Adjust test assertions to match new default hashing methods
- Update Proof classes to generate random values without input parameter
- Add password generation with configurable length and charset
- Modify README.md with comprehensive usage examples for different proof types
- Update tests to reflect new generation and configuration methods
- Improve code flexibility and security for authentication proofs
Move common hash and verify implementations from individual Proof subclasses to the abstract Proof base class, reducing code duplication and simplifying the class hierarchy
Introduce a new section demonstrating the usage of the Utopia\Auth\Store class, showcasing key features like setting, getting, encoding, and decoding data with practical code examples
@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR absorbs the utopia-php/auth package into packages/auth within the monorepo, bringing in the full source history, stripping package-local QA tooling, and wiring up the monorepo CI, mirror-redirect workflow, and PHPUnit 12 compatibility.

  • Hash implementations (Argon2, Bcrypt, MD5, SHA, PHPass, Scrypt, ScryptModified) and issuer implementations (Asymmetric RS256, Symmetric HS256) for JWT access tokens, id_tokens, and refresh tokens are all absorbed as-is from the upstream package.
  • Two issues carried in from the original package warrant attention before this code sees wider use: the PHPass.getRandomBytes() fallback writes its updated state to a local copy so the chain is broken on PHP environments where /dev/urandom is unavailable, and both Scrypt and ScryptModified generate a random salt per instance but do not embed it in the hash output, so verify() silently returns false against a previously stored hash unless the original salt is separately persisted and restored.

Confidence Score: 3/5

The JWT issuers and most hash classes are solid, but the Scrypt salt-not-embedded issue will cause verify() to silently return false in any stateless (new-instance-per-request) verification flow, and the PHPass randomness fallback is both insecure and broken.

The Scrypt/ScryptModified verify() path silently fails across request boundaries because the random salt generated at construction is never embedded in the hash output — a new instance created for login will always return false against a registration-time hash. PHPass's getRandomBytes() fallback updates a local copy of the options map, so its internal state chain is never actually advanced; on environments without /dev/urandom the salt reduces to a predictable MD5(microtime) chain. Both issues were present in the absorbed upstream package but are real defects that affect correctness and security.

packages/auth/src/Auth/Hashes/Scrypt.php, packages/auth/src/Auth/Hashes/ScryptModified.php, and packages/auth/src/Auth/Hashes/PHPass.php need the most attention before this code is used in a stateless production context.

Important Files Changed

Filename Overview
packages/auth/src/Auth/Hashes/PHPass.php PHPass hash implementation — contains a broken randomness fallback whose state update writes to a local copy instead of the instance, and the MD5(microtime) chain is predictable; on PHP 8+ random_bytes() should replace getRandomBytes() entirely.
packages/auth/src/Auth/Hashes/Scrypt.php Scrypt hash — generates a random salt per instance but does not embed it in the hash output; verify() will always fail when called on a new instance, requiring callers to separately persist and restore the salt.
packages/auth/src/Auth/Hashes/ScryptModified.php ScryptModified hash — same salt-not-in-output issue as Scrypt; uses AES-256-CTR with zero IV (acceptable here since the key is unique per password), and uses hash_equals for timing-safe comparison.
packages/auth/src/Auth/Issuers/Asymmetric.php RS256 asymmetric issuer base class — clean RSA key-pair handling, deterministic kid derivation from public modulus, correct JWK export.
packages/auth/src/Auth/Issuers/Asymmetric/AccessToken.php RFC 9068 access-token issuer — proper at+jwt header type, scope injection guard via unset+merge pattern, audience and list-shape validations look correct.
packages/auth/src/Auth/Issuers/Asymmetric/IdToken.php OIDC id_token issuer — at_hash/c_hash/nonce injection guards correct; leftHalfHash uses SHA-256 + left 16 bytes per OIDC §3.1.3.6 for RS256.
packages/auth/src/Auth/Issuers/Symmetric/RefreshToken.php HS256 refresh-token issuer — scope injection guard correct, jti auto-generated, standard claims assembled properly.
packages/auth/src/Auth/OAuth2/ResourceIndicators.php RFC 8707 resource indicators — isValid() now correctly restricts to http/https with a required host and no fragment; duplicate and ordering logic looks correct.
packages/auth/src/Auth/Proofs/Password.php Password proof factory — createHash() passes arbitrary $options to setOptions(), enabling callers to restore a saved salt for Scrypt; password generation uses random_int() from the charset correctly.
packages/auth/.github/workflows/mirror.yml Mirror-redirect workflow — uses pull_request_target but does not check out PR code, limiting the attack surface; only comments and closes the PR using the default github.token.
packages/auth/src/Auth/Store.php Simple key-value store with base64+JSON encode/decode — handles invalid JSON gracefully, no issues found.
packages/auth/composer.json Package manifest — declares php>=8.0 requirement and all necessary extensions (hash, openssl, scrypt, sodium).

Reviews (3): Last reviewed commit: "Merge origin/main into absorb-auth" | Re-trigger Greptile

Comment thread packages/auth/src/Auth/Hashes/Scrypt.php Outdated
Comment thread packages/auth/src/Auth/Hashes/Scrypt.php Outdated
Comment thread packages/auth/src/Auth/OAuth2/ResourceIndicators.php
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved. I merged origin/main into this branch and fixed the conflict in README.md in commit 8aacafb3.

@ChiragAgg5k
ChiragAgg5k merged commit f038860 into main Jun 20, 2026
4 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the absorb-auth branch June 20, 2026 03:28
loks0n added a commit that referenced this pull request Jun 20, 2026
Restores the git-subtree annotation dropped when #13 was squash-merged, so
splits fast-forward onto the published mirror (0.6.0) instead of synthesizing
a divergent root.

git-subtree-dir: packages/auth
git-subtree-mainline: 3e145bb
git-subtree-split: 76bd615

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
loks0n added a commit that referenced this pull request Jun 20, 2026
The squash-merge of #13 discarded auth's imported history, leaving the package
unreachable from its published mirror (0.6.0 = 76bd615). This -s ours merge
records the mirror head as a second parent so its objects are present and
reachable — the state a non-squashed import would have left — while keeping the
current monorepo-ified tree. The subtree annotation lets `split` fast-forward
onto the mirror instead of synthesizing a divergent root.

git-subtree-dir: packages/auth
git-subtree-mainline: 3e145bb
git-subtree-split: 76bd615

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants