-
Notifications
You must be signed in to change notification settings - Fork 422
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
Two tests fail when trying to update swagger-parser dependency to address CVE-2021-3765 #736
Comments
@robmcguinness , you mention in #514 that the changes in I'm looking through the OpenAPI specification to better understand how One of the test cases that fails has a definition structured like this: {
datapoint: {
properties: {
date: {
type: 'string',
format: 'date'
},
value: {
type: 'number'
}
},
required: ['date', 'value'],
type: 'object'
},
datapointlist: {
type: 'array',
items: {
$ref: '#/definitions/datapoint'
},
required: ['datapoint']
}
} The validateSpec function in An exception happens during validation of Is the issue is that the definition is not aligning to the specification or if the validation does not handle this valid definition correctly. Maybe @marcelstoer can also weigh in on this. |
@feenst took me a while to understand why you dragged me into this but now I got it 😄 This here looks wrong to me.
|
I met with Ben Hutton and Juan Cruz Viotti this morning at JSON Schema Office Hours to describe the problem. Ben suggested that the
The array type does not include Juan Cruz suggested the following addition to // The "required" keyword is only applicable for objects
if (Array.isArray(schema.type) && !schema.type.includes('object')) {
return;
} else if (!Array.isArray(schema.type) && schema.type !== 'object') {
return;
} I'll look into raising a pull request to |
@feenst thanks for this confirmation! However, rather than just skipping the validation in these cases shouldn't the validation fail exactly because array types do not include Also, if you prepare a PR for this, can I ask you to maybe also take APIDevTools/swagger-parser#157 into consideration? |
@marcelstoer, I was considering whether this would be best solved by changing the validation or changing the output of I have been looking into how I would say that based on what I've seen so far, I think the validation should possibly fail for a different reason than why it's failing now and skipping this property validation might still be correct. In any case, I'm still reviewing and evaluating. I'll look at that issue if / when I raise a pull request to |
Looks like |
If you expect a specific type, it needs to be specified. |
Has there been any update on this? We are waiting on the new release of hapi-swagger that fixes the CVE-2021-3765 vulnerability and we were hoping this would be resolved soon |
I had been working on this before leaving for vacation around the holidays. There were some test-related failures on I was also looking into this issue in context of my pull request. I've had other priority items come up since returning for vacation and haven't been able to revisit this. |
Is there anyone who tried to update |
@feenst Looks like this may be waiting on an PR you wrote in Swagger Parser that is waiting on a test for validation. Is there anything I can do to help move that along so we can get this vulnerability closed up? |
Having reviewing the thread and both the swagger/JSON schema spec it looks like hapi-swagger should only be applying "required" property to objects and not arrays. If you take this view point it would mean that the two test are incorrect and the swagger-parser is doing what it should do. Bring this up as a bug with the other maintainers to see if we can push a fix |
fix: issue #736 no required for arrays in swagger
Issue
A component of the validator package is susceptible to CVE-2021-3765. This package is part of the dependency tree from hapi-swagger because of its dependency on swagger-parser 4.0.2.
When trying to raise a pull request to update to a newer version of swagger-parser as a dependency of hapi-swagger, two tests are failing.
Tests fail when trying to use the next available version of swagger-parser (4.1.0). You can see from the changelog here that version adds functionality to the validator, specifically validateRequiredPropertiesExist, which is why the tests are failing.
I'm still looking into this, but hoping from some insight from others on why the responses defined for the given tests are failing with the additional validation.
Environment
npx envinfo --npmPackages '*hapi*' --binaries
Binaries:
Node: 14.8.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD
Steps to Reproduce
npm install [email protected]
npm run test
Expected Behavior
Tests succeed
Actual Behavior
Two tests fail:
array with required #249
replace example with x-example for response
Reproducible Demo
Follow steps to reproduce.
The text was updated successfully, but these errors were encountered: