-
Notifications
You must be signed in to change notification settings - Fork 18
Sanitized tags to prevent XSS #980
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
Open
girishpanchal30
wants to merge
2
commits into
development
Choose a base branch
from
bugfix/themeisle/2058
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| <?php | ||
| /** | ||
| * WordPress unit test plugin. | ||
| * | ||
| * @package Orbit_Fox | ||
| * @subpackage Orbit_Fox/tests | ||
| * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License | ||
| */ | ||
| class Test_Module_Beaver_Widgets extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Path to the pricing table frontend template. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $pricing_table_template; | ||
|
|
||
| public function setUp(): void { | ||
| parent::setUp(); | ||
|
|
||
| // The common functions file resolves its own path through the module instance, | ||
| // so it has to be loaded with the module as $this. Beaver Builder is not needed | ||
| // for the helpers themselves. | ||
| $module = new Beaver_Widgets_OBFX_Module(); | ||
| $load_common = Closure::bind( | ||
| function () { | ||
| require_once $this->get_dir() . '/inc/common-functions.php'; | ||
| }, | ||
| $module, | ||
| 'Beaver_Widgets_OBFX_Module' | ||
| ); | ||
| $load_common(); | ||
|
|
||
| $this->pricing_table_template = dirname( dirname( __FILE__ ) ) . '/obfx_modules/beaver-widgets/modules/pricing-table/includes/frontend.php'; | ||
| } | ||
|
|
||
| /** | ||
| * Render the pricing table frontend template. | ||
| * | ||
| * @param array $args Settings to overwrite the defaults with. | ||
| * | ||
| * @return string | ||
| */ | ||
| protected function render_pricing_table( $args = array() ) { | ||
| $settings = (object) array_merge( | ||
| array( | ||
| 'card_layout' => 'yes', | ||
| 'plan_title' => 'Plan title', | ||
| 'plan_title_tag' => 'h2', | ||
| 'plan_subtitle' => 'Plan subtitle', | ||
| 'plan_subtitle_tag' => 'p', | ||
| 'price' => '50', | ||
| 'currency' => '$', | ||
| 'currency_position' => 'after', | ||
| 'period' => '/mo', | ||
| 'features' => array(), | ||
| 'text' => 'Buy now', | ||
| 'link' => 'https://example.com', | ||
| ), | ||
| $args | ||
| ); | ||
|
|
||
| ob_start(); | ||
| include $this->pricing_table_template; | ||
|
|
||
| return ob_get_clean(); | ||
| } | ||
|
|
||
| /** | ||
| * Supported tags should be returned unchanged. | ||
| * | ||
| * @covers ::themeisle_sanitize_tag | ||
| */ | ||
| public function test_sanitize_tag_keeps_supported_tags() { | ||
| foreach ( array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p' ) as $tag ) { | ||
| $this->assertEquals( $tag, themeisle_sanitize_tag( $tag ) ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Anything that is not a supported tag should fall back to a safe default. | ||
| * | ||
| * @covers ::themeisle_sanitize_tag | ||
| */ | ||
| public function test_sanitize_tag_falls_back_for_unsupported_tags() { | ||
| $unsupported = array( | ||
| 'h1 onmouseover=alert(document.cookie)', | ||
| 'p onclick=alert(1)', | ||
| 'h2 class="evil"', | ||
| 'script', | ||
| 'div', | ||
| 'H1', | ||
| '', | ||
| ); | ||
|
|
||
| foreach ( $unsupported as $tag ) { | ||
| $this->assertEquals( 'h1', themeisle_sanitize_tag( $tag ), 'Unsupported tag: ' . $tag ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The pricing table should render the configured heading tags. | ||
| */ | ||
| public function test_pricing_table_renders_configured_tags() { | ||
| $output = $this->render_pricing_table( | ||
| array( | ||
| 'plan_title_tag' => 'h3', | ||
| 'plan_subtitle_tag' => 'h4', | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertStringContainsString( '<h3 class="obfx-plan-title text-center">Plan title</h3>', $output ); | ||
| $this->assertStringContainsString( '<h4 class="obfx-plan-subtitle text-center">Plan subtitle</h4>', $output ); | ||
| } | ||
|
girishpanchal30 marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * The pricing table should reject unsafe heading tags. | ||
| */ | ||
| public function test_pricing_table_sanitizes_unsupported_tags() { | ||
| $output = $this->render_pricing_table( | ||
| array( | ||
| 'plan_title_tag' => 'h3 onmouseover=alert(1)', | ||
| 'plan_subtitle_tag' => 'script', | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertStringContainsString( '<h1 class="obfx-plan-title text-center">Plan title</h1>', $output ); | ||
| $this->assertStringContainsString( '<h1 class="obfx-plan-subtitle text-center">Plan subtitle</h1>', $output ); | ||
| $this->assertStringNotContainsString( 'onmouseover', $output ); | ||
| $this->assertStringNotContainsString( '<script', $output ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The identical sink is still open in the post-grid widget —
modules/post-grid/includes/frontend.phpL63-64 interpolates$settings->title_tagstraight intothe_title()with no escaping at all. Same module, same vector as themeisle#2058, so closing the issue on the pricing table alone leaves it exploitable.Please route post-grid through this helper too. Its select also offers
spananddiv(post-grid.phpL150-165), so the allowed list and the fallback need to be parameters:That would also let
sanitize_tag()inelementor-extra-widgets/widgets/elementor/pricing-table.phpL1179 drop its copy of the same list.