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 (#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 jaysbeekay/sure#670 (Track B, controller-layer convergence for Mercury, owner 2026-11-16). Stacked on B8a (jaysbeekay/sure#740) in fork stack #687.
Upstream draft PR: https://github.com/we-promise/sure/pull/5251 (same branch, same commit), in native stack we-promise/sure#5268 on refactor/provider-kit.
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 (#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 #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 #733), each left for its provider's move.