Skip to content

Fix: Webhook API secret rotation and security - #11884

Merged
Meldiron merged 6 commits into
1.9.xfrom
fix-webhook-api-security
Apr 13, 2026
Merged

Meldiron merged 6 commits into
1.9.xfrom
fix-webhook-api-security

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Webhook secret rotation API is now in correct folder
  • Webhook secret rotation can now be done zero-downtime
  • Webhook secret is now better protected (write only)

Test Plan

  • Existing tests updated
  • New tests

Related PRs and Issues

x

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?

@github-actions

github-actions Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit db406b0 - 4 flaky tests
Test Retries Total Time Details
FunctionsScheduleTest::testCreateScheduledAtExecution 1 129.09s Logs
UsageTest::testFunctionsStats 1 10.22s Logs
UsageTest::testPrepareSitesStats 1 7ms Logs
UsageTest::testEmbeddingsTextUsageDoesNotBreakProjectUsage 1 6ms Logs

@greptile-apps

greptile-apps Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR moves the webhook secret-rotation endpoint into the correct folder structure, adds an optional secret parameter to webhook creation, and makes the signing key write-only by stripping it from GET, list, and regular update responses while still returning it on create and explicit secret-rotation calls.

Confidence Score: 5/5

Safe to merge; the secret is correctly hidden in read/update paths and correctly exposed on create and rotation. All findings are P2 style suggestions.

No P0 or P1 issues found. All current endpoints (Get, XList, Update) correctly remove signatureKey before rendering, so no secret is leaked today. The only concerns are a fragile opt-out design in the model filter and a test-name/expectation mismatch for the zero-downtime claim.

src/Appwrite/Utopia/Response/Model/Webhook.php — the opt-out pattern in filter() is worth revisiting to prevent future secret leaks.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Create.php Adds optional secret param for user-provided signing key; falls back to bin2hex(random_bytes(64)); no removeAttribute('signatureKey') so secret is correctly returned on creation.
src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Get.php Removes signatureKey before calling dynamic() to prevent secret exposure; correct and consistent with the write-only intent.
src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Secret/Update.php New endpoint for secret rotation; uses correct sparse Document update pattern and intentionally omits removeAttribute('signatureKey') so the new secret is returned in the response.
src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/Update.php Removes signatureKey before responding to ensure the secret is not exposed on a normal webhook update; follows sparse Document update pattern.
src/Appwrite/Platform/Modules/Webhooks/Http/Webhooks/XList.php Strips signatureKey from every webhook document in the list before rendering; secret correctly hidden from list responses.
src/Appwrite/Utopia/Response/Model/Webhook.php Adds secret rule (type string, default ''); filter() unconditionally maps signatureKey → secret, creating an implicit opt-out pattern where endpoints must pre-remove signatureKey to hide the secret.
src/Appwrite/Platform/Modules/Webhooks/Services/Http.php Registers new UpdateWebhookSecret action; import and wiring are correct.
tests/e2e/Services/Webhooks/WebhooksBase.php Comprehensive new tests for secret exposure, min/max length, rotation, and custom secrets; testSecretRotationZeroDowntime name and behavior don't fully align with true zero-downtime (dual-key) semantics.

Comments Outside Diff (1)

  1. src/Appwrite/Utopia/Response/Model/Webhook.php, line 109-110 (link)

    P2 Fragile opt-out pattern for secret hiding

    filter() unconditionally maps signatureKey → secret for every webhook response. Any endpoint that should NOT expose the secret must proactively call $webhook->removeAttribute('signatureKey') before dynamic() — if a future endpoint omits that step, the signing key will be silently leaked. The current endpoints (Get, Update, XList) all handle this correctly, but the contract is implicit and unenforced.

    Consider inverting the pattern: have filter() default secret to '', and let only the endpoints that explicitly need to expose the key (Create, updateWebhookSecret) set it:

    // In filter() — always produce an empty secret by default
    $document->setAttribute('secret', '');
    $document->removeAttribute('signatureKey');

    Then in Create.php and Secret/Update.php, set the field on the document before calling dynamic():

    $webhook->setAttribute('secret', $webhook->getAttribute('signatureKey'));
    $webhook->removeAttribute('signatureKey');
    $response->dynamic($webhook, Response::MODEL_WEBHOOK);

    This makes exposure opt-in rather than opt-out, eliminating the footgun.

Reviews (1): Last reviewed commit: "Fix tests" | Re-trigger Greptile

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

  • Requests per second: 1,686
  • Requests with 200 status code: 303,545
  • P99 latency: 0.109941864

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,686 1,319
200 303,545 237,521
P99 0.109941864 0.154540771

@Meldiron
Meldiron merged commit 0a21f3b into 1.9.x Apr 13, 2026
44 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.

2 participants