Skip to content

feat: send the SHA-1 hash to the Appwrite Pwned service - #13805

Merged
Meldiron merged 2 commits into
mainfrom
feat-pwned-send-sha1-hash
Sep 21, 2026
Merged

Meldiron merged 2 commits into
mainfrom
feat-pwned-send-sha1-hash

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

What does this PR do?

Updates the appwrite:// password-pwned adapter to the interface Appwrite Pwned 0.4.0 ships.

POST /v1/detection no longer takes the password. It takes a hash parameter — the SHA-1 of the password as 40 hexadecimal characters (appwrite-labs/pwned#11). The adapter now hashes the password and sends only the hash, so the password itself never leaves the server, and the request body is no longer something that has to be kept out of a log.

  • Auth\Validator\PasswordPwned\Appwrite posts {"hash": "<40 hex chars>"} instead of {"password": "..."}.
  • The cache key is derived from the hash rather than the password. It is still an HMAC keyed with the shared secret, so the cache holds nothing crackable, and one answer per password is still cached.
  • Docblock and the _APP_PWNED_PASSWORDS_DSN description in app/config/variables.php say what now travels. The warning to keep the service on a network you control or behind TLS stays — a bare SHA-1 is unsalted, so an observer can still match a common password by its hash.

No behaviour changes for the other adapters: hibp:// already sent a hash prefix, and none:// and mock:// never leave the process. No API surface, model, or migration change.

This requires Appwrite Pwned 0.4.0 or newer. A server pointed at 0.3.x with an appwrite:// DSN gets a 400 for the unknown parameter, which the adapter surfaces as general_pwned_passwords_unavailable — passwords are never silently accepted. Operators using appwrite:// upgrade the service alongside this.

Test Plan

tests/unit/Auth/Validator/PasswordPwned/AppwriteTest.php updated for the new wire format:

  • testTheHashIsSentWithTheSharedSecretAsBearerToken asserts the body is exactly {"hash": strtoupper(sha1(password))} and that the plaintext password appears nowhere in it.
  • The 400 fixture in testServiceErrorsAreReported carries 0.4.0's error object for a rejected hash.
docker compose exec appwrite test tests/unit/Auth/Validator

61 tests, 204 assertions, green. composer lint clean on the three changed files.

tests/e2e/Services/Project/PoliciesPasswordPwnedIntegrationTest.php runs against mock://localhost and is untouched by this.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? — no API metadata changed; the only description touched is the _APP_PWNED_PASSWORDS_DSN environment variable.

🤖 Generated with Claude Code

Appwrite Pwned 0.4.0 takes the SHA-1 hash of the password on
POST /v1/detection instead of the password itself, as a `hash`
parameter of 40 hexadecimal characters.

The adapter now hashes the password and sends only the hash, so the
password never leaves the server. The cache key is derived from the
hash rather than the password; it is still an HMAC keyed with the
shared secret, so the cache holds nothing crackable.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge because the change since the previous review only makes an assertion’s input explicitly string-typed and introduces no new defect.

Summary

Updates the Appwrite Pwned adapter for the service’s hash-based request contract.

  • Computes and transmits the uppercase SHA-1 password hash instead of plaintext.
  • Derives the protected cache key from that hash.
  • Updates operator documentation and unit-test fixtures for Appwrite Pwned 0.4.0.
  • The only change since the previous review adds a safe string cast to a test assertion.

Reviews (2) · Last reviewed commit: "chore: cast the recorded request body be..."

Rector's dry-run over tests/ flags the mixed-typed body the fetch
adapter records, since assertStringNotContainsString takes a string.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat-pwned-send-sha1-hash (after).

Metric Before After Change
🚀 Requests/sec 206.1 204.49 ⚪ -0.8%
⏱️ Latency P50 85 ms 85.23 ms ⚪ +0.3%
⏱️ Latency P95 194.07 ms 199.07 ms ⚪ +2.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 85.23 199.07 12,597 204.49 +5
Account 170.65 309.06 663 10.99 +26.75
TablesDB 81.36 150.86 6,851 112.83 -2.05
Storage 80.36 171.82 3,315 56.73 -3.88
Functions 124.72 238.91 1,768 30.96 +12.87

Top API waits (after)

API request Max wait (ms)
account.name.update 461.69
account.prefs.update 407.74
functions.variables.delete 401.8
functions.variables.update 376.76
functions.create 348.07

@Meldiron
Meldiron merged commit 61a29e1 into main Sep 21, 2026
49 checks passed
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.

1 participant