Validate custom URLs in the shared link() field when they are saved
Back to our planType
tech-debt
Problem
The shared link() field helper (src/platform/payload/link.ts after #489, formerly src/modules/site/cms/link.ts) stores a custom URL as typed. An editor can save javascript:…, data:… or a protocol-relative //host link. The "Top issues" block (#489) filters these out when it draws the page, but other blocks that use link() (call to action, content columns, hero links, header and footer navigation) depend on their own rendering. Nothing refuses the bad URL when it is saved.
Proposed fix
Add a validate to link()'s url field. It accepts an absolute http(s) URL, a site path starting with a single /, mailto: and tel: if any block already uses them (check first), and an anchor #… if used. It refuses everything else with a message the editor can act on. Reuse the checks from #489's isSafeHref and isHttpUrl, moving the shared check into src/platform/lib/ so blocks and the field use one rule.
Acceptance criteria
- Saving a link with
javascript:,data:,//hostor/\hostis refused in Admin and over the API. - Existing valid links still save. Check the seed and the current production link forms (paths, https, any
mailto:ortel:) before tightening. - A test covers the field's validation in-memory.
Area
cms, frontend
Priority
medium
Generated by Claude Code, opens in a new tab