Dashboard Widgets: Sanitize help link hrefs - #80409
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
help link hrefs
help link hrefs
chihsuan
left a comment
There was a problem hiding this comment.
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.
|
Yes, let's do it in a follow-up. Thanks for your review. |
What?
Hardens
gutenberg_sanitize_widget_help()so each help linkhrefis run throughesc_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
labelandhrefwere non-empty, so anhrefwith an unsafe scheme such asjavascript: 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 linkhrefis now filtered withesc_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.phpadds anUnsafe protocollink (javascript:alert(1)) to the sanitizer input and asserts that only the valid link survives.