close
Skip to content

Dashboard Widgets: Sanitize help link hrefs - #80409

Merged
retrofox merged 2 commits into
trunkfrom
fix/sanitize-widget-help-link-href
Jul 21, 2026
Merged

Dashboard Widgets: Sanitize help link hrefs#80409
retrofox merged 2 commits into
trunkfrom
fix/sanitize-widget-help-link-href

Conversation

@retrofox

@retrofox retrofox commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What?

Hardens gutenberg_sanitize_widget_help() so each help link href is run through esc_url_raw(), and links whose href does not survive sanitization are dropped along with the malformed ones.

Why?

Widget help notes carry optional links rendered as anchors on the dashboard.

The previous sanitizer only checked that label and href were non-empty, so an href with an unsafe scheme such as javascript: alert(1) passed through untouched and reached the rendered markup.

Passing the href through esc_url_raw() rejects unsafe protocols and normalizes the value before it is stored and rendered.

How?

In lib/experimental/dashboard-widgets/widget-types.php, each link href is now filtered with esc_url_raw().

The link is kept only when the filtered href is non-empty, so unsafe or unparseable URLs are dropped instead of forwarded.

Testing

Automated coverage in phpunit/experimental/widget-types-test.php adds an Unsafe protocol link (javascript:alert(1)) to the sanitizer input and asserts that only the valid link survives.

@retrofox
retrofox requested a review from spacedmonkey as a code owner July 17, 2026 11:11
@retrofox retrofox self-assigned this Jul 17, 2026
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: retrofox <retrofox@git.wordpress.org>
Co-authored-by: chihsuan <chihsuan@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@retrofox retrofox added [Type] Experimental Experimental feature or API. [Feature] Dashboard WordPress admin dashboard, widget framework, and layout customization [Type] Security Related to security concerns or efforts labels Jul 17, 2026
@retrofox
retrofox requested review from chihsuan and simison July 17, 2026 11:13
@retrofox retrofox removed the [Type] Security Related to security concerns or efforts label Jul 17, 2026
@retrofox retrofox changed the title Dashboard Widgets: Sanitize help link hrefs Dashboard Widgets: Sanitize help link hrefs Jul 17, 2026
@retrofox retrofox changed the title Dashboard Widgets: Sanitize help link hrefs Dashboard Widgets: Sanitize help link hrefs Jul 17, 2026

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tightening this up! The change looks good to me.

I noticed "widget action URLs" could potentially benefit from similar sanitization, but that feels outside the scope of this focused fix and can be followed up separately.

@retrofox

Copy link
Copy Markdown
Contributor Author

Yes, let's do it in a follow-up. Thanks for your review.

@retrofox
retrofox merged commit 780279a into trunk Jul 21, 2026
56 of 60 checks passed
@retrofox
retrofox deleted the fix/sanitize-widget-help-link-href branch July 21, 2026 07:50
@github-actions github-actions Bot added this to the Gutenberg 23.7 milestone Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Dashboard WordPress admin dashboard, widget framework, and layout customization [Type] Experimental Experimental feature or API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants