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

Url validation failed #481

Closed
velocityzen opened this issue May 3, 2017 · 5 comments
Closed

Url validation failed #481

velocityzen opened this issue May 3, 2017 · 5 comments
Labels

Comments

@velocityzen
Copy link

What version of Ajv are you using? Does the issue happen if you use the latest version?
[email protected]

Ajv options object

{allErrors: true}

JSON Schema

{ 
 "type": "string",
 "format": "url"
}

Sample data

'https://localhost:3000/#test'

Your code

let Ajv = require('ajv')
let v = new Ajv(options)
v.validate(scheme, data);
console.log(v.errors);

Validation result, data AFTER validation, error messages

[ { keyword: 'format',
    dataPath: '',
    schemaPath: '#/format',
    params: { format: 'url' },
    message: 'should match format "url"' } ]

What results did you expect?
It is a correct URL

Are you going to resolve the issue?
nope

@epoberezkin
Copy link
Member

@gajus does it not allow hash fragment?

@velocityzen you can use "uri" as an alternative, "url" is an additional format.

@gajus
Copy link
Contributor

gajus commented May 3, 2017

It does.

The issue here is "localhost". The current regex does not allow TLD-less domains.

Ideally, this should be a configurable option.

@epoberezkin
Copy link
Member

@gajus Thank you. Should it allow? Or not really?

@gajus
Copy link
Contributor

gajus commented May 3, 2017

See the note at:

Assume that this regex will be used for a public URL shortener written in PHP, so URLs like https://localhost/, //foo.bar/, :https://foo.bar/, data:text/plain;charset=utf-8,OHAI and tel:+1234567890 shouldn’t pass (even though they’re technically valid). Also, in this case I only want to allow the HTTP, HTTPS and FTP protocols.

– https://mathiasbynens.be/demo/url-regex

I'd say it shouldn't. In most cases it would produce unexpected result. It could even be used as an attack vector.

I'd recommend that in the case user requires non-public URLs (such localhost, date URIs, tel, skype, etc.) it should be implemented in the user-space.

@epoberezkin
Copy link
Member

I'd recommend that in the case user requires non-public URLs (such localhost, date URIs, tel, skype, etc.) it should be implemented in the user-space.

There is "uri" format for that. Thank you, it's all ok then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants