Skip to content

7.0.0

Latest

Choose a tag to compare

@github-actions github-actions released this 29 Sep 09:00
8e34429
  • PHP 8.4+ is now required.
  • (ADD) Built-in OAuth 2.0 support. A new Aura\Auth\Adapter\OAuth2Adapter runs the authorization-code exchange and maps the resource owner to [$username, $userdata] via a configurable username_field or map callback. Providers are reached through a small Aura\Auth\OAuth\ProviderInterface seam (with a LeagueProvider wrapper for league/oauth2-client, kept as a suggest/require-dev dependency so the core stays dependency-light). A new Aura\Auth\OAuth\AuthorizationCodeFlow drives the flow securely: it generates and persists the anti-CSRF state and a PKCE code_verifier when supported, and handleCallback() handles provider errors, validates state in constant time (consuming it), and returns only the validated code/code_verifier to pass to login() — never raw $_GET. Build with AuthFactory::newOAuth2Adapter() and AuthFactory::newOAuth2Flow(). See docs/oauth.md.
  • (ADD) "Remember me" support (issue #4). A new Aura\Auth\Remember\RememberService issues, resumes, and forgets long-lived login tokens using the split-token (selector/validator) scheme with server-side storage and per-use token rotation. Storage is pluggable via RememberStorageInterface, with a PDO-backed PdoRememberStorage provided. A new Status::REMEMBERED (and Auth::isRemembered()) marks users re-authenticated from a cookie as lower privilege than credentialed (VALID) users. The LoginService, LogoutService, and ResumeService accept an optional RememberService so the feature works through existing call sites; the added constructor parameters are nullable and backward compatible. Build the pieces with AuthFactory::newRememberService() and AuthFactory::newPdoRememberStorage(). See the README "Remember Me" section.
  • (ADD) LDAP "bind, search, rebind" support (issue #45). Aura\Auth\Adapter\LdapAdapter accepts an optional search configuration (binddn, bindpw, basedn, filter, and optional attributes); when given, it binds with a service account, searches for the user's real DN — which may live anywhere in the tree, so users spread across multiple OUs are now supported — then rebinds as that DN to verify the password, returning the discovered attributes. Without search it behaves exactly as before (direct bind via dnformat), so the change is backward compatible. A failed search operation raises the new Aura\Auth\Exception\SearchFailed, kept distinct from a successful zero-result search (UsernameNotFound). Configure via AuthFactory::newLdapAdapter(). A real-OpenLDAP integration test suite (opt-in via LDAP_TEST_URI) runs in CI. See docs/adapters.md.
  • (FIX) Aura\Auth\Verifier\PasswordVerifier now works with Argon2. It decided between password_verify() and hash() by testing is_string($algo) && $algo !== PASSWORD_BCRYPT, which was correct when the PASSWORD_* constants were integers; PHP 7.4 turned them into strings ("2y", "argon2i", "argon2id"), so every algorithm except bcrypt fell through to the hash() branch. As a result new PasswordVerifier(PASSWORD_ARGON2I) or PASSWORD_ARGON2ID raised ValueError: hash(): Argument #1 ($algo) must be a valid hashing algorithm on every login attempt, making Argon2 unusable through this class. The check is now ! in_array($algo, password_algos(), true), which keeps every algorithm password_hash() supports — including ones added in future PHP releases — on the password_verify() path. No working configuration changes behaviour, since the affected ones could not authenticate at all.
  • (CHG) PasswordVerifier configured with a hash() algorithm now reads password_hash() output as well, deciding from the stored value rather than from its own configuration. This is what makes migrating a legacy column safe: accounts move to the new algorithm one at a time as their owners log in, so the column holds both kinds of hash throughout, and a verifier that only understood its configured algorithm would reject every account the moment it was migrated — locking each user out on their next visit. needsRehash() correspondingly reports false for a value that has already been migrated, so a migrated row is not rewritten on every login.
  • (ADD) Password rehashing support. A new Aura\Auth\Verifier\RehashInterface (implemented by PasswordVerifier) reports when a stored hash should be replaced, and PdoAdapter/HtpasswdAdapter expose the result of the login that just succeeded via needsRehash() — the one moment the plaintext is available to produce a replacement. PasswordVerifier takes an optional second constructor argument of password_hash() options, so a raised bcrypt cost is detected as well as a changed algorithm; a legacy hash() digest always reports true, so migrating off one is self-driving. RehashInterface is deliberately separate from VerifierInterface, and needsRehash() is deliberately absent from AdapterInterface, so existing implementations of both are unaffected; ThrottleAdapter forwards the report to the adapter it wraps. See "Rehashing Stored Passwords" in docs/adapters.md.
  • (ADD) Automatic password rehashing. Passing an implementation of the new Aura\Auth\Rehash\RehashStorageInterface to an adapter's setRehashStorage() makes it replace an outdated hash during a successful login, instead of reporting the condition through needsRehash() and leaving the application to act on it — which silently migrates nothing if the check is forgotten or missed on one login path. A PDO-backed Aura\Auth\Rehash\PdoRehashStorage covers a single accounts table (build it with AuthFactory::newPdoRehashStorage()); anything more involved implements the one-method interface. The target algorithm belongs to the writer rather than the verifier, which is what allows a legacy column to migrate: the verifier reads MD5 while the writer stores bcrypt. A failed rehash never fails the login — it is housekeeping, so the exception is captured and exposed through getRehashError() for logging rather than propagated, and needsRehash() stays true so a manual block still sees the outstanding work. See "Rehashing Automatically" in docs/adapters.md.
  • (FIX) Close a username-enumeration timing leak in PdoAdapter and HtpasswdAdapter. Both threw UsernameNotFound before any password verification ran, so an unknown username returned in about a millisecond while a known one paid a full bcrypt verification — a difference readable straight through internet jitter, letting an attacker harvest valid usernames with a junk password and a stopwatch. Both adapters now run a throwaway verification against a dummy hash on the not-found path before throwing the same exception as before, measured at 1.00x where it had been 3.98x. The dummy hashes are public constants on AbstractAdapter and matched to PHP's default bcrypt cost (which changed from 10 to 12 in PHP 8.4); getDummyHash() can be overridden by deployments that set cost explicitly. The protection does not depend on the constants being secret — it removes the timing signal rather than hiding it. See docs/security.md.
  • (ADD) Format-matched dummy hashes, via a new Aura\Auth\Verifier\DummyHashInterface. The enumeration fix above verifies against a bcrypt dummy from AbstractAdapter, which equalises the two login paths only when the stored hashes are bcrypt too. In front of a legacy hash() column or an htpasswd file of $apr1$/{SHA} entries — all verified in microseconds — it did not close the gap but inverted and widened it, taking the unknown-username path from 0.0002ms to 261ms against a 0.0002ms wrong-password path: a cleaner signal for an attacker than the original bug, pointing the other way. Only the verifier knows which format it reads, so the verifier now supplies the dummy. PasswordVerifier builds one from its configured algorithm and options, so pinning array('cost' => 13) pins the dummy too; HtpasswdVerifier builds one from a format named in its new optional constructor argument (apr1 by default, what plain htpasswd writes), plus an optional second argument of password_hash() options for the bcrypt case — $2y$ encodes its cost, and htpasswd -B writes cost 5 by default where PHP writes 10 or 12, so array('cost' => 5) is what keeps that file's two paths level. Those arguments affect nothing but the dummy — verify() still dispatches per entry, so mixed-format files still authenticate everyone. Each dummy is generated from random_bytes() and memoised, so nothing verifies against it and the failure path pays for one verification rather than two. DummyHashInterface is optional and checked with instanceof, so third-party verifiers keep the previous behaviour and AbstractAdapter::getDummyHash() remains as their fallback. Each configured format now measures at a ratio of about 1; a file mixing formats can only be matched to the one the bulk of it holds, so a residue remains there. See docs/security.md.
  • (DOC) Document the enumeration timing gap the library does not close, in docs/security.md. The page described the throwaway verification in PdoAdapter and HtpasswdAdapter without mentioning the network adapters at all, which invited the assumption that every adapter was covered. LdapAdapter in bind-search-rebind mode still answers an unknown username a round trip faster than a wrong password, because a search matching nothing throws before the rebind ever happens; its direct-bind mode has no such gap, and ImapAdapter draws no distinction of its own. The note explains why a throwaway bind is not the fix — it would send the submitted password to the directory under a nonexistent DN and write a failed-bind record to its audit log on every unknown username, which is what intruder detection and lockout policy are usually driven by — and points at direct bind and at throttling instead.
  • (FIX) NativeRedisClient no longer reports a failed Redis read as a failure count of zero. hashGetAll() folded any non-array reply into an empty array, which RedisThrottleStorage::getFailures() reads as "no failures recorded" — so a key that could not be read silently switched throttling off for that account, and stayed off, because the matching hincrby/hset writes were dropped just as quietly. Commands whose failure is reported by return value rather than by exception now raise Exception\ConnectionFailed, which fails closed: ThrottleService::assert() runs before the wrapped adapter, so a broken backend blocks attempts instead of waving them through, matching PdoThrottleStorage, which already lets PDO's exceptions propagate. This is narrower than it sounds — phpredis throws of its own accord when the connection is refused or drops, so an unreachable Redis already failed closed; what is covered is chiefly WRONGTYPE, when another application shares the database and puts a non-hash under the throttle prefix. The guard tests for an exact false: HSET and DEL answer 0 on ordinary outcomes and EXPIRE answers false for a key that no longer exists, so a looser check would throw on healthy traffic; expire() and delete() stay unchecked for that reason, and a dropped delete() errs safe anyway by leaving the counter in place.
  • (FIX) HtpasswdVerifier's APR1/MD5 computation is now reachable as computeApr1(), split out of apr1() so a dummy in that format can be generated. PHP's crypt() has no $apr1$ support — it answers *0 — so the package's own implementation is the only source of a valid one; a *0 would have fallen through verify() to the DES branch and cost the wrong amount while still looking plausible. Verification behaviour is unchanged, and is now checked against real htpasswd -m output.
  • (FIX) Compare hashes with hash_equals() rather than === in PasswordVerifier (the hash() algorithm path) and in HtpasswdVerifier's SHA, APR1/MD5, and DES paths, so comparison time no longer depends on how many leading characters matched. The original code predates hash_equals(), which arrived in PHP 5.6 — after this code was written against a php >=5.4.0 requirement.
  • (ADD) Depend on the new aura/session-interface (^7.0) package, which provides the shared session/segment contracts.
  • (CHG) AuthFactory, Auth, and the LoginService/LogoutService/ResumeService now type-hint the shared Aura\Session_Interface\SessionInterface and SegmentInterface. As a result an Aura\Session\Session and its segments — or any other implementation of the shared contracts — can now be passed to Aura.Auth directly, while the built-in light Session/Segment continue to work standalone.
  • (CHG) Aura\Auth\Session\SessionInterface and Aura\Auth\Session\SegmentInterface are deprecated. They now simply extend the shared interfaces and are retained only for backward compatibility; type-hint the Aura\Session_Interface versions instead.
  • (CHG) Add native string/mixed/bool/void type declarations to Session, Segment, NullSession, and NullSegment to match the shared interfaces.
  • (CHG) Use explicit nullable types (?Type) for parameters that default to null in AuthFactory and ImapAdapter, fixing the PHP 8.4 implicit-nullable deprecation.
  • (TST) Update test doubles and test classes for PHP 8.2 (declared properties instead of dynamic ones).
  • (TST) Require phpunit/phpunit ^11.0 and modernize the suite for it: mock proxied Phpfunc functions via real test doubles with onlyMethods() (replacing the removed addMethods()), use willReturn() instead of will($this->returnValue()), and migrate doc-comment metadata (@runInSeparateProcess, @runTestsInSeparateProcesses, @preserveGlobalState) to PHP attributes. The CI matrix now targets PHP 8.4/8.5.
  • (CHG) Remove Psalm: drop the vimeo/psalm dev dependency, the psalm.xml config, and the Psalm CI job.
  • (CHG) Document that passing a hash() algorithm name to PasswordVerifier (new PasswordVerifier('md5')) compares an unsalted digest with no work factor, and exists only so a site with a legacy password column can authenticate users while migrating them. docs/adapters.md gained the warning and a migration recipe, and a stale reference to HashVerifier was corrected — that class was merged into PasswordVerifier in 2014. A new docs/security.md collects the account-enumeration and password-storage notes, including the part the application owns: adapters throw distinct UsernameNotFound and PasswordIncorrect exceptions for logging, and rendering them as different messages hands an attacker what the timing fix protects.
  • (ADD) A docs/schemas.md reference with CREATE TABLE statements for SQLite, MySQL/MariaDB, and PostgreSQL covering the aura_auth_remember, aura_auth_token, and aura_auth_throttle tables, plus an example accounts table. The page publishes the same .sql files the new PDO integration job executes, so the documented schema is one that is tested rather than one written from memory; a test fails if the two drift apart. Previously the only per-engine guidance was a parenthetical in a class docblock.
  • (TST) Real MySQL and PostgreSQL integration tests. A new opt-in suite (--group pdo, skipped unless PDO_TEST_DSN is set) exercises PdoAdapter and the PDO-backed remember-me, token, throttle, and rehash storages against real servers, run in CI against MySQL 8.0 and PostgreSQL 16 via service containers. SQLite hides portability problems — it has dynamic typing, no strict mode, and its own string-comparison rules — so anything depending on the server was previously untested. One case is called out explicitly: MySQL's default collation is case-insensitive and its VARCHAR comparison ignores trailing spaces, so ALICE and alice both match a stored alice there while PostgreSQL matches neither; the adapter must return the stored username either way, or session identity varies by how the user typed their name and anything keyed on it splits in two.
  • (TST) PdoAdapterTest fixtures now use bcrypt (at cost 4, bcrypt's minimum, to keep the suite fast) instead of MD5, so the most-read usage example no longer models a configuration the docs warn against; dedicated tests keep the legacy hash() path covered.