Fix domain validation regex rejecting consecutive hyphenated subdomain labels#221
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix double-hyphen issue in subdomain denylist
Fix domain validation regex rejecting consecutive hyphenated subdomain labels
Jul 8, 2026
ssl
approved these changes
Jul 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the allowlist/denylist domain validation in Payload::setList() to stop rejecting domains that contain hyphens in multiple different subdomain labels (e.g., something-one.something-two.sub.root.com) by replacing the previous complex, position-dependent regex with a simpler per-label pattern.
Changes:
- Replaced the domain-validation regex used when adding allowlisted/denylisted domains.
- Normalized validation to apply the same label rules at every dot-separated label position (including hyphen handling) while still disallowing
**.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Validate domain string | ||
| if (!preg_match('/^(?:(?:(?!\*)[a-zA-Z\d][a-zA-Z\d\-*]{0,61})?[a-zA-Z\d]\.){0,1}(?!\d+)(?!.*\*\*)[a-zA-Z\d*]{1,63}(?:\.(?:(?:(?!\*)[a-zA-Z\d][a-zA-Z\d\-*]{0,61})?[a-zA-Z\d]\.){0,1}(?!\d+)(?!.*\*\*)[a-zA-Z\d*]{1,63})*$/', $domain)) { | ||
| if (!preg_match('/^(?!.*\*\*)(?:[a-zA-Z\d*](?:[a-zA-Z\d\-*]{0,61}[a-zA-Z\d*])?\.)*[a-zA-Z\d*](?:[a-zA-Z\d\-*]{0,61}[a-zA-Z\d*])?$/', $domain)) { |
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.
The denylist/allowlist domain validator incorrectly rejects domains where hyphens appear in two different subdomain labels (e.g.
something-one.something-two.sub.root.com), while accepting hyphens within a single label (e.g.something.something-one-two.sub.root.com).Root cause
The regex in
Payload::setList()had a flawed structure that interleaved "hyphenated label" and "non-hyphenated label" matchers:After consuming
something-one.as the leading hyphenated label, the next segment required a hyphen-free label — causingsomething-twoto fail at its hyphen.Fix
Replace the complex regex with a straightforward per-label pattern that uniformly handles all labels regardless of position:
Each label must start and end with an alphanumeric or
*(no leading/trailing hyphens), with hyphens and wildcards permitted in the middle. Double wildcards (**) remain prohibited.