Repository navigation
fix(redirects): reject enabling a redirect that closes a loop - #3692
Conversation
🦋 Changeset detectedLatest commit: d8b7764 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
This is the right fix for the stated bug: enabling a disabled redirect can close a redirect loop, and neither the handler nor the 081 database guards checked that path. The PR correctly tightens the handler’s loop-check condition and adds a defensive migration-level trigger (090) on both PostgreSQL and SQLite that rejects the same write from any writer.
What I checked:
- Handler logic (
packages/core/src/api/handlers/redirects.ts): the loop check now fires when a redirect becomes enabled, even if source/destination are unchanged. The condition (willBeEnabled && (source changed || destination changed || !existing.enabled)) correctly captures "the edge becomes active", covers terminal-status skips, and preserves the ability to disable redirects. - Migration 090: the trigger is idempotent (
CREATE OR REPLACE FUNCTION+DROP TRIGGER IF EXISTSon Postgres,CREATE TRIGGER IF NOT EXISTSon SQLite), uses the same advisory lock as 081, excludes the row being updated, and only fires on a realenabled 0 → 1transition with a non-empty destination. TheSELECT RAISE(ABORT, ...) WHERE EXISTS(...)idiom matches the established D1-safe pattern from 081. - Migration registration: 090 is imported and registered in
runner.tsimmediately after 089, with the expected naming. - Tests: the handler test now asserts that enabling a loop-closer is rejected and leaves the row disabled; the new migration test verifies the 090 trigger rejects a direct SQL enable; the transfer test drops the new trigger on the origin to model a pre-090 loop and keeps testing the large-package import path. All tests look like they exercise real behavior, not implementation details.
- Changeset: the entry leads with the user-facing behavior, names the affected surfaces (admin, API, plugins), notes the protection for writers that bypass the API, and reassures that existing loops remain editable/disablable. It meets the changeset README standard for a patch entry.
- AGENTS.md conventions: no logged-out hot path is affected, no user-facing strings changed, no migrations are edited in-place, SQL is not interpolated, and comments explain intent without narrator/justification prose.
I found no logic bugs, regressions, or convention violations. The implementation is clean and the regression coverage is appropriate.
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | ea78e47 | Sep 30 2026, 03:30 PM |
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://fix-redirect-enable-loop.try.emdashcms.com, https://fix-redirect-enable-loop-emdash-playground.emdash-cms.workers.dev (commit d8b7764)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
468159d to
ea78e47
Compare
Overlapping PRsThis PR modifies files that are also changed by other open PRs: This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
Enabling a disabled redirect skipped the loop check in the handler, and the 081 database guards only fire when source or destination changes, so a plain enable could close a loop. The handler now checks loops whenever a rule becomes enabled, and migration 090 adds a trigger on both dialects that rejects the same write from any writer. The transfer loop test now removes the new trigger on its origin to model a site whose loop predates the guard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ea78e47 to
d8b7764
Compare
What does this PR do?
Enabling a disabled redirect can close a redirect loop. The redirect handler only ran the loop check when the source or destination changed, and the database guards from migration 081 fire on the same condition, so a plain
enabled: false → trueupdate skipped both.The transfer loop test now drops the new trigger on its origin database, so it can model a site whose loop predates the guard.
This is the first of three stacked PRs from work on #2288. The others are #3693 (stable pattern precedence) and #3694 (redirect artifact cache), stacked on this branch.
Closes # (no issue; found while working on #2288)
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure
Screenshots / test output
Not applicable (no UI change).
redirect-enable-loop-guard-migration.test.tschecks that the 090 trigger rejects the same write made directly against the database.🤖 Generated with Claude Code