Repository navigation
Enhanced RGBA color validation - #4718
girishpanchal30 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes requested
The stricter color check works, but the ability routes still store malformed colors without it.
inc/abilities/site_set_theme_mod.php:175—correctnessThe ability routes store color fields without the color check this PR tightens.site_set_theme_modsavesset_theme_mod( $key, $this->sanitize_value( $input['value'] ) )at line 175, andsanitize_value()only runs text sanitization (lines 191-200). The header and footer row-style abilities do the same fortext_color,background.colorValueandbackground.overlayColorValue(inc/abilities/builder_configure.php:188-194). Sorgb(1.2.3,4,5), whichneve_sanitize_colors()now rejects, is stored and printed as a CSS variable (inc/core/styles/css_prop.php:227-242). Run each color-bearing field of these abilities throughneve_sanitize_colors()before storage, and reject the call when it returns ''. Add ability tests that sendrgb(1.2.3,4,5)to each route.
Validation details
- Files reviewed: 2/2 changed files.
- The sanitization class passes at HEAD in a WordPress sandbox with PHP 8.3:
cd /var/www/html/wp-content/themes/neve && set -o pipefail; timeout 900 phpunit --do-not-cache-result --filter 'TestSani…printedOK (12 tests, 145 assertions)(run R9) - Both changed tests fail with the pr-base sanitizer, so they detect the change:
set -o pipefail; T=/var/www/html/wp-content/themes/neve; cd $T && timeout 900 phpunit --do-not-cache-result --filter 'Te…printedFailures: 2(run R12) - An isolated run compared the old and new patterns on 28 inputs. Only invalid CSS values changed to rejected, and long inputs showed no backtracking:
timeout 30 php /workspace/checks/C3/check.php | tee /workspace/checks/C3/output.txt(run R7, exit 0)
Untested areas
- Malformed colors inside
var()fallbacks and gradients still passneve_sanitize_colors(). No color picker was found that emits them, so this stays unconfirmed. - Palette colors saved under the old pattern were not traced to a real producer.
- WordPress versions between 5.5 and 7.1 were not read.
- The variant pass did not settle these places, where the fixed cause may still reach:
assets/apps/components/src/Common/ColorPickerFix.js:53-66— unverified: deciding whether malformed user input survives requires the version-matched WordPress ColorPicker.commitValues/GradientPicker contract. Preview outputs themselves interpolate value…assets/apps/components/src/Controls/ColorControl.js:46-52,175-181— unverified: deciding whether malformed user input survives requires the version-matched WordPress ColorPicker.commitValues/GradientPicker contract. Preview outputs themselves interpolate value…class-wp-customize-setting.php:650-660,657-667— unverified:/deps/wordpress/5.5/wp-includes/class-wp-customize-setting.php:650-660— unverified: persistence routing is established at 5.5 and 7.1: saving obtains post_value() after configured sanitization (:518-521 and :525-528; manager guards below). Corresponding source for…/deps/wordpress/7.1/wp-includes/class-wp-customize-setting.php:657-667— unverified: persistence routing is established at 5.5 and 7.1: saving obtains post_value() after configured sanitization (:518-521 and :525-528; manager guards below). Corresponding source for…- not reached: complete server-rendering path for header-footer-grid/Core/Components/Utility/SearchIconButton.php:239-267
🤖 Automated review · run code-review-agent_6b0564ed20f950.57009720.
🤖 Review agent — review posted ✅ on bebe609c · changes requested · 1 finding · 32 min
Run code-review-agent_6b0564ed20f950.57009720 · trail
There was a problem hiding this comment.
🟡 Changes requested
The new checks fix most ability color routes. The menu icon button appearance colors still skip the color check.
Questions for the author
- Issue #4708 reports that the Customizer row Text Color is cleaned only with
wp_filter_nohtml_kses. Is that setting checked as a color anywhere before it reaches the CSS?
Validation details
- Files reviewed: 8/8 changed files. One question was not settled: "Failure direction: Too strict".
- The new ability tests pass at HEAD:
set -o pipefail; cd /repo && git status --short | head -3; rm -rf /workspace/ab && mkdir -p /workspace/ab/head/themes /…printedOK (6 tests, 22 assertions)(run R5) - Four of them fail with the pr-base code, so they detect the change:
set -o pipefail; cd /workspace/ab/head/themes/neve && timeout 280 phpunit --do-not-cache-result --testdox --filter 'Test…printedTests: 6, Assertions: 14, Failures: 4.(run R6) - The earlier finding is fixed for builder rows and for
_colorand_backgroundkeys.
Untested areas
- "Failure direction: Too strict" was not settled for the background check.
- The color pickers in
ColorPickerFix.jsandColorControl.jswere not traced to the values they emit. - WordPress versions between 5.5 and 7.1 were not read.
- Import and migration color copies were not traced.
- The variant pass did not settle these places, where the fixed cause may still reach:
class-wp-customize-setting.php:650-660,657-667— unverified: The unversioned place resolves to the two endpoint versions ruled above; behavior at intermediate supported WordPress versions was not read.- not reached: migration/import writes in inc/core/admin.php:1097 and header-footer-grid/functions-migration.php:84
assets/apps/components/src/Common/ColorPickerFix.js:53-66— unverified: Presence-only checks reach inherited commitValues(colors). Whether malformed numeric components survive that implementation remains unknown; version-matched readable @wordpress/com…assets/apps/components/src/Controls/ColorControl.js:46-52,175-181— unverified: RGB interpolation and gradient forwarding lack local structural validation, but whether the upstream pickers emit malformed components remains unresolved. The dependency range in p…
🤖 Automated review · run code-review-agent_6b056e5b78b701.95767916.
🤖 Review agent — review posted ✅ on a4f93901 · changes requested · 2 findings · 21 min
Run code-review-agent_6b056e5b78b701.95767916 · trail
There was a problem hiding this comment.
🟡 Changes requested
The earlier findings are fixed. Four color paths outside the diff still store malformed colors and need the same check.
inc/abilities/appearance_update.php:585—correctnessThe appearance ability still stores malformed hex button colors. Its check accepts any hex of 3 to 8 digits, sobuttons.primary.background: "#12345"or a 7-digit value is saved toneve_button_appearance(lines 535-559). That value reaches--primarybtnbgunchanged and the browser drops it. Validate every button field (background, text and their hover values, primary and secondary) withneve_sanitize_colors(). Reject a non-empty value it returns as''. Add a case intests/test-neve-ability-color-inputs.phpthat sends#12345for each field and expects the request to fail.header-footer-grid/Core/Builder/Abstract_Builder.php:531—correctnessThe header and footer row Text Color is still not checked as a color. Its setting uses'sanitize_callback' => 'wp_filter_nohtml_kses', which only strips HTML. The saved value is printed as--colorwithout escaping (Abstract_Builder.php:1040-1043,css_prop.php:227-242). Sorgb(1.2.3,4,5)is stored, and#222;}body{background:lime}/*can close the rule and add CSS (issue #4708). Useneve_sanitize_colorsas the callback for every row Text Color setting. Add tests intests/test-neve-sanitization.phpthat sanitize a header row and a footer row Text Color with both values and expect''.inc/core/admin.php:1097—correctnessSwitching from Neve to a child theme copies every theme mod without the new color checks.migrate_options()runs onafter_switch_themeand copies stored values as they are. A color saved before this fix, such asrgb(1.2.3,4,5)inneve_scroll_to_top_icon_color, is copied and printed as--colorin the child theme. Run each copied color, background and button appearance mod through its Customizer sanitizer before the copy, and drop a value it blanks. Add a test that stores a malformed color, runsmigrate_options()for a child theme, and expects the copied mod to be empty.globals/sanitize-functions.php:36—correctnessMalformed function colors still pass when they sit insidevar()or a gradient. Thevar()fallback uses the loose$color_fnpattern[0-9a-z.,%\/\s-]+, and the gradient pattern accepts any such call. Sovar(--missing,rgb(1.2.3,4,5))andlinear-gradient(rgb(1.2.3,4,5),#fff)are saved unchanged and printed into CSS. Extend the component grammar ofneve_is_css_function_color()to accept the valid slash alpha form, such asrgb(1 2 3 / 50%). Then check everyrgb(),rgba(),hsl()andhsla()call inside avar()fallback or a gradient with that grammar. Add both malformed values totests/test-neve-sanitization.phpand expect''.
Validation details
- Files reviewed: 4/4 files changed since the prior review. Run code-review-agent_6b056e5b78b701.95767916 reviewed the other 4 files, not rerun.
- The ability color tests pass at HEAD:
du -sh /repo 2>/dev/null | tail -1; rm -rf /tmp/c3copy; git -C /repo worktree list; cp -a /repo /tmp/c3copy && cd /tmp/c…printedOK (10 tests, 39 assertions)(run R3) - The color sanitizer keeps nested malformed colors unchanged at HEAD and pr-base:
timeout 30 php /workspace/checks/C8/run.php(run R9, exit 0) - Question for the author:
CONTRIBUTING.mdputs new unit tests undertests/php/unit. Is that rule outdated?
Untested areas
- The valid button appearance test passed with the pr-base code. That run has no record.
- The suite fails to load an unchanged menu icon test in the checkout. A clean copy passes.
- The color picker scripts were not traced to the values they emit.
- Only WordPress 5.5 and 7.1 were read. The child theme copy was checked on 7.1 only.
- The variant pass did not settle these places, where the fixed cause may still reach:
- not reached: previously unverified ColorPickerFix.js:53-66, ColorControl.js:46-52,175-181 and migration writes
assets/apps/components/src/Common/ColorPickerFix.js:53-66— unverified: Presence checks forward components to inherited commitValues; the resolved upstream implementation and its numeric normalization remain unread.assets/apps/components/src/Controls/ColorControl.js:46-52,175-181— unverified: RGB interpolation and gradient forwarding depend on upstream picker output validation. JavaScript dependencies are absent (/workspace/review/context.md:79); the runtime component i…class-wp-customize-setting.php:650-660,657-667— unverified: WordPress 5.5 and 7.1 retain their supplied per-route rulings. Intermediate supported versions’ sanitize-before-write contracts remain unread; endpoint evidence does not establish …
🤖 Automated review · run code-review-agent_6b0575fabc1e97.12013384.
🤖 Review agent — review posted ✅ on a62cc7ba · changes requested · 6 findings · 45 min
Run code-review-agent_6b0575fabc1e97.12013384 · trail
| * Sanitize a value for its setting: colors and backgrounds as the Customizer does, the rest as text. | ||
| * | ||
| * @param string $key The allowlisted theme_mod key. | ||
| * @param mixed $value The incoming value. | ||
| * @return mixed Sanitized value, or null when a color or background is invalid. |
There was a problem hiding this comment.
comments The sanitize_setting() docblock is now stale. It says "colors and backgrounds as the Customizer does, the rest as text" and "null when a color or background is invalid". The new _button_appearance branch at line 211 follows neither sentence. Write "colors, backgrounds and button appearances as the Customizer does, the rest as text". Change the @return text to "null when a color, background or button appearance is invalid".
| public function test_set_theme_mod_rejects_button_appearance_with_malformed_color(): void { | ||
| $result = ( new Site_Set_Theme_Mod() )->execute( | ||
| array( | ||
| 'action' => 'set', | ||
| 'key' => 'nav-icon_button_appearance', | ||
| 'value' => array( | ||
| 'type' => 'fill', | ||
| 'background' => self::MALFORMED_COLOR, | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertFalse( $result['success'] ); | ||
| $this->assertSame( 'invalid_value', $result['error']['code'] ); | ||
| $this->assertFalse( get_theme_mod( 'nav-icon_button_appearance' ) ); | ||
| } |
There was a problem hiding this comment.
tests Add cases for the two new rejection paths of sanitize_button_appearance_input(). A non-array value returns null (inc/abilities/abstract_ability.php:279-281). A color field sent as an array is blanked by neve_sanitize_colors(), and blanks_sent_field() rejects it (abstract_ability.php:296-303). No test sends either. Add cases that set nav-icon_button_appearance to 'fill' and to array( 'type' => 'fill', 'background' => array( '#fff' ) ). Assert the invalid_value code and that get_theme_mod() returns false.
Summary
Improved CSS function color validation and sanitization by refining the detection regex to handle a broader range of valid and invalid color values. Expanded test coverage to cover additional edge cases and ensure more reliable color handling.
Check before Pull Request is ready:
Closes #4706 (comment)