Skip to content

Commit cebf7b8

Browse files
fix: sanitize url before using it
1 parent c4bb9e4 commit cebf7b8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/welcome/useful-plugins.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,21 @@ const PluginCard = ( { plugin } ) => {
101101
} )
102102
}
103103

104+
// Validate URL before using
105+
const isValidUrl = url => {
106+
try {
107+
const parsed = new URL( url )
108+
return [ 'http:', 'https:' ].includes( parsed.protocol )
109+
} catch {
110+
return false
111+
}
112+
}
113+
104114
return <div key={ plugin.id } className="s-card">
105115
<div className="s-plugin-title">
106-
<img className="s-plugin-icon" src={ pluginData.icon } alt={ __( 'Plugin icon', i18n ) } />
116+
{ pluginData.icon && isValidUrl( pluginData.icon ) && (
117+
<img className="s-plugin-icon" src={ pluginData.icon } alt={ __( 'Plugin icon', i18n ) } />
118+
) }
107119
<h3 className="s-card-title">{ plugin.title }</h3>
108120
</div>
109121
<p>{ plugin.description }</p>

0 commit comments

Comments
 (0)