rankmath / seo-by-rank-math

Rank Math is a revolutionary WordPress SEO Plugin that combines the features of many SEO tools and lets you multiply your traffic in the easiest way possible :bulb: :chart_with_upwards_trend: →
https://rankmath.com
107 stars 52 forks source link

Sanitize your filter outputs to prevent mismatch with the type from the result #280

Open CrochetFeve0251 opened 5 months ago

CrochetFeve0251 commented 5 months ago

Hey, Now you are also group.one folks so why not helping each others?

I looked quickly at your code base and I saw two points that might interest you to improve as you are also a plugin used by millions of websites.

Is your feature request related to a problem? Please describe. You added some filters into your plugin and it is a great practice.

However, I am seeing some potential troubles you can have with some clients miss using the filters.

As you are not validating or sanitizing the output of your filters it is possible to have invalid types being returned from that hooks potentially leading to a miss type.

This miss type can be invisible on certain parts of your code but on others like this one that can lead into warning or fatal.

Describe the solution you'd like The best solution would be to validate hooks either by adding some manual logic or adding a dispatcher into the code that also take as parameter of the filter a sanitizer for the value like this library. Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Currently we are trying to see if there is a way to push that practice into the core: https://github.com/wp-media/wp-rocket/issues/6629