Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipv6 string with mask between 33 and 128 are rejected. #1232

Closed
JosephCaillet opened this issue Jun 30, 2017 · 0 comments · Fixed by #1235
Closed

ipv6 string with mask between 33 and 128 are rejected. #1232

JosephCaillet opened this issue Jun 30, 2017 · 0 comments · Fixed by #1235
Labels
bug Bug or defect
Milestone

Comments

@JosephCaillet
Copy link

Context

  • node version: 4.2.6
  • joi version: 10.6.0
  • environment (node, browser): node
  • used with (hapi, standalone, ...): hapi
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

When using Joi to validate ipv4 string and ipv6 string, there is a problem with cidr subnet mask : it cannot go over /32, witch is good for ipv4, but for ipv6 it can go up to /128.
Here is a little code to illustrate:

'use strict'

const Joi = require('joi')
const Hapi = require('hapi')

const server = new Hapi.Server();

server.connection({ 
    host: 'localhost', 
    port: 8000 
});


server.route({
    method: 'GET',
    path:'/testIP/{ip*}', 
    handler: function (request, reply) {
        return reply(`For Joi, ${request.params.ip} is a valid ip.`);
    },
	config: {
		validate: {
			params: {
				ip: Joi.string()
				.ip({
					version: ['ipv4', 'ipV6'],
					cidr: 'optional'
				})
				.required()
			}
		}
	}
});

server.start((err) => {
    if (err) {
        throw err;
    }
    console.log('Server running at:', server.info.uri);
})

Which result you had ?

http://localhost:8000/testIP/foo
-> 400, ok

http://localhost:8000/testIP/192.128.0.0.0
-> 400, ok

http://localhost:8000/testIP/192.128.0.0
-> 200, ok

http://localhost:8000/testIP/192.128.0.0/16
-> 200, ok

http://localhost:8000/testIP/192.128.0.0/32
-> 200, ok

http://localhost:8000/testIP/192.128.0.0/33
-> 400, ok

http://localhost:8000/testIP/ff:
-> 400, ok

http://localhost:8000/testIP/ff::
-> 200, ok

http://localhost:8000/testIP/ff::/22
-> 200, ok

http://localhost:8000/testIP/ff::/32
-> 200, ok

http://localhost:8000/testIP/ff::/33
-> 400, KO: should work !

http://localhost:8000/testIP/ff::/128
-> 400, KO: should work !

http://localhost:8000/testIP/ff::/64
-> 400, KO; should work !

http://localhost:8000/testIP/ff::/129
-> 400, ok

What did you expect ?

ipv6 must be allowed to have a mask up to /128.

@DavidTPate DavidTPate self-assigned this Jun 30, 2017
@DavidTPate DavidTPate added the bug Bug or defect label Jun 30, 2017
@Marsup Marsup added this to the 11.0.0 milestone Jun 30, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
@lock lock bot unassigned DavidTPate Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants