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

feat: add uriresolver option #1862

Merged
merged 15 commits into from Feb 4, 2022
Merged

Conversation

zekth
Copy link
Contributor

@zekth zekth commented Dec 20, 2021

What issue does this pull request resolve?

fix: #1844

What changes did you make?

Integrate fast-uri as an optional uri resolver.

Is there anything that requires more attention while reviewing?

Not sure about where to add the tests. Right now i only used the resolve test suite. Is there any other spot where we should consider adding fast-uri in the test suite?

Copy link

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work!

@zekth
Copy link
Contributor Author

zekth commented Jan 4, 2022

Any news on this?

@epoberezkin
Copy link
Member

epoberezkin commented Jan 15, 2022

@zekth - thanks for doing it.

I think using a condition at all call sites is a brittle approach that may lead to missing some call site, particularly in the future changes.

What could be done instead is removing URI import from resolve.ts entirely (and whatever other file that uses it now, if any) and instead putting it into options, similarly to how it was done for RegExp. Then all call sites would be updated to unconditionally use the resolver from the options, whether it's the default one or the one passed by the user.

This would be set up during instance options initialisation, there are two different types for user supplied options (Options) and runtime options (InstanceOptions), in the latter the uriResolver should be a required member, so you won't have to check in each call site if it is present, and just use it directly.

Also it has to be supported in standalone code, same as it was done for RegExp (I think).

I am referring to this PR that added RE2 support - #1684 (it's marked as closed but it was just accidentally merged via another branch, you can see in the master branch how it is done)...

@zekth
Copy link
Contributor Author

zekth commented Jan 15, 2022

@epoberezkin i addressed the changes needed. Also discovered that i forgot some other changes. If the shape of this PR is ok for you let me know and i'll rebase it properly.

@epoberezkin
Copy link
Member

looks good - thank you!

Couple questions/comments:

  1. Why does MissingRefError need a reference to resolver? I don't see it used anywhere...
  2. getFullPath accepts resolver as the first parameter and resolveUrl as the last - could you please make it the first in both cases? Another option would be just to call them with Ajv context so resolver is there... (e.g. getFullPath.call(this, ...))

@zekth
Copy link
Contributor Author

zekth commented Jan 19, 2022

@epoberezkin
Copy link
Member

I see - thank you!

@zekth
Copy link
Contributor Author

zekth commented Jan 20, 2022

@epoberezkin i reordered the parameters. Is it ok this way or you'd prefer to pass the complete Ajv context within the functions?

@mcollina
Copy link

I think it's better to bump fast-uri to 0.1.0 or even 1.0.0 to simplify maintenance.

@epoberezkin
Copy link
Member

@zekth - this is great, sorry for being so slow - going to release it now!

@epoberezkin epoberezkin merged commit 0e47ab4 into ajv-validator:master Feb 4, 2022
@zekth zekth deleted the add-fast-uri branch February 4, 2022 17:53
@epoberezkin
Copy link
Member

alright, I already pushed the release out, and then it occurred to me that we didn't add any docs for the feature.

@zekth - please add to the options page if you can :)

Thank you!

@zekth
Copy link
Contributor Author

zekth commented Feb 4, 2022

Will do ASAP!

Copy link

@Maribel400 Maribel400 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😏

@epoberezkin
Copy link
Member

Bump what? :)

@Maribel400
Copy link

Maribel400 commented Mar 10, 2022 via email

@Maribel400
Copy link

Maribel400 commented Mar 10, 2022 via email

@chevett
Copy link

chevett commented Oct 28, 2022

It appears that this is a breaking change? i'm seeing https://github.com/ajv-validator/ajv-merge-patch/blob/master/keywords/add_keyword.js#L22 fail with ajv@8.10+

@fetobasic
Copy link

fetobasic commented Mar 5, 2024

What issue does this pull request resolve?

fix: #1844

What changes did you make?

Integrate fast-uri as an optional uri resolver.

Is there anything that requires more attention while reviewing?

Not sure about where to add the tests. Right now i only used the resolve test suite. Is there any other spot where we should consider adding fast-uri in the test suite?

@zekth @mcollina @epoberezkin Correct me if I'm wrong, but I assume even if you go with the fast-uri option vulnerability scanners like Orca will still pick up the CVE-2021-44906 vulnerability in uri-js dependency (transitive) since there's still an import import type {URIComponents} from "uri-js" on line 3 of resolve.ts??

@zekth
Copy link
Contributor Author

zekth commented Mar 5, 2024

@fetobasic this is a dev-dependency so it's not applicable as vulnerability

@fetobasic
Copy link

fetobasic commented Mar 6, 2024

@fetobasic this is a dev-dependency so it's not applicable as vulnerability

@zekth Thanks for the quick response, but I meant uri-js not fast-uri. Uri-js is still a regular dependency in Ajv and uri-js has a transitive dependency on Minimist which contains the vulnerability.

I think I answered my own question the fact that uri-js is still a regular dependency for Ajv, scanners will pick it up, even if you avoid using the library by utilizing the optional uriresolver like fast-uri?

@zekth
Copy link
Contributor Author

zekth commented Mar 6, 2024

Sorry i misunderstood. Yes you're right unfortunately.

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

Successfully merging this pull request may close these issues.

Replace uri-js by fast-uri
6 participants