Repository navigation
fix(auth): refuse unreadable HIBP ranges, cache empty HIBP ranges and JWKS key sets - #15705
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
This PR only adds two unit tests; no library behavior changes. Both tests were verified against their subjects (
Reviewed commit: 2727e7a |
🟢 Tier S · Ready to mergeHIBP now rejects responses with no recognized hash suffix entries as unavailable. Its tests cover valid padded ranges plus retrying after empty or HTML responses. The JWKS test verifies that an empty set is cached during the refresh cooldown and that a newly published key is picked up after the cooldown expires. Latest changes: The newest commits add HIBP response sanity checks and update the HIBP fixtures and tests to distinguish valid padded empty ranges from unreadable responses that must be retried.
📂 Walkthrough · 3
🔇 Filtered out · 1Findings Hansi considered but did not post.
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@Luxor-Code-Review Fixed in 6ca61e6.
It still fails on main's cache ( |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
|
@appwrite review |
|
@tenki-reviewer review |
|
Review complete. No blocking issues — approved ✅; 1 nitpick below. 🧹 Nitpicks (1) — 🟢 1 low
The PR introduces unit coverage for two caching hot paths in authentication: the OIDC JWKS key-set fetch (cooldown, forced refetch, failure fallback) and the HIBP pwned-password range lookup (cache hits, expiry, empty-range handling). Tests use named fakes and avoid network calls.
Reviewed commit: 6ca61e6 |
Superseded by a newer Luxor approval on this pull request.
|
@Luxor-Code-Review Thanks. Keeping this step as is:
Ageing every entry moves time forward for the whole cache without naming any key, and the assertions are only on what's observable: the key returned and the fetch count. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…as no breaches Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@appwrite review |
|
@tenki-reviewer review |
|
A review of f1e52d2 is already running, so I didn't start another one. |
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
This PR makes the Pwned-Passwords range lookup fail closed when the HIBP range response cannot be read, instead of treating it as a no-breaches answer, and strengthens the unit suite around that behavior and the OIDC JWKS cache.
Reviewed commit: f1e52d2 |
There was a problem hiding this comment.
Hardens the HIBP password-breach validator to fail closed on unreadable range responses and adds unit coverage for that path plus JWKS cache behavior.
Key findings
- 🟡 Truncated 200 range body is cached as a clean range — HIBP.php:103
A newer Luxor review found issues on this pull request.
8263cc3
into
fix/cache-store-empty
Issue
Closes #15703. Stacked on #15704.
With #15704,
utopia-php/cachestores an empty array[]. Two callers here return[]for an empty answer, and until now they fetched it again on every request:PasswordPwned::remember(): a HIBP range with no breached hashes.Jwks::getKey(): a JWKS with no usable RSA keys.Caching
[]also made an existing gap inHIBPlast longer.HIBP::range()reads a 200 response line by line and keeps theSUFFIX:COUNTlines with a count above 0. A 200 with no such line at all (an empty body, an HTML error page) came back as[], which means "no breaches", so the password was accepted even though no lookup really happened. That contradicts the class contract inPasswordPwned: a password is never accepted when the lookup did not happen, and a nonsense answer throws. Before #15704 that[]was not cached, so it affected one request. With #15704 it would be cached forCACHE_TTL(one hour), and every password sharing that hash prefix would skip the check for that hour.Solution
HIBP::range()counts the entries it reads (lines with a separator and a hex suffix, whatever the count). If a 200 response has none, it throwsGENERAL_PWNED_PASSWORDS_UNAVAILABLE, like an unreachable service or a non-200 status, so nothing is cached and the next check asks again. A range of only padded entries (all count 0) is still valid and returns[]. The real service is asked withAdd-Padding: true, so a real answer always has hundreds of entries.PasswordPwned::remember()("A miss reads back as false, so an answer is always wrapped in an array") is still accurate, so it is unchanged.Tests
HIBPTest::testUnreadableRangeIsReportedAndNotCached(two cases: an empty body, an HTML page): a 200 without a single entry throwsGENERAL_PWNED_PASSWORDS_UNAVAILABLEon both of two checks, and both checks reach the service, so it is not cached.HIBPTest::testOnlyTheHashPrefixLeavesTheServerandtestLookupsGoToTheConfiguredEndpointused an empty body only to capture the request URL. They now get a padding-only range, so they keep testing the URL instead of tripping the new check.HIBPTest::testRangeWithNoBreachesIsCached: a range with only padding entries (no breaches) is fetched once for two checks of the same prefix, using a Memory cache.testFailedLookupIsNotCachedstill covers that errors are not cached.JwksTest::testEmptyKeySetIsCached: a JWKS with no keys is fetched once plus the one forced refetch for the unknownkid, and is cached as[]. A second lookup in the 60s cooldown fetches nothing. Once the cache entries are aged past the cooldown, an unknownkidforces one more refetch and picks up a newly published key. Caching is proven by counting fetches through the fake transport, without building the cache keys.Locally the app's PHPUnit bootstrap needs the
utopiaextension (it providesUtopia\Locale), so I ran these with--no-configuration --bootstrap vendor/autoload.php. The full unit suite runs in CI.Red: against the cache source of
origin/main(8e1e655)Green: on #15704
Red: the new HIBP tests before the fix
Appwrite\Extend\Exceptionreads theerrorsconfig, so for these I used a bootstrap that loadsvendor/autoload.phpand setsConfig::setParam('errors', include 'app/config/errors.php').Green: after the fix
JwksTestis unchanged and still passes (7 tests).composer lint, PHPStan and Rector (tests/tools/rector.php) pass on both changed files.New files, classes and tests
No new files or classes. New test methods:
testRangeWithNoBreachesIsCached,testEmptyKeySetIsCached,unreadableRanges(data provider) andtestUnreadableRangeIsReportedAndNotCached, each explained above.🤖 Generated with Claude Code