Skip to content

fix: add type and data-ajax-nonce to button kses allowlist#879

Merged
superdav42 merged 2 commits intomainfrom
bugfix/kses-strips-button-nonce
Apr 15, 2026
Merged

fix: add type and data-ajax-nonce to button kses allowlist#879
superdav42 merged 2 commits intomainfrom
bugfix/kses-strips-button-nonce

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Apr 15, 2026

Summary

  • Adds type and data-ajax-nonce to the <button> allowlist in wu_kses_allowed_html(), fixing the setup wizard Network Activate button

Root Cause

The setup wizard requirements table HTML passes through wp_kses() twice — once in field-note.php (line 33) and again in default.php (line 20). The <button> element's kses allowlist only permitted disabled, name, and value.

This stripped two critical attributes from the Network Activate button:

Attribute Effect of stripping
type="button" Button defaults to type="submit", submitting the wizard form instead of firing the AJAX handler
data-ajax-nonce="..." JS reads undefined, sends no nonce → server responds {"success":false,"data":[{"code":"bad-nonce",...}]}

PR #875 correctly moved the JS to an external file and switched to _ajax_nonce / data-ajax-nonce, but the button attributes were still stripped by wp_kses() before reaching the browser.

Fix

One-line change to inc/functions/helper.php — adds type and data-ajax-nonce to the button's kses allowlist. Both are standard HTML attributes that pose no XSS risk.

Verification

Tested on http://wordpress.local:8080 setup wizard:

  • Button renders with type="button" and data-ajax-nonce="<valid>" in DOM
  • AJAX request sends _ajax_nonce=<value> in POST body
  • Server responds {"success":true}
  • Page reloads with plugin network-activated

Summary by CodeRabbit

  • Bug Fixes
    • Updated button element attribute handling to properly support additional functionality.

The setup wizard requirements table HTML passes through wp_kses()
twice (field-note.php and default.php templates). The button element's
kses allowlist only permitted disabled, name, and value — stripping
type="button" and data-ajax-nonce from the Network Activate button.

Without type="button", the click submits the parent form instead of
triggering the AJAX handler. Without data-ajax-nonce, the JS reads
undefined and the server rejects the request with bad-nonce.

PR #875 correctly moved the JS to an external file and changed the
nonce field to _ajax_nonce, but the button attributes were still
stripped before reaching the browser.
@superdav42 superdav42 added the bug Something isn't working label Apr 15, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9caf0d81-5286-474f-b0ed-6afdf7dc7f2b

📥 Commits

Reviewing files that changed from the base of the PR and between 44c629d and f860fa5.

📒 Files selected for processing (1)
  • inc/functions/helper.php

📝 Walkthrough

Walkthrough

The wu_kses_allowed_html() function in inc/functions/helper.php was modified to permit additional attributes on button elements: type and data-ajax-nonce. Existing attributes were also reordered within the allowlist.

Changes

Cohort / File(s) Summary
HTML Sanitization Allowlist Update
inc/functions/helper.php
Extended button element's allowed attributes to include type and data-ajax-nonce; reordered existing disabled, name, and value entries.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

Poem

🐰 A button grows new powers bright,
With types and nonces held just right,
The allowlist expands with care,
So AJAX whispers float through air! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding type and data-ajax-nonce attributes to the button kses allowlist, which directly addresses the root cause of the bug described in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/kses-strips-button-nonce

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 15, 2026

Performance Test Results

Performance test results for 9908421 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 40 37.78 MB 876.00 ms 163.50 ms 1066.00 ms 2042.00 ms 1953.10 ms 89.50 ms (-5.40 ms / -6% )
1 56 49.03 MB 911.50 ms (-20.00 ms / -2% ) 147.50 ms 1056.50 ms 2056.00 ms 1975.55 ms 81.85 ms

@github-actions
Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42 superdav42 merged commit 524108c into main Apr 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant