From a2ab68842adf469af97f72ea6b57fc44b621e3fb Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 24 Apr 2021 23:21:01 +0200 Subject: [PATCH 1/3] ProperEscapingFunction: further improve attribute matching Prior to VIPCS 2.3.0, equal signs not followed by quotes were ignored by this sniff, even though unquoted values for attributes in HTML is supported as long as the value does not contain whitespace. However, detecting equal signs not followed by quotes could confuse the attribute detecting as equal signs without quotes can also be used outside of HTML attribute context. This improves the attribute detection further by making sure that an equal sign (with or without subsequent quotes) is preceded by at least one alphanumeric character to indicate it _could_ be an HTML attribute. Includes tests. Fixes 680 --- .../Sniffs/Security/ProperEscapingFunctionSniff.php | 2 +- .../Tests/Security/ProperEscapingFunctionUnitTest.inc | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php b/WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php index 7e876d5c..9b9513f0 100644 --- a/WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php +++ b/WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php @@ -23,7 +23,7 @@ class ProperEscapingFunctionSniff extends Sniff { * * @var string */ - const ATTR_END_REGEX = '`(?href|src|url|(^|\s+)action)?=(?:\\\\)?["\']*$`i'; + const ATTR_END_REGEX = '`(?href|src|url|(^|\s+)action)?(?<=[a-z0-9_-])=(?:\\\\)?["\']*$`i'; /** * List of escaping functions which are being tested. diff --git a/WordPressVIPMinimum/Tests/Security/ProperEscapingFunctionUnitTest.inc b/WordPressVIPMinimum/Tests/Security/ProperEscapingFunctionUnitTest.inc index c273f93f..af65ab5f 100644 --- a/WordPressVIPMinimum/Tests/Security/ProperEscapingFunctionUnitTest.inc +++ b/WordPressVIPMinimum/Tests/Security/ProperEscapingFunctionUnitTest.inc @@ -106,3 +106,10 @@ echo ''; // Error.
html
'; ?>
html
+ +// Issue #680 - only match = when preceeded by something which could be an HTML attribute. + + +
From 46cf78964fe9cbd0659f8773940ae6761a658054 Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Tue, 27 Apr 2021 12:12:07 -0600 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb6c31fa..f2e4b095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.3.2] - 2021-04-28 + +Props: jrfnl + +### Fixed +- [#681](https://github.com/Automattic/VIP-Coding-Standards/pull/681): ProperEscapingFunction: improve attribute matching accuracy for notAttrEscAttr. + ## [2.3.1] - 2021-04-23 Props: jrfnl @@ -550,6 +557,7 @@ Initial release. Props: david-binda, pkevan. +[2.3.1]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.3.1...2.3.2 [2.3.1]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.3.0...2.3.1 [2.3.0]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.2.0...2.3.0 [2.2.0]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.1.0...2.2.0 From 0b9b134812df979e06305d238f406dec3c3d3852 Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Tue, 27 Apr 2021 12:36:35 -0600 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2e4b095..045ac2da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -557,7 +557,7 @@ Initial release. Props: david-binda, pkevan. -[2.3.1]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.3.1...2.3.2 +[2.3.2]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.3.1...2.3.2 [2.3.1]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.3.0...2.3.1 [2.3.0]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.2.0...2.3.0 [2.2.0]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.1.0...2.2.0