Blocks Editor URL Validation#
URL validation for links in the Blocks rich text editor is split across two independent files with duplicated logic ā creating a maintenance risk of silent divergence. A known bug (open as of 2026-09-21, fix in PR #27758) causes fragment-only anchor links (#anchor) to be rejected by both layers, a regression introduced by a security hardening commit.
Allowed Protocols#
Both validation sites define an identical allowlist :
ALLOWED_LINK_PROTOCOLS = new Set(['http:', 'https:', 'ftp:', 'mailto:', 'tel:'])
Any URL whose protocol (as parsed by new URL()) is not in this set is rejected. Because new URL() normalizes the protocol before the check, obfuscation attempts like %6aavascript:, \tJaVaScRiPt:, or javascript: are all caught.
Validation Functions#
| Symbol | Location | Purpose |
|---|---|---|
isValidLink | Link.tsx | Client-side gate; controls Save button and rendered href |
isValidAbsoluteLink | Link.tsx | Stricter client-side check; used only in the paste handler (insertData) |
checkValidLink | blocks-validator.ts | Server-side yup validator; rejects invalid links on save |
isValidLink and checkValidLink share the same algorithm :
- If the input starts with
/, prependhttps://strapi.iosonew URL()doesn't throw on root-relative paths. - Pass the (possibly rewritten) string to
new URL(). - Return
trueonly ifurl.protocolis inALLOWED_LINK_PROTOCOLS; returnfalseon any exception.
isValidAbsoluteLink skips the root-relative rewriting ā it calls new URL(link) directly ā making it intentionally stricter. Pasting #anchor or /about will not auto-create a link.
Where Validation Is Applied#
- Save button:
isSaveDisabled = !isValidLink(linkUrl)ā the Save button in the link popover is disabled for any URLisValidLinkrejects. - Rendered
href:href={isValidLink(link.url) ? link.url : undefined}ā stored links with invalid URLs silently lose theirhrefin the editor view. - Paste handler:
isValidAbsoluteLinkis checked on paste; if true, the text is auto-converted to a link node . - Server save:
linkNodeValidatorrunscheckValidLinkvia a yup.test()on every save/publish operation .
Fragment-Only Link Bug (Issue #27756)#
Status: open; fix pending in PR #27758.
Fragment-only URLs like #anchor are rejected by both isValidLink and checkValidLink. Root cause: the guard only rewrites strings starting with /; new URL('#anchor') (bare) throws, and the catch block returns false .
Two user-visible effects :
- Anchor links cannot be authored ā Save button stays disabled.
- Existing anchor links lose their
hrefā content already stored with#anchorsilently renders without ahrefin the editor.
Effect 2 is a regression from commit 2f3595f, which added ALLOWED_LINK_PROTOCOLS to block javascript: schemes. Before that commit the anchor element used href={link.url} unconditionally .
Proposed fix in PR #27758: treat a leading # the same as a leading / inside isValidLink (and checkValidLink):
- const url = new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);
+ const url = new URL(
+ link.startsWith('/') || link.startsWith('#') ? `https://strapi.io${link}` : link
+ );
The fragment resolves against the base, the protocol becomes https:, and ALLOWED_LINK_PROTOCOLS still applies. isValidAbsoluteLink is deliberately left unchanged (paste handler should not auto-create fragment links). The edge case #javascript:alert(1) passes but renders as an inert fragment href ā it does not execute JavaScript .
Duplicated Allowlist ā Divergence Risk#
ALLOWED_LINK_PROTOCOLS and the URL-parsing algorithm are copy-pasted into two separate files with no shared source . Any change to the allowlist (e.g., adding # support) must be applied in both files. A mismatch means content accepted by the editor UI may be rejected on the server, or vice versa. There is no shared utility tying these together.
Key Files#
| File | Purpose |
|---|---|
Blocks/Link.tsx | Client-side link block: isValidLink, isValidAbsoluteLink, ALLOWED_LINK_PROTOCOLS, link popover, withLinks Slate plugin |
entity-validator/blocks-validator.ts | Server-side yup schema for Blocks content; checkValidLink, linkNodeValidator |
Blocks/tests/Link.test.tsx | Unit tests covering unsafe URL rejection, paste behavior, and Save-button gating |
| PR #27758 | Open fix: allow #anchor fragment-only links |
Commit 2f3595f | Introduced ALLOWED_LINK_PROTOCOLS security fix that caused the fragment regression |