Check Mercury's return path the way the provider kit does
Summary
Mercury controller convergence, C2d: Mercury's return_to check now matches the provider kit's, as Lunch Flow's does since C1d (jaysbeekay/sure#733). The old check accepted protocol-relative paths, an open redirect: ?return_to=//evil.example was rendered as the selection dialog's Cancel link, and after a successful link redirect_to raised OpenRedirectError (a 500). MercuryItemsController now includes the kit's SafeReturnPath concern and its own copy goes.
Part of #5003 (Track B, controller-layer convergence for Mercury, decided 2026-11-16).
Stacked on #5250. Fork pre-flight: jaysbeekay/sure#741 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).
Behaviour delta (Mercury)
return_to | Before | After |
|---|---|---|
/accounts?tab=all | kept | kept |
/accounts (surrounding whitespace) | rejected | kept, stripped |
//evil.example | kept: Cancel link off the site; a successful link raised OpenRedirectError (500) | rejected (fallback path) |
/%2Fevil.example, /%2fevil.example, /%5Cevil.example | kept | rejected |
/ (bare slash) | kept | rejected |
/\evil.example, /<tab>/evil.example, https://evil.example/... | rejected | rejected |
What changed
MercuryItemsControllerincludesSafeReturnPath; its privatesafe_return_to_pathis deleted.
Demo data
No demo data needed.
Migration notes
No migration.
Verification
- Tests (fail-first): new
MercuryItemsReturnToTest, the 11 cases of Lunch Flow's (jaysbeekay/sure#733) against Mercury's selection dialog and link action. Before the change 7 fail (whitespace,//, three encoded forms, bare slash, and the link'sOpenRedirectError); the rest pass before and after as guards. - Mutation, caught: Mercury keeping a lax check of its own (8 failures). The concern's own layers were mutated in jaysbeekay/sure#733.
- Existing tests unedited:
MercuryItemsControllerTestpasses. bin/rails test(full, at the C2d commit): 16,434 runs, 0 failures; the same 8ReleaseNotesWorkflowTesterrors (nonodein the test image).bin/rubocopon changed files: no offenses.bin/brakeman: no warnings.- Size: non-test +2 / -25.
- Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.
Blast radius
safe_return_to_pathis read in Mercury'sselect_accounts,link_accounts,select_existing_accountandlink_existing_account; all treatnilas "use the fallback".- Siblings: Sophtron, Wise, Questrade, Redbark and Kraken keep lax copies (listed in jaysbeekay/sure#733), each left for its provider's move.
Summary by cubic
Mercury's return_to validation now matches the provider kit's SafeReturnPath concern, closing an open redirect where ?return_to=//evil.example rendered an off-site Cancel link and a successful link raised OpenRedirectError. MercuryItemsController includes the shared concern and its lax safe_return_to_path copy is removed; absolute, protocol-relative, backslash, percent-encoded, control-character, and bare-slash paths are rejected, and surrounding whitespace is stripped.
MercuryItemsReturnToTestcovers all 11 return-path cases against every Mercury action that readsreturn_to: the selection dialogs and link actions, plus triple-slash and control-character cases, each proven by mutation.- Sibling providers (Sophtron, Wise, Questrade, Redbark, Kraken) keep their lax copies and are left for their own migration.