Skip to content

fix(templates): store password-typed template variables as secrets (appwrite:appwrite:alert#4728) - #15477

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix-template-variable-secret
Nov 11, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix-template-variable-secret

Conversation

@claudear

Copy link
Copy Markdown
Contributor

What

Code-scanning alert #4728: credentials typed into the function/site template setup wizards were stored as non-secret variables, so GET /v1/functions/:functionId/variables (scope functions.read) and the sites equivalent returned them in clear text.

Three gaps composed:

  1. app/config/templates/function.php / site.php describe credential inputs only with 'type' => 'password' and never set secret, so Templates/Get.php → TemplateVariable filled it with its false default.
  2. Both wizards seeded each variable with secret: v.secret || false — always false.
  3. They then passed that explicit false to createVariable, so the route's secure default (->param('secret', true, ...)) never applied.

Variable::filter() blanks value only when secret === true, so any read-only API key, console member with read scope, or function runtime key with those scopes could read Redis/database passwords, third-party tokens and Stripe secret keys. The wizards also masked the input off the same never-true flag, so password fields were rendered as visible text during entry.

Fix

type === 'password' is now authoritative for secrecy end to end:

  • 'secret' => true on all 56 password-typed entries in the function catalog and all 3 in the site catalog, so new servers are explicit.
  • isTemplateVariableSecret() (apps/console/src/lib/template-variables.ts) treats a password input as secret, so a server that omits the flag still classifies correctly. Both wizards seed variables through it.
  • The Secret badge and the type='password' masking now follow the seeded flag instead of the raw catalog one, so password fields are masked during entry.

Non-credential template variables keep their explicit secret: false — their values stay readable in the console, as before.

Tests

Both tests fail on main and pass here.

  • tests/unit/General/TemplatesTest.php — every password-typed variable in both catalogs must be marked secret (59 entries today). Failed before the catalog change (query-upstash-vector: UPSTASH_TOKEN, : STRIPE_SECRET_KEY).
  • apps/console/tests/unit/template-variable-secret.test.ts — a password-typed variable is classified secret whether the server sends secret: false or omits it; text inputs stay readable.

Verified: full --testsuite unit (2592 tests, no failures; only the known environmental KeyTest/ListCacheTest errors), Pint, PHPStan and Rector on the changed PHP, bun test tests/unit and tsc --noEmit for the console.

Follow-up (not in this PR)

Variables already created through the template wizards remain non-secret. They should be audited and the stored credentials rotated — the fix only protects values entered from here on.

🤖 Generated with Claude Code

@luxor-code-review

luxor-code-review Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Heuristic fixes future creates only, not existing variables (template-variables.ts:13) — The isTemplateVariableSecret heuristic (apps/console/src/lib/template-variables.ts:13) and the catalog secret flags close the leak only at variable-creation time: the server masks values (src/Appwrite/Utopia/Response/Model/Variable.php:78) based solely on the persisted secret attribute, never on type.

This PR marks password-typed variables in the server-side template catalogs as secret so credential values are masked in the variables get/list routes, and wires the console template wizard to the resolved per-variable secret state with a type === 'password' fallback for older servers. Contract-lock tests were added in tests/unit and the console unit suite to pin every password-typed catalog entry to secret: true.

Files Change
app/config/templates/function.php, app/config/templates/site.php Add 'secret' => true to password-typed variables in both template catalogs
apps/console/src/lib/template-variables.ts New isTemplateVariableSecret() helper with a type === 'password' fallback for catalogs that omit the flag
apps/console/.../functions/create/TemplateConfigView.tsx, apps/console/.../sites/create/TemplateConfigView.tsx Drive the Secret label, password input, and createVariable call from the resolved per-variable secret state
tests/unit/General/TemplatesTest.php, apps/console/tests/unit/template-variable-secret.test.ts Contract tests asserting every password-typed catalog variable carries secret: true

All cross-file contracts checked out: the TemplateVariable response model already exposes secret and type, the catalogs are registered config keys, and the console heuristic matches the PHP contract lock exactly. One residual gap is tracked below: the fix applies at variable-creation time only, so credential variables created by the pre-fix wizard remain readable.

Reviewed commit: 0998fd9

@appwrite

appwrite Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

New Console

Project ID: new-console

Sites (1)
Site Status Logs Preview QR
 New Console
new-console
Ready Ready View Logs Preview URL QR Code

Tip

JWT tokens let functions act on behalf of users while preserving their permissions

@appwrite

appwrite Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The template catalogs now mark password-typed function and site variables as secret, and both setup wizards classify those variables as secret even when older servers omit the flag. The wizards use the resulting secret state for input masking and when creating variables. Added unit tests cover catalog markings and password-versus-text classification.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 7
File Change
app/config/templates/function.php Marks password-typed function template variables as secret.
app/config/templates/site.php Marks password-typed site template variables as secret.
apps/console/src/components/pages/projects/$projectId/functions/create/TemplateConfigView.tsx Classifies function template variables and uses their secret state for masking and creation.
apps/console/src/components/pages/projects/$projectId/sites/create/TemplateConfigView.tsx Classifies site template variables and uses their secret state for masking and creation.
apps/console/src/lib/template-variables.ts Adds the shared password-type secrecy classification.
apps/console/tests/unit/template-variable-secret.test.ts Tests secret classification for password, text, and explicitly secret inputs.
tests/unit/General/TemplatesTest.php Checks that password-typed variables in both catalogs are marked secret.

Reviewed c92a69c · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/appwrite/appwrite/@appwrite.io/console@15477

commit: c92a69c

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

The function and site template catalogs described credential inputs with
`type => 'password'` alone and never set `secret`, so the template
response model filled it with `false`. Both setup wizards seeded each
variable with that flag and passed it to `createVariable`, overriding the
route's `secret` default of `true` — Redis and database passwords, API
tokens and Stripe secret keys entered during setup were stored readable
and handed back in clear text to anything holding `functions.read` or
`sites.read`.

Mark every password-typed catalog entry secret, and derive secrecy in the
wizards from the type so a server that omits the flag still classifies
the value. The input masking and the Secret badge now follow the same
computed flag instead of the raw catalog one.

appwrite:appwrite:alert#4728

Co-Authored-By: Claude Opus 5 <[email protected]>
@claudear
claudear force-pushed the fix-template-variable-secret branch from 0998fd9 to c92a69c Compare November 11, 2026 09:36
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-template-variable-secret (after).

Metric Before After Change
🚀 Requests/sec 176.71 205.09 🟢 +16.1%
⏱️ Latency P50 98.98 ms 83.96 ms 🟢 -15.2%
⏱️ Latency P95 228.52 ms 199.98 ms 🟢 -12.5%
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 83.96 199.98 12,540 205.09 -28.55
Account 156.89 319.14 660 11.52 -22.55
TablesDB 81.27 163.26 6,820 114.99 -20.79
Storage 77.05 174.36 3,300 57.39 -42.35
Functions 119.25 230.31 1,760 31.31 -25.12

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.create 460.8
functions.variables.update 459.23
account.name.update 443.54
account.prefs.update 442.68
tablesdb.rows.delete 396.03

@ChiragAgg5k
ChiragAgg5k merged commit 09db206 into main Nov 11, 2026
76 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix-template-variable-secret branch November 11, 2026 12:03
ChiragAgg5k added a commit that referenced this pull request Nov 12, 2026
fix(templates): store password-typed template variables as secrets (appwrite:appwrite:alert#4728)

(cherry picked from commit 09db206)
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.

2 participants