Skip to content

Fix UrlField and FileField may execute JS code on click - #11409

Merged
fzaninotto merged 2 commits into
masterfrom
fix/url-field-unsafe-urls
Oct 19, 2026
Merged

fzaninotto merged 2 commits into
masterfrom
fix/url-field-unsafe-urls

Conversation

@fzaninotto

@fzaninotto fzaninotto commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Problem

<UrlField> renders a record's field value directly as an anchor's href attribute with no scheme validation or sanitization. If the backing data source (a REST/GraphQL API, any data provider) returns a javascript: URI for that field instead of a URL, UrlField places it unmodified into the DOM. Clicking the rendered link executes it in the admin user's session. UrlField is documented purely as "displays a url," with no warning that the field value must be scheme-validated by the caller, unlike RichTextField's documented sanitization requirement.

Solution

Use a scheme detection function before putting the record field in the href prop.

If javascript: is detected, render an empty link and log an error in the console.

Closes #11408

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

Comment thread packages/ra-core/src/util/getSafeUrl.ts Fixed
URL is 25x slower, but most important, it requires window to be defined, which forbids SSR.
@fzaninotto
fzaninotto merged commit d20820a into master Oct 19, 2026
15 checks passed
@fzaninotto
fzaninotto deleted the fix/url-field-unsafe-urls branch October 19, 2026 15:27
@fzaninotto fzaninotto added this to the 5.15.5 milestone Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UrlField renders a record's field value directly as a link href with no scheme validation (XSS)

2 participants