Fixes #39287 - validate domain name format#10977
Open
Alleny244 wants to merge 1 commit intotheforeman:developfrom
Open
Fixes #39287 - validate domain name format#10977Alleny244 wants to merge 1 commit intotheforeman:developfrom
Alleny244 wants to merge 1 commit intotheforeman:developfrom
Conversation
f0c6993 to
933b749
Compare
chris1984
reviewed
May 7, 2026
| include ParameterSearch | ||
| validates :name, :presence => true, :uniqueness => true | ||
| validates :name, :presence => true, :uniqueness => true, | ||
| :format => {:with => Net::Validations::HOST_REGEXP, :message => N_(Net::Validations::DOMAIN_NAME_FORMAT_ERR_MSG)} |
Member
There was a problem hiding this comment.
DOMAIN_NAME_FORMAT_ERR_MSG is already defined as N_(...) in validations.rb:13. Wrapping it again with N_() is redundant.
Suggested change
| :format => {:with => Net::Validations::HOST_REGEXP, :message => N_(Net::Validations::DOMAIN_NAME_FORMAT_ERR_MSG)} | |
| :format => {:with => Net::Validations::HOST_REGEXP, :message => Net::Validations::DOMAIN_NAME_FORMAT_ERR_MSG} |
ekohl
reviewed
May 7, 2026
Member
ekohl
left a comment
There was a problem hiding this comment.
What about data in the database that is already invalid? Have you considered how users deal with that?
| MASK_REGEXP ||= /\A((255.){3}(0|128|192|224|240|248|252|254))|((255.){2}(0|128|192|224|240|248|252|254).0)|(255.(0|128|192|224|240|248|252|254)(.0){2})|((128|192|224|240|248|252|254)(.0){3})\z/ | ||
|
|
||
| HOST_REGEXP_ERR_MSG = N_("hostname can contain only lowercase letters, numbers, dashes and dots according to RFC921, RFC952 and RFC1123") | ||
| DOMAIN_NAME_FORMAT_ERR_MSG = N_("domain name can contain only lowercase letters, numbers, dashes and dots according to RFC921, RFC952 and RFC1123") |
Member
There was a problem hiding this comment.
Domain names are case insensitive. It confuses me a bit why HOST_REGEXP does enforce lower case.
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.
Why
Domain names were validated only for presence/uniqueness in the
Domainmodel.This allowed invalid characters and malformed values to be accepted.
What changed
Domain#nameusingNet::Validations::HOST_REGEXPNet::Validations::DOMAIN_NAME_FORMAT_ERR_MSGdomain_testwith:example.com)Example.com,example_domain.com)*,*.*,*.example.com,example.*.com,!!!,example..com, etc.)Test plan
Steps
bundle exec rails test test/models/domain_test.rbExpected result