Distinguish endpoint secret decryption failures from ordinary delivery failures - #231
Merged
Merged
Conversation
…livery failures A naive APP_KEY rotation (replacing the key instead of moving the old value into APP_PREVIOUS_KEYS) permanently breaks decryption of every Endpoint.secret_key. Previously this DecryptException was caught by SendWebhook's generic catch(Throwable) block and recorded as an ordinary delivery failure, indistinguishable from a downed customer endpoint, so the real cause (an APP_KEY misconfiguration) went undetected while retries burned through backoff for a condition they could never fix. SendWebhook now catches DecryptException specifically, logs it at critical level, and records a delivery response_body that names the actual cause. DEPLOYMENT.md documents the correct APP_KEY rotation procedure using APP_PREVIOUS_KEYS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was broken
Endpoint.secret_keyis encrypted at rest usingAPP_KEY(app/Models/Endpoint.php:33). Nothing documented the correct way to rotateAPP_KEYin production, and nothing in code distinguished a decryption failure from an ordinary delivery failure.If an operator rotated
APP_KEYthe "obvious" way (generate a new value, replace the old one, restart) without first moving the old key intoAPP_PREVIOUS_KEYS, everyEndpoint::secret_keybecame permanently undecryptable — there's no other copy of the plaintext secret anywhere.SendWebhook::handle()'s genericcatch (Throwable $e)caught the resultingDecryptExceptionthe same way it catches an HTTP failure, so every delivery for every endpoint started failing and looked identical to mass endpoint downtime, with retries burning through backoff for a condition retries could never fix.What changed
app/Jobs/SendWebhook.php: added acatch (\Illuminate\Contracts\Encryption\DecryptException $e)block ahead of the genericThrowablecatch. It logs atcriticallevel and records aDelivery.response_bodythat names the actual cause (APP_KEYrotated without preserving the previous key inAPP_PREVIOUS_KEYS), instead of surfacing as an opaque/generic failure. The delivery is still scheduled for retry, since fixingAPP_PREVIOUS_KEYScan make a subsequent attempt succeed.DEPLOYMENT.md: added an "APP_KEY Rotation" runbook under Security Considerations describing the safe rotation procedure (move the current key intoAPP_PREVIOUS_KEYS, generate the new key, re-save everyEndpointrow to re-encrypt under the new key, then remove the old key).tests/Feature/SendWebhookSecretDecryptFailureTest.php: covers both the new catch path (secret encrypted under a key no longer inAPP_KEY/APP_PREVIOUS_KEYSis caught and flagged distinctly, and still scheduled for retry) and the correct-rotation recovery path (a secret encrypted under the old key still decrypts once that key is present inAPP_PREVIOUS_KEYS).Test plan
vendor/bin/pint --dirty— cleanphp artisan test— full suite passes (269 passed, 1 pre-existing skip)Fixes #168