Skip to content

Validated header and footer row text colors - #4710

Open
girishpanchal30 wants to merge 6 commits into
developmentfrom
bugfix/4708
Open

girishpanchal30 wants to merge 6 commits into
developmentfrom
bugfix/4708

Conversation

@girishpanchal30

Copy link
Copy Markdown
Contributor

Summary

Strengthened sanitization and validation of row text and background color settings in the header and footer builder by introducing a consistent approach across Customizer settings, theme mod storage, and dynamic CSS output. Ensured that only valid color values are accepted and rendered, and added comprehensive unit tests covering sanitization, validation, and output behavior.

Check before Pull Request is ready:

Closes #4708

@pirate-bot

pirate-bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Plugin build for a86a3f4 is ready 🛎️!

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes requested

The text color fix works, but other row and ability values still print raw into CSS, and Configure hides rejected colors.

  • header-footer-grid/Core/Builder/Abstract_Builder.php:2063 — security ✓ Verified in the sandbox The footer row Vertical Alignment setting has the same flaw as the Text Color fix. It uses wp_filter_nohtml_kses, which only strips tags. Its value is printed raw as --valign. A user without unfiltered_html can save top;}body{background:lime}/*, and the front end prints --valign: top;}body{background:lime}/*. Replace the callback with one that accepts only the radio choices (flex-start, center, flex-end). Add a META_FILTER on --valign that falls back to the default for stored values. Add a case to tests/test-neve-row-text-color.php that saves the payload and asserts that lime is not in the CSS.
  • header-footer-grid/Core/Builder/Abstract_Builder.php:1067-1069 — security ✓ Verified in the sandbox A stored row background color still prints raw. Before this PR, Header and Footer Configure saved background.colorValue with only sanitize_text_field, so sites can already hold #222;}body{background:lime}/* there. The new --color filter covers stored text colors for this reason, but --bgcolor and --overlaycolor have no filter. The front end prints --bgcolor: #222;}body{background:lime}/*;. Add a META_FILTER to --bgcolor and --overlaycolor that runs neve_sanitize_colors() and falls back to the default. Add an output case that stores the payload in hfg_footer_layout_main_background and asserts that lime is not in the CSS.
  • inc/abilities/appearance_update.php:428-441 — security ✓ Verified in the sandbox The neve/appearance-update ability stores fontWeight with no validation. A body fontWeight of 400;}body{background:lime}/* prints --bodyfontweight: 400;}body{background:lime}/*; on the front end. Heading and button weights take the same path. Accept only the numeric weights 100 to 900 (and normal, bold) for every typography target, and reject anything else with a validation error. Add a test that sends the payload for the body, a heading and the button, and asserts that lime is not in the CSS.
Validation details
  • Files reviewed: 5/5 changed files. Unchecked rows: issue #3820 PHPStan; precedent #4678 suffix-based sanitizer shapes; Failure direction: Causes, Too permissive, Too strict, Direction.
  • The new tests pass at HEAD (run R8) and fail on the base tree (run R9), PHP 8.3, WordPress 7.1.5.
  • Payload runs on the other paths ran at HEAD and base (runs R14 and R15).
  • Font family and allowlisted dimension keys in the abilities also print raw values. Those paths predate this change (run R18).
Untested areas
  • PHPStan was not installed, so issue #3820 PHPStan was not checked.
  • Precedent #4678 suffix-based sanitizer shapes: filter-added allowlist keys were not checked.
  • Failure direction: Causes, Too permissive, Too strict, Direction: legacy background shapes from older versions were not checked.
  • Customizer font family settings were not executed.

🤖 Automated review · run code-review-agent_6afff007a00e61.28722729.


🤖 Review agent — review posted ✅ on 13855e1c · changes requested · 5 findings · 42 min

Run code-review-agent_6afff007a00e61.28722729 · trail

Comment thread inc/abilities/builder_configure.php Resolved
Comment thread inc/abilities/builder_configure.php Resolved
@girishpanchal30

Copy link
Copy Markdown
Contributor Author

Review item F4: Valid finding, but outside this PR: inc/abilities/appearance_update.php isn't changed here, and the gap isn't limited to fontWeight — apply_typography() merges every element prop (size, line height, letter spacing, transform, weight) into the theme mod raw. Fixing just the weight would be a partial fix, so this belongs in its own issue, sanitizing the merged props with the Customizer's typography sanitizer. Your own validation notes also list the font family path as predating this change.

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes requested

The row height, alignment, background and warning fixes work, but the appearance ability still prints font weight and font family raw into CSS.

  • inc/abilities/appearance_update.php:441 — security ✓ Verified in the sandbox This is still open from the earlier review. The neve/appearance-update ability stores fontWeight with no validation. A body fontWeight of 400;}body{background:lime}/* prints --bodyfontweight: 400;}body{background:lime}/*; on the front end. Heading and button weights take the same path. Accept only the numeric weights 100 to 900 (and normal, bold) for every typography target. Reject anything else with a validation error. Add a test that sends the payload for the body, a heading and the button, and asserts that lime is not in the CSS.
  • inc/abilities/appearance_update.php:425 — security The neve/appearance-update ability stores the body and heading font family with only sanitize_text_field. That function keeps Arial;}body{background:lime}/*, because the value has no tags or spaces to strip. The CSS output prints a family without spaces unquoted, so the front end gets --bodyfontfamily: Arial;}body{background:lime}/*;. The font weight fix does not cover this field. Reject a font family that contains ;, {, }, (, ) or /* with a validation error. Add a test that sends the payload for the body and a heading, and asserts that lime is not in the CSS.
Validation details
  • Files reviewed: 8/8 changed files. Unchecked rows: issue #3820 PHPStan; Failure direction: Causes, Too permissive, Too strict, Direction, Visibility.
  • The row tests pass at HEAD set -o pipefail; cd /var/www/html/wp-content/themes/neve; timeout 280 phpunit --do-not-cache-result --filter 'TestNeveRo… printed OK (8 tests, 42 assertions) (run R7) and fail on the base tree set -o pipefail; cd /var/www/html/wp-content/themes/neve-base; timeout 280 phpunit --do-not-cache-result --filter 'TestN… printed Tests: 8, Assertions: 10, Failures: 8. (run R5).
  • The footer alignment and row background fixes from the earlier review are confirmed by these tests.
  • The font weight payload still reaches the CSS at HEAD set -o pipefail; mkdir -p /workspace/checks/C1/c; cd /var/www/html/wp-content/themes/neve; sed 's#/workspace/checks/C11/… printed "lime_in_css": true (run R8).
  • The font family result reuses run code-review-agent_6afff007a00e61.28722729, not rerun.
  • Question: CONTRIBUTING.md puts unit tests in tests/php/unit, but phpunit.xml runs tests/. Should the document change?
Untested areas
  • PHPStan could not be installed, so issue #3820 PHPStan was not checked.
  • Failure direction: Causes, Too permissive, Too strict, Direction, Visibility were not settled for the background rejection.
  • Older stored footer alignment values were not found.
  • Dimension keys in the theme mod ability were not checked.
  • The variant pass did not settle these places, where the fixed cause may still reach:
    • header-footer-grid/Core/Builder/Abstract_Builder.php:1039-1042,1062-1065,1075-1077,2100-2105 — unverified: Text color, --bgcolor and --overlaycolor now have output guards, including for already-stored values. Complete validation depends partly on WordPress sanitize_hex_color; installed …
    • globals/sanitize-functions.php:69-97 — unverified: Text color, --bgcolor and --overlaycolor now have output guards, including for already-stored values. Complete validation depends partly on WordPress sanitize_hex_color; installed …
    • header-footer-grid/Core/Components/Abstract_Component.php:686-689,824-837 — unverified: Component/global font-family paths remain unchanged. A no-space declaration-breaking string remains unquoted by the formatter; whether the installed sanitize_text_field preserves i…
    • inc/core/styles/css_vars.php:252-255,282-284 — unverified: Component/global font-family paths remain unchanged. A no-space declaration-breaking string remains unquoted by the formatter; whether the installed sanitize_text_field preserves i…
    • inc/core/styles/css_prop.php:383-415 — unverified: Component/global font-family paths remain unchanged. A no-space declaration-breaking string remains unquoted by the formatter; whether the installed sanitize_text_field preserves i…
    • inc/abilities/site_set_theme_mod.php:26-51,175-185,201-210 — unverified: Allowlisted sidebar/form/scroll-to-top dimensions still bypass color/background validation. The prior responsive/directional/unit candidates remain unresolved pending installed san…
    • inc/abilities/abstract_ability.php:246-259 — unverified: Allowlisted sidebar/form/scroll-to-top dimensions still bypass color/background validation. The prior responsive/directional/unit candidates remain unresolved pending installed san…

🤖 Automated review · run code-review-agent_6b000d0d667fd0.35707748.


🤖 Review agent — review posted ✅ on cc3240a7 · changes requested · 2 findings · 20 min

Run code-review-agent_6b000d0d667fd0.35707748 · trail

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes requested

The font weight fix works, but font family, nested colors and dimension values from two abilities still reach the CSS unchecked.

Validation details
  • Files reviewed: 2/2 files changed since the last review. Unchecked rows: issue #3820 PHPStan; Failure direction: Causes, Too permissive, Too strict, Direction, Visibility.
  • The new font test passes at HEAD set -o pipefail; rsync -a --delete --exclude .git /repo/ /var/www/html/wp-content/themes/neve/ && cd /var/www/html/wp-co… printed OK (2 tests, 25 assertions) (run R4) and fails on the base tree cd /workspace/checks/R1; set -o pipefail; timeout 290 sandbox-phpunit-ab.sh /workspace/checks/R1/head 80458289bc2be8c0ba… (run R19, exit 0).
  • Invalid font weights now return ability_invalid_input through the run route, dispatched in process `cd /workspace/checks/R1/head; cat > tests/test-r1-rest-probe.php <<'EOF'
Untested areas - PHPStan could not be installed, so issue #3820 PHPStan was not checked. - Failure direction: Causes, Too permissive, Too strict, Direction, Visibility were not settled for the background rejection. - The theme is not active over HTTP in the sandbox. REST checks ran in process.
🤖 Automated review · run code-review-agent_6b0016ce5e7373.74406880. --- **🤖 Review agent** — review posted ✅ on `c70cf3be` · [changes requested · 4 findings](https://github.com//pull/4710#pullrequestreview-5990839865) · 14 min Run `code-review-agent_6b0016ce5e7373.74406880` · [trail](https://agents.vertistudio.com/admin/trails/github-pr/Codeinwp-neve-4710)

Comment thread inc/abilities/appearance_update.php Resolved
Comment thread inc/abilities/site_set_theme_mod.php Resolved
Comment thread inc/abilities/appearance_update.php Resolved
Comment thread inc/abilities/site_set_theme_mod.php Resolved

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes requested

The four earlier findings are fixed, but five other Customizer and ability paths still let a saved value close its CSS rule.

  • globals/sanitize-functions.php:256 — security ✓ Verified in the sandbox The Customizer path still stores CSS-closing button colors. neve_sanitize_button_appearance() returns its value unchanged. The registered sanitizer of nav-icon_button_appearance keeps a background of #222;}body{background:lime}/*, and set_theme_mod() stores it. The generated CSS then contains --bgcolor: #222;}body{background:lime}/*;. This PR now rejects that value for nav-icon_button_appearance in neve/site-set-theme-mod, but not in the Customizer. This code was already present before this PR. Validate background and text with neve_sanitize_colors() in this function. Add a Customizer-save test that asserts lime is not in the CSS.
  • globals/sanitize-functions.php:294 — security The Customizer path still stores CSS-closing component line heights. neve_sanitize_typography_control() only checks that lineHeight, letterSpacing and fontSize are arrays. It does not check the values inside them. A Customizer save with lineHeight.mobile set to 1;}body{background:lime}/* keeps the value. CSS_Prop then prints it raw in the responsive rule, so the generated CSS gets a new body rule. This code was already present before this PR. Validate each responsive value as a number and each suffix as an allowed unit here. Add a Customizer-save test that asserts lime is not in the CSS.
  • header-footer-grid/Traits/Core.php:135 — security The Customizer path still stores CSS-closing component padding and margin values. The array branch of sanitize_spacing_array() returns its input unchanged. A Customizer save with a side such as top set to 1;}body{background:lime}/* keeps the value. CSS_Prop concatenates each side into the directional rule, so the generated CSS gets a new body rule. This code was already present before this PR. Cast each side to a number and allow only known units here. Add padding and margin Customizer-save tests that assert lime is not in the CSS.
  • header-footer-grid/Core/Components/Abstract_Component.php:847 — security ✓ Verified in the sandbox The Customizer path still stores CSS-closing component font families. The font family setting uses only sanitize_text_field(), which keeps ;, { and }. The registered sanitizer of primary-menu_component_font_family keeps Arial;}body{background:lime}/*, and set_theme_mod() stores it. The generated CSS then contains --fontfamily: Arial;}body{background:lime}/*;. This code was already present before this PR. Use a sanitize callback that rejects a font family containing ;, {, }, < or /*, like the PR's FONT_FAMILY_PATTERN. Add a Customizer-save test that asserts lime is not in the CSS.
  • inc/abilities/schema_helpers.php:144 — security ✓ Verified in the sandbox neve/appearance-update still prints an undeclared radius unit raw. box_model_schema() declares only the four sides and does not set additionalProperties: false. So WordPress accepts an extra unit key. A buttons.primary.radius.unit of px;}body{background:lime}/* is merged into neve_button_appearance unchanged. The generated CSS contains --primarybtnborderradius:3px;}body{background:lime}/*;. This code was already present before this PR. Set 'additionalProperties' => false in box_model_schema(), or declare unit with an enum of allowed units. Add a test that sends this payload and asserts lime is not in the CSS.
Validation details
  • Files reviewed: 6/6 files changed since the last review. Unchecked rows: issue #3820 PHPStan; Appearance_Update::button_schema() return changed; Appearance_Update::get_input_schema() return changed; Failure direction: Visibility.
  • The new tests pass at HEAD mkdir -p /workspace/checks/R2b; set -o pipefail; F='test_font_weight_none_is_saved|test_font_families_reject_text_escape… printed OK (4 tests, 48 assertions) (run R8). Three of them fail on the base tree mkdir -p /workspace/checks/R2b; set -o pipefail; F='test_font_weight_none_is_saved|test_font_families_reject_text_escape… printed Tests: 4, Assertions: 9, Failures: 3. (run R8).
  • The Customizer sanitizer probe ran at HEAD `mkdir -p /workspace/checks/V3 && cat > /workspace/checks/V3/test-v3-probe.php <<'EOF'
Untested areas - PHPStan is not installed, so issue #3820 PHPStan was not checked. - Appearance_Update::button_schema() return changed, Appearance_Update::get_input_schema() return changed and Failure direction: Visibility were not settled. - Footer and secondary menu font families were not placed in the layout, so their CSS was not run. - The site is not served over HTTP. All checks ran in PHPUnit. - The variant pass did not settle these places, where the fixed cause may still reach: - `inc/abilities/appearance_update.php:439-448,518-566` — unverified: Numeric fields and enums constrain declared properties, but merged objects preserve incoming properties. Explore should verify version-matched WordPress validation of undeclared fi…
🤖 Automated review · run code-review-agent_6b001eced7d001.28335018. --- **🤖 Review agent** — review posted ✅ on `0a6a267b` · [changes requested · 5 findings](https://github.com//pull/4710#pullrequestreview-5991397771) · 27 min Run `code-review-agent_6b001eced7d001.28335018` · [trail](https://agents.vertistudio.com/admin/trails/github-pr/Codeinwp-neve-4710)

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes requested

The five earlier findings are fixed, but the new dimension sanitizer erases the "No unit" line height choice of header and footer components.

Validation details
  • Files reviewed: 8/8 files changed since the last review. Unchecked rows: issue #3820 PHPStan; Builder_Configure::get_builder() return changed; Schema_Helpers::box_model_schema() return changed; Failure direction: Causes, Too strict and Visibility.
  • The six new tests pass at HEAD set -o pipefail; cd /workspace/checks/R1 && rm -rf src && mkdir -p src && git clone -q --no-hardlinks /repo src/neve 2>&… printed OK (6 tests, 40 assertions) (run R6). Each fails on the base tree set -o pipefail; cd /workspace/checks/R1 && rm -rf base && mkdir base && cp -a src/neve base/neve && cd base/neve && git… printed Failures: 6 (run R7).
  • A component line height saved with "No unit" stores an empty suffix at HEAD [R10] and — on the base tree [R11]. Both print --lineheight: 1.6;.
Untested areas
  • PHPStan is not installed.
  • Stored palette, blog card and archive values print raw if a delimiter is already stored. Their writers were not traced.
  • Malformed colors such as rgb(1) still pass the unchanged color sanitizer. Whether the PR promises full color validity was not settled.
  • The Customizer screen was not opened. All runs used PHPUnit.
  • The variant pass did not settle these places, where the fixed cause may still reach:
    • inc/abilities/appearance_update.php:439-448,518-566 — unverified: Carried-forward merged-object question: incoming undeclared properties survive the local merges, but declaring injection reachable requires the installed WordPress Abilities API’s …

🤖 Automated review · run code-review-agent_6b0028ae8242e3.99148280.


🤖 Review agent — review posted ✅ on 10422d2c · changes requested · 2 findings · 32 min

Run code-review-agent_6b0028ae8242e3.99148280 · trail

Comment thread globals/sanitize-functions.php Resolved
Comment thread inc/core/styles/css_prop.php Resolved

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approved

The PR passes. The "No unit" line height fix and the new getter test resolve both earlier findings.

Validation details
  • Files reviewed: 3/3 files changed since the last review. Unchecked rows: issue #3820 PHPStan; issue #3300 background alignment warning; Builder_Configure::get_builder() return changed; Failure direction: Causes, Too strict and Visibility.
  • PHPUnit at HEAD printed cd /workspace/checks/R1; rm -rf head ten prb; for p in "t-head head" "t-10422 ten" "t-prbase prb"; do set -- $p; mkdir -… printed OK (7 tests, 40 assertions) (run R5).
  • With the 10422d2 code, the run printed cd /workspace/checks/R1; grep -E "✘|✔" run-10422-nontest.log; grep -n "Failed\|Error" run-10422-nontest.log | head -5; e… printed ✘ No unit line height is kept (run R7).
  • Without the getter css_unit() calls, the run printed cd /workspace/checks/R1; rm -rf mut; mkdir mut; cp -a head/neve mut/; cp -a head/neve/vendor mut/neve/ 2>/dev/null; f=mu… printed ✘ Responsive unit getters reject stored units (run R8).
  • Extra ability properties reach CSS only through css_unit(), which falls back to px.
Untested areas
  • PHPStan is not installed.
  • The unchecked rows above were not settled.
  • The variant and requirements passes were not rerun.
  • Legacy font values copied by Mods_Migrator were not checked for strings such as 16px.
  • The Customizer screen was not opened.
Questions for the author
  • Can stored typography or spacing settings hold strings such as 10px? neve_sanitize_css_dimensions() clears them.

🤖 Automated review · run code-review-agent_6b00321e3a1519.31229138.


🤖 Review agent — review posted ✅ on a86a3f45 · approved · 0 findings · 25 min

Run code-review-agent_6b00321e3a1519.31229138 · trail

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants