Repository navigation
Enhanced RGBA color validation - #4718
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
There was a problem hiding this comment.
🟡 Changes requested
The earlier docblock, test, row color and hex findings are fixed, but the appearance ability now stores button colors with extra CSS.
inc/core/styles/css_prop.php:227-242—correctnessColors stored before this fix, or written by an importer, are still printed without the color check. The custom property branch interpolates the stored value as it is. The palette output ininc/core/dynamic_css.php:179-220concatenates palette values the same way. So a savedrgb(1.2.3,4,5)row, button or palette color keeps printing after the update. Templates Patterns Collection importstheme_modsandtheme_mods_nevewithout Neve's sanitizers, with the same effect. Run color values throughneve_sanitize_colors()before they are printed as custom properties and palette variables. Add a test that stores a malformed color mod and expects the generated CSS to omit it.
Questions for the author
- Can any producer or stored setting supply gradient stops such as
hsl(120deg, 50%, 50%)orrgb(var(--r),0,0)? The new gradient check now rejects both forms, which earlier versions saved.
Validation details
- Files reviewed: 7/7 files changed since the prior review. The row "consumer: neve_sanitize_button_appearance() return changed" stays unchecked.
- The color tests pass at HEAD in a clean copy:
OK (27 tests, 228 assertions)(run R10). - The appearance ability stores the extra CSS:
CSS_HAS_BODY_DISPLAY_NONE yes(run R13). - The child theme copy keeps a bad palette color:
CHILD_PRIMARY_ACCENT "rgb(1.2.3,4,5)"(run R13).
Untested areas
- The row "consumer: neve_sanitize_button_appearance() return changed" was not settled.
- The stored-value output path was traced in source only.
- The Beaver Builder palette consumer was not read.
- Only WordPress 5.5 and 7.1 were read.
- The test suite does not load in
/repo. A clean copy passes.
🤖 Automated review · run code-review-agent_6b058dbc0b5838.96589553.
🤖 Review agent — review posted ✅ on 413f6857 · changes requested · 5 findings · 38 min
Run code-review-agent_6b058dbc0b5838.96589553 · trail
There was a problem hiding this comment.
🟡 Changes requested
The four earlier findings in threads are fixed, but child-theme migration now blanks the search button mode, and stored colors still print unchecked.
inc/core/styles/css_prop.php:240-246—correctnessColors stored before this fix still print without the color check in three more places. The box-shadow filter returns atinc/core/styles/css_prop.php:74-80, before this check. So a storedshadowColorofrgba(0,0,0,.5);}body{display:none}prints in--primarybtnshadowand closes the rule (inc/core/styles/css_vars.php:85-144,header-footer-grid/Core/Components/Button.php:259-285). Elementor global colors print stored palette colors unchanged (inc/compatibility/elementor.php:115-131,380-391). The palette switch prints its palettes unchanged (header-footer-grid/Core/Components/PaletteSwitch.php:202-221,239-246,284-300). Sanitize the color where these values are read, or in one shared reader. Add a test that stores a bad color for each printer.
Validation details
- Files reviewed: 8/8 files changed since the prior review. The "Failure direction" rows (Causes, Too permissive, Too strict, Direction, Persistence, Recovery, Visibility) stay unchecked.
- The three color test files pass in a copy of HEAD:
cd /tmp/opencode/c6/repo; set -o pipefail; for pair in "sanitization:TestSanitization" "ability-color-inputs:TestNeveAbi…printedOK (16 tests, 176 assertions)(run R6) - Child-theme migration blanks
header_search_button_appearance:cd /workspace/checks/C7/probe && python3 - <<'EOF' p='C7ProbeTest.php' s=open(p).read() s=s.replace(" add_filter( 'styl…(run R12, exit 0) - A stored shadow color prints with the extra CSS:
cd /workspace/checks/C7/probe && python3 - <<'EOF' p='C7ProbeTest.php' s=open(p).read() s=s.replace(" public function te…(run R10, exit 0)
Untested areas
- The "Failure direction" rows for the button background fallback were not rechecked.
- The Elementor and palette switch printers were traced in source only.
- Beaver Builder palette presets were not read past normalization.
- Imported palette slugs with uppercase letters would be dropped. No such import was found.
- The suite does not load in
/repo. A copy passes. - The variant pass did not settle these places, where the fixed cause may still reach:
inc/compatibility/beaver.php:138-176— unverified: Stored malformed colors reach Beaver presets unchanged. Beaver Builder Lite 2.11.2.2 (/deps/plugins/beaver-builder-lite-version/latest/fl-builder.php:6) normalizes filtered presets…
🤖 Automated review · run code-review-agent_6b066ea7a5b743.08935689.
🤖 Review agent — review posted ✅ on e73fc8ef · changes requested · 3 findings · 25 min
Run code-review-agent_6b066ea7a5b743.08935689 · trail
There was a problem hiding this comment.
🟢 Approved
This approves the PR because the earlier findings are fixed; the note asks a developer to confirm that no importer writes unsafe custom color keys.
inc/core/front_end.php:625—notecss_global_custom_colors()prints each storedneve_global_custom_colorskey raw into selectors andvar(--…). A stored key such ascustom-1);color:red}body{display:none}/*closes the rule in the generated CSS. The Customizer drops such keys, and the:rootprinter now drops them too. Can any importer or migration still write custom color keys withoutsanitize_global_custom_colors()? If none can, this is safe. If one can, filter the keys here as well.
Validation details
- Files reviewed: 11/11 files changed since the prior review. The rows "Button::add_style() return changed" and "neve_sanitize_button_appearance() return changed" stay unchecked.
- The three changed test classes pass at HEAD in a copy of the theme:
cd /tmp/opencode/c1/repo && set -o pipefail; for c in TestSanitization TestNeveCssStyleTags TestElementorCompatibility; …printedOK (16 tests, 180 assertions)(run R3) - With the non-test files from e73fc8e, the new assertions fail for the gradient suffix, the search button mode, the shadow, the palette switch and Elementor:
cd /tmp/opencode/c1/prior/repo && set -o pipefail; for c in TestSanitization TestNeveCssStyleTags TestElementorCompatibi…printedTests: 16, Assertions: 170, Failures: 2.(run R4) - A stored unsafe custom color key still prints raw in the front-end CSS:
set -o pipefail; cd /tmp/opencode/c1/repo && ls -la /workspace/checks/C9/ && timeout 300 phpunit --do-not-cache-result -…printedHAS_display_none_in_FRAG: yes(run R6)
Untested areas
- The rows "Button::add_style() return changed" and "neve_sanitize_button_appearance() return changed" were not settled.
- Beaver Builder palette presets were not traced to their CSS output.
- No importer that writes custom color keys directly was found or ruled out.
- The Customizer button presets and preview scripts were not traced.
- The variant pass did not settle these places, where the fixed cause may still reach:
inc/compatibility/beaver.php:138-176— unverified: Both palette sources still return unchecked presets. Beaver Builder Lite 2.11.2.2 (/deps/plugins/beaver-builder-lite-version/latest/fl-builder.php:6) normalizes after this filter (…- not reached: Customizer-preview producer validation before assets/js/src/customizer-preview/css-var-handler.js:118-146,307-350,440-449
🤖 Automated review · run code-review-agent_6b06779a4f1e05.30507687.
🤖 Review agent — review posted ✅ on d6a4bd0b · approved · 0 findings · 34 min
Run code-review-agent_6b06779a4f1e05.30507687 · trail
|
@girishpanchal30 #4718 now conflicts with I tried merging
Most of it combines cleanly: keep this PR's color, background and button-appearance checks, and add #4710's dimension loop in One behaviour contradicts. When an ability sends a background with one malformed color:
Which one do you want? Also note that |
d6a4bd0 to
57c4383
Compare
There was a problem hiding this comment.
🟡 Changes requested
Switching to a child theme now drops the palette switch auto-adjust setting. Fix the migration check before merge.
Questions for the author
- Is any non-array value other than a JSON object string a supported button appearance?
neve_sanitize_button_appearance()now returns''for it.
Validation details
- Files reviewed: 15/15 changed files. Six history and checklist questions stayed unchecked; they are named under Untested areas.
- The migration skip ran in isolation on PHP 8.3:
sed -n '1,175p' /repo/globals/sanitize-functions.php > /workspace/checks/C14/sanitize-functions.php { printf '<?php\n'; …printedtoggle skipped: yes(run R1)
Untested areas
- These questions were not settled: "Button border radius removal (#3565)", "Add to cart button regression (#3570)", "Elementor global colors consistency (#4633)", "Stricter gradient validator blanking values", "Color check on stored CSS variables", "Failure direction: Causes".
- The Customizer preview prints stored palette colors raw. A visible effect was not shown.
- Beaver Builder palette presets and Neve Pro mods were not traced.
- The variant pass did not settle these places, where the fixed cause may still reach:
assets/js/src/customizer-preview/css-var-handler.js:118-146,307-350,440-449— unverified: Background, overlay and both shadow colors are interpolated without validation; sibling direct-color and button handlers also interpolate values at assets/js/src/customizer-preview…inc/compatibility/beaver.php:138-176— unverified: Registered at lines 25-27, this exports stored palette colors and custom val fields after only removing #. Beaver Builder Lite 2.11.2.2 (/deps/plugins/beaver-builder-lite-version/l…
🤖 Automated review · run code-review-agent_6b07c956330ba5.88243567.
🤖 Review agent — review posted ✅ on 57c43835 · changes requested · 1 finding · 40 min
Run code-review-agent_6b07c956330ba5.88243567 · trail
There was a problem hiding this comment.
🟢 Approved
This approves the PR because the child-theme migration now keeps the palette switch toggle, and the earlier findings are fixed.
Validation details
- Files reviewed: 15/15 changed files. Five questions stayed unchecked: "neve_sanitize_button_appearance() return changed", "Add to cart button regression (#3570)", "Array to string conversion warning (#3406)", "Failure direction: Causes" and "Failure direction: Too strict".
- The migration test passes at this commit:
cd /repo && set -o pipefail; timeout 290 php /workspace/checks/C2/run-one.php 2>&1 | tee /workspace/checks/C2/run-one.lo…printedRESULT run=1 failures=0 errors=0 risky=0 skipped=0(run R17) - With the old migration code, the same test fails:
cd /repo && git show 57c438357f0411f2a679f9802e694e46985ba8b9:inc/core/admin.php > /workspace/checks/C2/themes/neve/inc/…printedFailed asserting that false is identical to 1.(run R19) - The sanitization test class passes: `cd /repo && cat > /workspace/checks/C2/run-class.php <<'EOF'
Untested areas
- The five questions named above were not settled. - Customizer preview color handlers and the Beaver Builder palette export were not traced to a visible effect. - No producer of palette colors with surrounding spaces was found. An import that stores one would lose that color. - The repository-wide PHPUnit run fails to load in the sandbox. A custom entry script ran the class instead. - The variant pass did not settle these places, where the fixed cause may still reach: - `assets/js/src/customizer-preview/app.js:378-443` — unverified: preview handlers interpolate background, overlay, button and shadow colors into style.innerHTML without equivalent validation. The decisive remaining fact is whether an ordinary co… - `assets/js/src/customizer-preview/css-var-handler.js:117-146,294-350,364-369,440-449` — unverified: preview handlers interpolate background, overlay, button and shadow colors into style.innerHTML without equivalent validation. The decisive remaining fact is whether an ordinary co… - `inc/compatibility/beaver.php:138-176` — unverified: stored palette and custom colors leave Neve unchecked. Beaver Builder Lite 2.11.2.2 preserves non-hex presets (/deps/plugins/beaver-builder-lite-version/latest/classes/class-fl-bui…|
@vytisbulkevicius I have resolved the conflict. I rebased the branch onto
On the behaviour conflict, I went with this PR's behaviour: when an ability sends a background with a malformed color, the whole background is rejected. |
|
🎉 This PR is included in version 4.2.20 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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)