Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

βœ… β™Ώ 🐞 Sanitization removes aria-hidden attributes from uploaded SVG icons #29340

Closed
6 tasks done
bugnumber9 opened this issue Nov 20, 2024 · 7 comments
Closed
6 tasks done
Labels
bug Indicates a bug with one or multiple components. control/icons References any instance of the Icon control. mod/b* [Temp.] For internal use only. mod/v* [Temp.] For internal use only. mod* [Temp.] For internal use only. solved Indicates that an Issue has been Solved, or a Feature Request has been Released. status/merged Indicates when a Pull Request has been merged to a Release. type/accessibility Indicates when a topic is related to Accessibility. type/security Indicates when a topic is related to component Security. widget/icon-list References the Icon List widget.

Comments

@bugnumber9
Copy link

bugnumber9 commented Nov 20, 2024

Prerequisites

  • I have searched for similar issues in open and closed tickets and cannot find a duplicate.
  • I have troubleshooted my issue, and it still exists against the latest stable version of Elementor.

Description

I use a custom SVG icon in the Icon List widget.
This SVG icon has aria-hidden="true" attribute, but it's not displayed on the frontend.

Steps to reproduce

  1. Add an Icon List widget.

  2. Use a custom SVG icon with an inline ARIA attribute.
    This is my SVG icon, you can see the ARIA attribute in the code:
    image

  3. Inspect the element on the frontend.
    This is what's displayed on the frontend:
    image
    As you can see, the aria-hidden="true" attribute isn't displayed.

Expected behavior

ARIA attributes shouldn't be skipped when a custom SVG icon is displayed on the frontend.

Isolating the problem

  • This bug happens when only the Elementor (and Elementor Pro) plugins are active.
  • This bug happens with the Hello Elementor theme active.
  • I can reproduce this bug consistently by following the steps I described above.

Elementor System Info

Click to reveal
== Server Environment ==
	Operating System: Linux
	Software: LiteSpeed
	MySQL version: MariaDB Server v10.6.20
	PHP Version: 8.2.25
	PHP Memory Limit: 1G
	PHP Max Input Vars: 10000
	PHP Max Post Size: 64M
	GD Installed: Yes
	ZIP Installed: Yes
	Write Permissions: All right
	Elementor Library: Connected

== WordPress Environment ==
	Version: 6.7
	Site URL: <removed>
	Home URL: <removed>
	WP Multisite: No
	Max Upload Size: 64 MB
	Memory limit: 1024M
	Max Memory limit: 1024M
	Permalink Structure: /%postname%/
	Language: en_US
	Timezone: 0
	Debug Mode: Inactive

== Theme ==
	Name: Hello Elementor
	Version: 3.1.1
	Author: Elementor Team
	Child Theme: No

== User ==
	Role: administrator
	WP Profile lang: en-US
	User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0

== Active Plugins ==
	Elementor
		Version: 3.25.8
		Author: Elementor.com

	Elementor Pro
		Version: 3.25.3
		Author: Elementor.com


== Features ==
	Custom Fonts: 0
	Custom Icons: 0

== Integrations ==
	


== Elementor Experiments ==
	Improved CSS Loading: Inactive by default
	Inline Font Icons: Active
	Additional Custom Breakpoints: Active
	Container: Active
	Upgrade Swiper Library: Active
	Nested Elements Performance: Active by default
	Optimized Control Loading: Active
	Optimized Markup: Inactive by default
	Conditionally load Swiper CSS files: Inactive by default
	Plugin Onboarding: Active by default
	CSS Smooth Scroll: Active by default
	Default to New Theme Builder: Inactive
	Header & Footer: Inactive
	Elementor Home Screen: Active by default
	Landing Pages: Inactive
	Nested Elements: Active
	Editor Top Bar: Inactive
	Element Caching: Active
	Link In Bio: Active by default
	Floating Buttons: Active by default
	Elementor Editor Events: Inactive by default
	Atomic Widgets: Inactive by default
	Launchpad Checklist: Inactive by default
	Menu: Active


== Log ==
	


== Elementor - Compatibility Tag ==
	
	Elementor Pro: Compatible

== Elementor Pro - Compatibility Tag ==

Agreement

  • I agree that my issue may be closed without action if it doesn't meet all the requirements.
@bugnumber9 bugnumber9 added the status/awaiting_triage Indicates when an Issue, Pull Request, or Discussion awaits to be triaged. label Nov 20, 2024
@nicholaszein nicholaszein changed the title Icon List widget doesn't display inline ARIA attribute in the uploaded SVG icon β›” β™Ώ 🐞 Icon List widget doesn't display inline ARIA attribute in the uploaded SVG icon Nov 20, 2024
@nicholaszein nicholaszein added type/accessibility Indicates when a topic is related to Accessibility. control/icons References any instance of the Icon control. widget/icon-list References the Icon List widget. mod* [Temp.] For internal use only. type/security Indicates when a topic is related to component Security. mod/b* [Temp.] For internal use only. mod/v* [Temp.] For internal use only. bug Indicates a bug with one or multiple components. and removed status/awaiting_triage Indicates when an Issue, Pull Request, or Discussion awaits to be triaged. labels Nov 20, 2024
@nicholaszein
Copy link
Member

Hi @bugnumber9! How's it going?

Thank you for submitting your issue! πŸ™

We are aware that the aria-hidden attribute is removed from SVGs, but unfortunately, this is intentional, and is part of the sanitization of SVGs for security reasons

I will leave this issue open, but unfortunately, for the time being, we won't be changing this behavior for security reasons.

I hope you can understand.

Kind regards

@nicholaszein nicholaszein changed the title β›” β™Ώ 🐞 Icon List widget doesn't display inline ARIA attribute in the uploaded SVG icon β›” β™Ώ 🐞 Sanitization removes aria-hidden attributes from uploaded SVG icons Nov 20, 2024
@bugnumber9
Copy link
Author

Hey @nicholaszein

Thanks for your reply, yet I have to admit it's frustrating...

What security risks are involved with inline ARIA attributes? I'm not aware of any.
Sanitization, by definition, is removing potentially unsafe code. How come do ARIA attributes fall into this category?

There's no option in the Icon List widget to add that attribute to icons.
More often than not they should have it because in the majority of cases icons are decorative.

Finally, I can think of multiple ways to achieve the desired result.

I can use HTML widget and just paste SVG code (it'll render it as is), and then have a Heading widget next to it.
I can probably use Dynamic Tags with Dynamic Shortcodes (haven't tested yet but pretty sure it'll work) and again just paste the SVG code into the shortcode.
There are other hacky ways to do it.

With the current approach, the Icon List widget is not accessible without those "hacks" I mentioned above while adding nothing to security.

@nicholaszein
Copy link
Member

Hi @bugnumber9!

Apologies, I should have been more clear about the sanitization. Aria attributes pose no security risks on SVGs. The sanitization we use (based on the WordPress default sanitization) removes any attribute and other tags from the SVG tag that are not specifically native to SVG tags.

Your point about icons being decorative (and more specifically the aria attributes themselves) is a valid point.

We are aware this is a problem, however, we are unable to modify the sanitization of these icons at the moment. We understand this is not ideal, and we do have plans to address this limitation in the future, but due to the severity and complexity of this specific case, we cannot prioritize a fix for this at the moment.

I hope I was able to better convey the reason behind this decision.

Thank you for sharing your feedback though! πŸ™

@nicholaszein nicholaszein changed the title β›” β™Ώ 🐞 Sanitization removes aria-hidden attributes from uploaded SVG icons β™Ώ 🐞 Sanitization removes aria-hidden attributes from uploaded SVG icons Nov 20, 2024
@jamieburchell
Copy link

jamieburchell commented Nov 21, 2024

@nicholaszein Why not just whitelist the attribute in your sanitiser?

There is a filter that can be used. Something like this in a custom snippet or the theme's functions.php file should work:

<?php

/**
 * Allow aria-hidden attribute in SVG
 */
add_filter( 'elementor/files/svg/allowed_attributes', function( $allowed_attributes ) {

    $extra = array(
        'aria-hidden'
    );

    return array_merge( $extra, $allowed_attributes );

}, 10, 2);

@nicholaszein
Copy link
Member

@jamieburchell, because these are not the only ones to allow in terms of accessibility.

Check this article: https://css-tricks.com/accessible-svgs/

@jamieburchell
Copy link

jamieburchell commented Nov 21, 2024

@nicholaszein Sure, more could be whitelisted. The OP mentions one specifically.

The point is that it is possible for Elementor to add them; there are no technical restrictions on sanitisation preventing that from happening. Your comment suggests it's not possible.

@rami-elementor
Copy link
Member

Fixed in Elementor 3.28.2

@nicholaszein nicholaszein changed the title β™Ώ 🐞 Sanitization removes aria-hidden attributes from uploaded SVG icons βœ… β™Ώ 🐞 Sanitization removes aria-hidden attributes from uploaded SVG icons Apr 1, 2025
@nicholaszein nicholaszein added status/merged Indicates when a Pull Request has been merged to a Release. solved Indicates that an Issue has been Solved, or a Feature Request has been Released. labels Apr 1, 2025
@elementor elementor locked as resolved and limited conversation to collaborators Apr 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Indicates a bug with one or multiple components. control/icons References any instance of the Icon control. mod/b* [Temp.] For internal use only. mod/v* [Temp.] For internal use only. mod* [Temp.] For internal use only. solved Indicates that an Issue has been Solved, or a Feature Request has been Released. status/merged Indicates when a Pull Request has been merged to a Release. type/accessibility Indicates when a topic is related to Accessibility. type/security Indicates when a topic is related to component Security. widget/icon-list References the Icon List widget.
Projects
None yet
Development

No branches or pull requests

4 participants