Skip to content

Add validator for IP address/inet columns

Drew Blessing requested to merge dblessing-ip-address-validator into master

What does this MR do?

Adds an IP Address validator, for use alongside the PostgreSQL inet column type.

I wanted to add this validator as part of !39652 (merged), but the MR would have been too lengthy. I decided it wasn't a necessary piece to the MVC and followed up on that here.

When using column type inet Rails will silently return the value as nil when the value is not valid according to its type cast using IpAddr. See https://github.com/rails/rails/pull/11574#issuecomment-21453340 for the PR and comment which suggested this behavior. I guess it is also the case for created_at/updated_at timestamps, although it's not as common to validate those so I have never encountered this before.

It's not very user friendly to return an error "IP Address can't be blank" when a value was clearly given but was not the right format. This validator will look at the value before Rails type casts it when the value itself is nil. This enables the validator to return a specific and useful error message.

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Drew Blessing

Merge request reports

Loading