Skip to content

GH#812: fix: sanitize subdomain slug in wu_create_site#822

Merged
superdav42 merged 1 commit intomainfrom
fix/812-subdomain-slug
Apr 13, 2026
Merged

GH#812: fix: sanitize subdomain slug in wu_create_site#822
superdav42 merged 1 commit intomainfrom
fix/812-subdomain-slug

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

Summary

Resolves #812

Addresses the remaining unresolved review bot feedback from PR #755: sanitize and validate the derived subdomain slug before building the domain in wu_create_site().

Context: PR #755 was merged with 3 unaddressed CodeRabbit suggestions. Two of them (domain normalization and site_id default) were already implemented in prior work. This PR implements the third: subdomain slug sanitization.

Changes

inc/functions/site.php

  • Sanitize subdomain slug (lines 253-261): The path-derived slug is now processed through sanitize_title_with_dashes(wu_clean()) before being interpolated into a hostname. This prevents invalid characters, mixed case, and special characters from producing malformed domain names.
  • Empty slug guard: If the sanitized slug is empty (e.g., path contained only special characters like !!!), the function returns a WP_Error('invalid_site_path') instead of creating a site with an invalid domain.

tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php

  • 3 new unit tests verifying the sanitization pipeline:
    • Valid path produces correct DNS-safe slug (My Cool Site!my-cool-site)
    • Invalid-only path sanitizes to empty (guarded by WP_Error in production)
    • Unicode paths produce non-empty valid slugs

Testing

WP_TESTS_DIR=/tmp/wordpress-tests-lib vendor/bin/phpunit --no-coverage \
  --filter "test_subdomain_slug_sanitization" \
  tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php
# OK (3 tests, 6 assertions)

All 21 tests in Site_Functions_Extended_Test pass. All 18 tests in Site_Functions_Test pass.

…ostnames

Resolves #812

The subdomain slug derived from site_data['path'] was interpolated directly
into a hostname without sanitization. Malformed or special-character paths
could produce invalid domain names. Now the slug is sanitized through
sanitize_title_with_dashes(wu_clean()) and validated to be non-empty before
use, returning WP_Error for completely invalid paths.

Note: fixes 1 (domain normalization) and 3 (site_id default) from the
original review feedback were already implemented in prior PRs.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 10 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 46 minutes and 10 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e086eb76-04a3-4593-9eca-b7123b057d52

📥 Commits

Reviewing files that changed from the base of the PR and between 3dfda95 and dadb184.

📒 Files selected for processing (2)
  • inc/functions/site.php
  • tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/812-subdomain-slug

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.

@superdav42
Copy link
Copy Markdown
Collaborator Author

Merge Summary

What changed:

  • inc/functions/site.php: Sanitize subdomain slug via sanitize_title_with_dashes(wu_clean()) before hostname interpolation; return WP_Error for empty slugs
  • tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php: 3 new unit tests for slug sanitization pipeline

Why:
PR #755 review feedback identified that wu_create_site() interpolates user-supplied path data directly into hostnames without sanitization, risking malformed domains on subdomain installs.

Testing:

  • 3 new unit tests pass (6 assertions)
  • All 21 tests in Site_Functions_Extended_Test pass
  • All 18 tests in Site_Functions_Test pass (no regressions)

Risk: Low — change only affects the subdomain conversion path in wu_create_site(), adding input sanitization that was previously missing.

@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 b2b64c4 into main Apr 13, 2026
10 of 11 checks passed
@superdav42
Copy link
Copy Markdown
Collaborator Author

Merge Summary

What changed:

  • inc/functions/site.php: Sanitize subdomain slug via sanitize_title_with_dashes(wu_clean()) before hostname interpolation; return WP_Error for empty slugs
  • tests/WP_Ultimo/Functions/Site_Functions_Extended_Test.php: 3 new unit tests for slug sanitization pipeline

Why:
PR #755 review feedback identified that wu_create_site() interpolates user-supplied path data directly into hostnames without sanitization, risking malformed domains on subdomain installs.

Testing:

  • 3 new unit tests pass (6 assertions)
  • All 21 tests in Site_Functions_Extended_Test pass
  • All 18 tests in Site_Functions_Test pass (no regressions)

Risk: Low — change only affects the subdomain conversion path in wu_create_site(), adding input sanitization that was previously missing.


Merged via PR #822 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).


aidevops.sh v3.8.6 spent 11m on this as a headless bash routine.

@github-actions
Copy link
Copy Markdown

Performance Test Results

Performance test results for 77946a9 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 41 37.83 MB 860.00 ms (-54.50 ms / -6% ) 151.00 ms 1026.00 ms (-45.50 ms / -4% ) 2010.00 ms 1923.00 ms 87.00 ms
1 56 49.02 MB 952.00 ms 141.50 ms 1094.00 ms 2078.00 ms 2000.30 ms 78.30 ms

superdav42 added a commit that referenced this pull request Apr 13, 2026
…ation

Adds two integration tests to Site_Functions_Extended_Test that verify
the subdomain slug sanitization introduced in GH#812 (PR #822) works
end-to-end at the wu_create_site() API level:

- test_create_site_sanitizes_subdomain_slug: verifies that a path with
  special characters (e.g. '/My Cool Site!/') produces a sanitized
  subdomain hostname containing 'my-cool-site' and does NOT fail with
  'invalid_site_path'.

- test_create_site_returns_error_for_empty_subdomain_slug: verifies that
  a path of only invalid characters (e.g. '/!!!/') returns WP_Error with
  'invalid_site_path', preventing malformed hostnames.

To make these tests runnable in the subdirectory test environment (where
is_subdomain_install() checks the SUBDOMAIN_INSTALL constant), a new
filter 'wu_is_subdomain_install' wraps the is_subdomain_install() call
in wu_create_site(). Tests override via add_filter('wu_is_subdomain_install',
'__return_true') to force the subdomain code path without redefining constants.

Resolves #826
superdav42 added a commit that referenced this pull request Apr 13, 2026
…ation

Adds two integration tests to Site_Functions_Extended_Test that verify
the subdomain slug sanitization introduced in GH#812 (PR #822) works
end-to-end at the wu_create_site() API level:

- test_create_site_sanitizes_subdomain_slug: verifies that a path with
  special characters (e.g. '/My Cool Site!/') produces a sanitized
  subdomain hostname containing 'my-cool-site' and does NOT fail with
  'invalid_site_path'.

- test_create_site_returns_error_for_empty_subdomain_slug: verifies that
  a path of only invalid characters (e.g. '/!!!/') returns WP_Error with
  'invalid_site_path', preventing malformed hostnames.

To make these tests runnable in the subdirectory test environment (where
is_subdomain_install() checks the SUBDOMAIN_INSTALL constant), a new
filter 'wu_is_subdomain_install' wraps the is_subdomain_install() call
in wu_create_site(). Tests override via add_filter('wu_is_subdomain_install',
'__return_true') to force the subdomain code path without redefining constants.

Resolves #826
superdav42 added a commit that referenced this pull request Apr 13, 2026
…ation (#828)

Adds two integration tests to Site_Functions_Extended_Test that verify
the subdomain slug sanitization introduced in GH#812 (PR #822) works
end-to-end at the wu_create_site() API level:

- test_create_site_sanitizes_subdomain_slug: verifies that a path with
  special characters (e.g. '/My Cool Site!/') produces a sanitized
  subdomain hostname containing 'my-cool-site' and does NOT fail with
  'invalid_site_path'.

- test_create_site_returns_error_for_empty_subdomain_slug: verifies that
  a path of only invalid characters (e.g. '/!!!/') returns WP_Error with
  'invalid_site_path', preventing malformed hostnames.

To make these tests runnable in the subdirectory test environment (where
is_subdomain_install() checks the SUBDOMAIN_INSTALL constant), a new
filter 'wu_is_subdomain_install' wraps the is_subdomain_install() call
in wu_create_site(). Tests override via add_filter('wu_is_subdomain_install',
'__return_true') to force the subdomain code path without redefining constants.

Resolves #826
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review followup: PR #755 — fix: relax over-strict validation_rules() so abilities accept minimal input

1 participant