Closed bmarshall511 closed 1 year ago
@darylldoyle Totally get where you're coming from. This was actually in response to this issue: https://github.com/10up/safe-svg/issues/115. In a few projects that I've been dabbling in recently, we've been using something similar within the theme to sanitize SVG output, so thought it might be a pretty cool solution for that request.
You've made some solid points, especially about KSES not being suitable for SVG sanitization. And I agree, maintaining the SVG elements list in line with the svg-sanitiser library might be quite a handful.
I hear ya about the fact that the KSES filter doesn't consider the extendibility of the list of allowed elements/attributes. This could indeed lead to some elements/attributes being stripped off due to late escaping. And for sure, the last thing we want is to overcomplicate things and neglect potential security implications.
Gonna check out those resources you've shared - seems like some really useful stuff there. I'm all about that SVG security knowledge, so much appreciated for that! How about for now I close this & can be used as reference for the #115 issue?
@bmarshall511 I appreciate your willingness to understand this! I hope the shared resources are helpful 🙂
In regards to #115, I think it'd be useful for Safe SVG to provide a helper function which wraps these lines:
https://github.com/10up/safe-svg/blob/develop/safe-svg.php#L277-L283
That would give people a way to output SVGs whilst ensuring they're sanitised. There's something to say for sanitising it to appease a linter. If the SVG is bundled with a theme, do we need to sanitise it on output? We should know what's in that file. We mainly need to sanitise files coming from third parties.
It would make sense if we were outputting SVGs from an API or other third-party integration.
I'm happy for you to close this issue and move the discussion to #115 if you like.
Description of the Change
Added a helper function used for
wp_kses()
to return an array of allowed HTML tags & attributes.Closes #115
How to test the Change
Example usage:
Changelog Entry
Credits
Props @bmarshall511
Checklist: