Repository navigation
fix(security): rate-limit guest transaction writes and compare MFA codes in constant time - #14762
Conversation
…des in constant time Guests hold documents.write, rows.write and the DocumentsDB/VectorsDB write scopes, so the transaction create/update/delete routes on every database API were reachable without an abuse limit while their operations sibling and the document/row routes were limited. They now use the same key and limits as those siblings. MFA challenge codes and TOTP values were compared with ===, whose running time depends on the matching prefix; hash_equals removes that signal. The Semgrep baseline drops the findings these resolve, plus a stale account entry that no longer matched.
|
Review complete. No issues found — approved ✅. This change wires Reviewed commit: d119963 |
🟢 Tier S · Ready to mergeTransaction create, update, and delete routes across Databases, TablesDB, DocumentsDB, and VectorsDB now apply guest abuse limits, and MFA challenge/TOTP code checks use constant-time comparisons. E2E abuse coverage and the Semgrep baseline were updated alongside those changes; the latest commit restores the OAuth2 callback finding to the baseline. Latest changes: The newest commit adds the OAuth2 POST callback finding back to the Semgrep baseline so the known finding remains matched.
📂 Walkthrough · 4
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
A local scan missed it, so the regenerated baseline dropped an entry that CI still reports. Only its line number moved.
…actions fix(security): rate-limit guest transaction writes and compare MFA codes in constant time (cherry picked from commit 4e5a556)
What
Resolves the open Semgrep code-scanning alerts for
guest-write-without-abuse-limit(Databases, DocumentsDB and VectorsDB transactions) andsecret-compare-timing(MFA challenges).Why
Guests hold
documents.write,rows.write,documentsdb.documents.writeandvectorsdb.documents.write(app/config/roles.php), soPOST/PATCH/DELETE /v1/{databases,tablesdb,documentsdb,vectorsdb}/transactions[/:transactionId]were callable by unauthenticated clients with no abuse limit. The shared api hook treats a missingabuse-limitas unlimited. Their siblingtransactions/:transactionId/operationsroute and the document/row write routes are already limited.The transaction routes now carry the same labels as those siblings: key
ip:{ip},method:{method},url:{url},userId:{userId},APP_LIMIT_WRITE_RATE_DEFAULT * 2for create/update andAPP_LIMIT_WRITE_RATE_DEFAULTfor delete, perAPP_LIMIT_WRITE_RATE_PERIOD_DEFAULT. TablesDB is included even though Semgrep did not flag it (its array scope label escapes the rule's pattern), since it is the same route behind the newer API name.MFA email/phone/custom codes and TOTP values were compared with
===, whose running time depends on how long the matching prefix is. They now usehash_equals; a missing or non-string stored code still fails verification.Baseline
.semgrep/baseline.jsonis regenerated withnode .semgrep/baseline.js updatefrom a Semgrep 1.179.0 scan. It drops the 13 entries this resolves. The OAuth2 callback entry inapp/controllers/api/account.phpstays, with its line number updated.Tests
tests/e2e/General/AbuseTest.phpgains create/update/delete transaction cases for all four APIs in theabuseEnabledgroup, using the existingassertGuestLimitedhelper: the request after the limit must return 429. The MFA change keeps verification behavior identical, which the existing Account MFA e2e tests cover; timing cannot be asserted in a test.Overlaps with #14320, which makes the same
hash_equalschange but rewrites the whole baseline file and has no rate-limit fix.Related: appwrite-labs/cloud#6666