Normalize blocklist hosts to prevent case/trailing-dot bypass#3365
Open
pfefferle wants to merge 2 commits into
Open
Normalize blocklist hosts to prevent case/trailing-dot bypass#3365pfefferle wants to merge 2 commits into
pfefferle wants to merge 2 commits into
Conversation
DNS hosts are case-insensitive and a trailing dot denotes the same absolute host, so case variants or a trailing dot could slip past a domain block. Normalize hosts (lowercase, strip IPv6 brackets, trim trailing dot) both when comparing incoming activity/actor hosts and when storing/removing blocked domains, keeping both sides canonical.
There was a problem hiding this comment.
Pull request overview
This PR hardens the domain blocklist matching logic in Moderation by normalizing hosts so attackers can’t bypass blocks using case variants (e.g., EXAMPLE.com) or a trailing FQDN dot (e.g., example.com.).
Changes:
- Added
Moderation::normalize_host()and applied it to domain block inserts/removals so stored block values are canonical. - Normalized incoming hosts during block checks in
is_actor_blocked()andcheck_activity_against_blocks()(actor/activity/object host comparisons). - Added PHPUnit coverage for normalization behavior and included a security/patch changelog fragment.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
includes/class-moderation.php |
Normalizes domain values on write and normalizes attacker-controlled hosts during domain-block comparisons. |
tests/phpunit/tests/includes/class-test-moderation.php |
Adds tests ensuring domain blocks can’t be bypassed via case or trailing-dot variants. |
.github/changelog/fix-blocklist-host-normalization |
Documents the security fix in a changelog fragment. |
Comment on lines
+345
to
349
| // Check site-wide domain blocks. Normalize the (attacker-controlled) host so a case | ||
| // variant or trailing dot cannot slip past a block; stored domains are normalized on insert. | ||
| $actor_domain = self::normalize_host( \wp_parse_url( $actor_uri, PHP_URL_HOST ) ); | ||
| if ( $actor_domain && \in_array( $actor_domain, $site_blocks['domains'], true ) ) { | ||
| return true; |
Comment on lines
+415
to
421
| // Check blocked domains. Normalize the (attacker-controlled) hosts so a case variant | ||
| // or trailing dot cannot slip past a block; stored domains are normalized on insert. | ||
| $urls = array( | ||
| \wp_parse_url( $actor_id, PHP_URL_HOST ), | ||
| \wp_parse_url( $activity->get_id(), PHP_URL_HOST ), | ||
| \wp_parse_url( object_to_uri( $activity->get_object() ) ?? '', PHP_URL_HOST ), | ||
| self::normalize_host( \wp_parse_url( $actor_id, PHP_URL_HOST ) ), | ||
| self::normalize_host( \wp_parse_url( $activity->get_id(), PHP_URL_HOST ) ), | ||
| self::normalize_host( \wp_parse_url( object_to_uri( $activity->get_object() ) ?? '', PHP_URL_HOST ) ), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes:
Domain blocklists compared hosts as raw strings, but DNS hosts are case-insensitive and a trailing dot (
example.com.) denotes the same absolute host. So a blocked domain could be slipped past with a case variant (Example.com,EXAMPLE.COM) or a trailing dot.This normalizes hosts on both sides of every comparison so the asymmetry is gone:
Moderation::normalize_host()that lower-cases, strips IPv6 brackets, and trims a trailing dot (matching the existing helper in the followers REST controller).is_actor_blocked()andcheck_activity_against_blocks()(covers the actor, activityid, and object URI hosts).add_user_block,remove_user_block,add_site_block,add_site_blocks,remove_site_block) so stored values are canonical too. Without this, a mixed-case stored domain would never match a normalized incoming host.Other information:
Testing instructions:
example.com(Settings → ActivityPub → Moderation, orModeration::add_site_block( 'domain', 'example.com' )).https://Example.com/@user,https://EXAMPLE.COM/@user, andhttps://example.com./@useris now blocked (previously these slipped through).example.org) is still allowed.Example.COM.) and confirm it is stored asexample.comand still removable.npm run env-test -- --filter=Moderation.Changelog entry
Changelog fragment included in
.github/changelog/fix-blocklist-host-normalization(Security / Patch).