Skip to content

Encrypted and length-limited attributes return 500 instead of 400 (webhooks authPassword/authUsername/url, variables value) #14293

Closed

Description

@ChiragAgg5k

Summary

Several endpoints accept values that their database columns can't hold. The request validator passes, createDocument/updateDocument throws Utopia\Database\Exception\Structure, nothing maps that exception, and the client gets a 500 general_unknown instead of a 400.

Two causes:

  1. Encrypted columns are sized for the plaintext. The encrypt filter (app/init/database/filters.php:277-289) stores a JSON wrapper, {"data":<base64 ciphertext>,"method":"aes-128-gcm","iv":<24 hex>,"tag":<32 hex>,"version":"1"}. That adds 121 characters plus about 33% for base64, and json_encode escapes every / in the base64 as \/, so the stored length also varies randomly from one save to the next.
  2. Validators allow more than the column holds, or set no length limit at all.

Reproduced on production

On Cloud (fra), 2026-10-09 10:13 UTC, using the Appwrite CLI against a test project. Every request returned 500 general_unknown and nothing was saved. All events are grouped under CLOUD-3R1X.

Request Validator Column Sentry event
POST /v1/webhooks with a 120-char authPassword PasswordFormat(Text(256)) httpPass: 255, encrypt httpPass
POST /v1/webhooks with a 256-char authUsername Text(256) httpUser: 255 httpUser
POST /v1/webhooks with a 270-char url Multiple([URL, PublicDomain]), no length limit url: 255 url
POST /v1/sites/:siteId/variables with a long value (seen in production, 27 events up to 2026-10-04) Text(8192) value: 8192, encrypt value
appwrite webhooks create --webhook-id repro --name repro --url https://example.com/hook \
  --events 'users.*.create' --auth-username mcp --auth-password "$(python3 -c "print('p'*120)")"
# → {"message":"Server Error","code":500,"type":"general_unknown"}

Webhook authPassword: the real limit is about 99, not 256

Password length Base64 length Stored length (column holds 255)
96 128 249, plus 2 per escaped /
99 132 253
100 136 257 ❌
256 (documented max) 344 465 ❌

Escaped slashes mean passwords of about 90–99 characters fail at random, depending on the IV. No length under 255 is guaranteed to fit. There's a // TODO will the length suffice after encryption? on httpPass in app/config/collections/platform.php.

Variables value

Function and site variables have the same problem: Text(8192) against an encrypted 8192-character column (Functions/Http/Variables/{Create,Update}.php:63-64, Sites/Http/Variables/{Create,Update}.php:63-64, column in app/config/collections/common.php). A value of about 6000 characters or more overflows once encrypted.

Proposed fix

  1. Size encrypted columns for the ciphertext, not the plaintext. Make httpPass and the variables value column VAR_TEXT with size 65535, as the VCS token columns already are (998e7a1). Add a migration step for existing columns. Do the same for any other encrypt column whose validator allows more than about (size - 121) * 3/4 / 2 characters.
  2. Match validators to their columns. authUsername → Text(255); url → add Text(255) to its Multiple validator; update the Max length wording in the parameter docs and the SDK specs.
  3. Safety net: map Utopia\Database\Exception\Structure to DOCUMENT_INVALID_STRUCTURE (400) in the general error handler, so any remaining mismatch becomes a 400 instead of a 500. CLOUD-3R1X shows this already happens across more than one endpoint.
  4. Regression tests: extend the existing webhooks and variables e2e tests:
    • a 256-character authPassword succeeds and is delivered intact
    • 256-character authUsername and url return 400
    • an 8192-character variable value succeeds

Context

Found while building MCP Events for the hosted MCP server (appwrite/mcp#127). It stores a sealed subscription envelope in the webhook's authPassword. With the current limit, that envelope has to be split across three fields.


2026-10-12: Merged PR #14356 — sized webhooks.httpPass to VAR_TEXT, raised authPassword to 2048, mapped Structure → 400, and stabilized encrypt JSON. Remaining encrypted columns (variables value, etc.) still open here.

2026-10-12: Opened Cloud PR appwrite-labs/cloud#6481, bumping appwrite/server-ce to ship #14356 on Cloud, after appwrite-labs/cloud#6474 converted httpPass to text in production.

Activity

  1. added
    product / auth
    product / databases
    product / migrations
    product / sites
    sdk / cli
    on Oct 9, 2026
  2. ChiragAgg5k commented on Oct 9, 2026

    @ChiragAgg5k
    MemberAuthor

    Scoping note from the MCP side (appwrite/mcp#127, envelope in appwrite/mcp#132): widening the httpPass column alone isn't enough. The authPassword request validator on webhook create/update is PasswordFormat(Text(256)), and the values we need to store are larger than 256 characters before encryption:

    Case Plaintext authPassword length
    Typical (79-char callback URL, one secret) 433
    Secret rotation (150-char URL, two secrets) 717
    Worst case (300-char URL, two 64-byte secrets) 1,034

    So the fix needs both:

    1. httpPass column → VAR_TEXT (65535), as in the issue, so the encrypted value always fits.
    2. authPassword validator on POST /v1/webhooks and PUT /v1/webhooks/:webhookId → at least Text(2048) (and the "Max length" wording in the param docs/SDK specs).

    The same applies to the variables value param if its column moves to VAR_TEXT: the validator and the column should agree on the plaintext limit.

  3. JoshiJoshiJoshi commented on Oct 11, 2026

    @JoshiJoshiJoshi

    The same wrapper overhead also limits user columns with encrypt: true in TablesDB. There it surfaces as a 400 with a misleading message instead of a 500, because the structure validator checks the length of the encrypted JSON wrapper instead of the plaintext.

    Measured on self-hosted 2.4.0 (Postgres), binary search per column, two runs:

    Column Accepted plaintext (ASCII) Accepted plaintext (ä)
    varchar(150), encrypt (the minimum size for encryption) 21 9–10
    varchar(300), encrypt 130–132 64–66
    varchar(1000), encrypt 646–647 324–325
    text, encrypt ≈ 48,000 –

    Writing exactly 150 characters into the varchar(150) column fails with Attribute "e" has invalid type. Value must be a valid string and no longer than 150 chars. createRow, upsertRow, createRows, updateRows and transactions behave the same. Usable length ≈ (size − 122) × ¾ for ASCII and half of that for multi-byte text.

    Sizing the stored column for the wrapper (or validating the plaintext against size and the wrapper against the column) would fix both cases.

  4. self-assigned this
    on Oct 12, 2026
  5. ChiragAgg5k commented on Oct 14, 2026

    @ChiragAgg5k
    MemberAuthor

    Released in Appwrite 2.5.0 (includes #14356).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

product / authproduct / databasesproduct / migrationsproduct / sitessdk / cli

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions