Repository navigation
Description
👟 Reproduction steps
- Varchar column
secretwithencrypt: true(size 200). - Create a row with
secret = "banana". PATCH /v1/tablesdb/{db}/tables/{table}/rows/{rowId}with{"data": {"secret": "{\"method\":\"stringReplace\",\"values\":[\"a\",\"o\"]}"}}.- Read the row.
👍 Expected behavior
Either secret = "bonono", or 400 because string operators are not supported on encrypted columns.
👎 Actual Behavior
200, and from now on the row returns "secret": false. The value is lost.
The operator runs as SQL REPLACE() on the stored ciphertext envelope, not on the plaintext. The raw value in Postgres afterwards:
before: {"data":"vxy1Q8Nn","method":"aes-128-gcm","iv":"3728…","tag":"c7d8…","version":"1"}
after stringReplace("a","Q"): {"dQtQ":"vxy1Q8Nn","method":"Qes-128-gcm","iv":"3728…","tQg":"c7d8…","version":"1"}
after stringReplace("a",""): {"dt":"7NtsuRXr","method":"es-128-gcm","iv":"6d976f9880f46c4c5e1f7","tg":"4162d03b…","version":"1"}
The JSON keys contain a, so any replacement of a destroys the envelope, even when the plaintext does not contain the search string ("secret" → false). Replacing characters that occur in the hex IV/tag (a–f, digits) is irreversible. stringConcat on the same column returns 500 and leaves the value unchanged; a search string that does not occur in the envelope ("zz") leaves the value intact. The same happens when the operator is staged in a transaction (commit 200) and with updateRows (two runs each, plus both matrix runs). A plain updateRow with a new value works as expected.
Cause: the operator validator (Validator/Operator.php L446–L458) only checks that the column is a string type; it does not know about the encrypt filter. The Postgres adapter then builds col = REPLACE(COALESCE(col, ''), :search, :replace) (Adapter/Postgres.php L2718–L2721) on the encrypted JSON produced by the encrypt filter (app/init/database/filters.php L277), and on read the filter's decryption fails and yields false. Any client or server user with update permission on the row can trigger this.
🎲 Appwrite version
2.3.0 (utopia-php/database 7.3.11)
💻 Operating system
Linux (Debian 12), Docker
🧱 Your Environment
Self-hosted Appwrite 2.3.0, Postgres adapter (PostgreSQL 18).
💡 Suggested fix
Reject operators (at least stringConcat/stringReplace) on attributes with the encrypt filter with a 400, or apply them in PHP after decryption and re-encrypt.
👀 Have you spent some time to check if this issue has been raised before?
- I checked and didn't find a similar issue
🏢 Have you read the Code of Conduct?
- I have read the Code of Conduct
Activity